cpp

Counting transitions in a bit string

Posted on

We need to count a number of transitions in a bit string from 0->1 and 1->0. I needed this in order to determine Uniform Descriptor in Local Binary Patterns(LBP) Samples 0000 0000 (0 Transitions : Uniform) 0x0 1110 0011 (2 Transitions : Uniform) 0xE3 0101 0000 (4 Transitions : NonUniform) 0x50 0000 1010 (4 Transitions […]

cpp

Dump leptonica pix data to console

Posted on

Small utility for dumping Leptonica Pix data to the screen. void dump(PIX* pix) { int_t w = pix->w; int_t h = pix->h;   int_t wpl = pixGetWpl(pix); l_uint32* data = pixGetData(pix); l_uint32* line;   printf("\n"); printf("Depth : %d \n", pix->d);   for (int_t y = 0; y < h; ++y) { printf("%04d : ", y); […]

cpp

Overloading by return value in C++

Posted on

Here we have a method that allows us to determine return parameter type using templates and operator overloading in C++. This is something that I needed for a project that I am working on where a method call would give me the expected type based on the return type. Usage There is two way of […]

cpp

Creating Javascript accessible object from C++ / CEF

Posted on

Example with Chromium Embedded Framework (CEF) on how to create an object in C++ and make it accessible via Javascript. console.inof(api) Object {ready: true, version: "psql.0.0.1", info: Object, getVersion: function}console.inof(api) Object {ready: true, version: "psql.0.0.1", info: Object, getVersion: function} void ExtractEngineApp::OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) {   auto info = CefV8Value::CreateObject(NULL, NULL); info->SetValue("major", […]

cpp

Accessing data of leptonica PIX data

Posted on

This is mainly as a reference   /** * Get Pixel value at given point */ l_uint32 pixAtGet(PIX* pix, int_t x, int_t y) { l_int32 wpl = pixGetWpl(pix); l_uint32* data = pixGetData(pix); l_uint32* line = data + y * wpl; l_uint32 value = GET_DATA_BYTE(line, x); return value; } /** * Get Pixel value at given […]

cpp

Tokenizing/splitting string in c++

Posted on

This method uses strtok to tokeninze our string given a specific delimeter, results of that are put into supplied vector. There are few other ways we can do this but this one is straight forward. #include <iostream> #include <string> #include <string.h>   #include <memory> #include <stdlib.h> #include <stdio.h> #include <list> #include <vector>   using namespace […]

cpp

Calculating partial Hausdorff Distance

Posted on

  struct Point { Point(int_t _x, int_t _y) : x(_x), y (_y) {   }   int_t x; int_t y; };     typedef std::list<Point*> points_t;   double euclideanDistance(const Point& lhs,const Point& rhs) { double p1 = std::pow((float)(rhs.x – lhs.x), 2); double p2 = std::pow((float)(rhs.y – lhs.y), 2); double vd = std::sqrt(p1 + p2);   […]

cpp

Compiling Webkit on Windows using Visual Studio 2012

Posted on

Just some notes on compiling WebKit on windows with visual studio. Issues : C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xrefwrap(431): error C2064: term does not evaluate to a function taking 1 arguments (..\..\win\WebCoreSupport\WebFrameLoaderClient.cpp) 25> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(239) : see reference to function template instantiation ‘_Ret std::_Callable_obj::_ApplyX(_V0_t &&)’ being compiled 25> with 25> [ […]

cpp

Leptonica barcode generation

Posted on

Leptonica provides us with easy way to read barcodes but it does not offer a way to create them(as far as I know). Here is a leptonica function that will allow us to generate CODABAR barcode, in the feature I am planning on adding more type and more options but for now this was all […]