3

I'm trying to figure out how to use the segmenter provided by the Leptonica library for document analysis. I've been looking at pageseg.c but I don't think I completely understand it :(!

If I take an image and load it as a PIX datatype, do I call pixGetRegionsBinary() to find where each symbol is? And then do I use the textblock mask to extract each symbol separately?

If I understand correctly I would have code like this:

Pix* page = pixRead("myImage.tif");

Pix** halftone;
Pix** textline;
Pix** textblock;

if ( pixGetRegionsBinary( page, halftone, textline, textblock, 0 ) )
{
     //..error message
}

Now is textblock all of the characters or am I using the wrong segmentation method :)? Also how would I know when the textblock "array" ends?

Thanks in advance!!

Edit 26/11/2013

For anyone interested - Leptonica Doxygen Documentation - Page Segmentation is a good example of full page segmentation!

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Kerren
  • 429
  • 1
  • 5
  • 15

1 Answers1

-1

Example of Character segmentation:

void CharacterSegmentation(string filename) {
   PIX * image = pixRead(filename.c_str());
   PIX * binaryImage = pixConvertTo1(image , 250);
   Boxa* connectedBox = pixConnCompBB(binaryImage, 4); 
   for (int i = 0; i < connectedBoxes ->n; i++) {
      BOX* box = boxaGetBox(connectedBox , i, L_CLONE);
      fprintf(stdout, "Box[%d]: x=%d, y=%d, w=%d, h=%d\n", i, box->x, box->y, box->w, box->h);
      BOX* boxd = boxCreate(box->x, box->y, box->w, box->h);
      SaveCharacterImage(image, boxd);
      boxDestroy(&boxd);  
      boxDestroy(&binaryImage);
   }
   pixDestroy(&image);
   pixDestroy(&binaryImage);    
} 

void SaveCharacterImage(PIX* image, BOX* rectangle) {
   PIX* pixd = pixClipRectangle(pixa, boxd, NULL);
   string s = to_string(i) + ".png";
   pixWrite(s.c_str(), pixd, 1);
   pixDestroy(&pixd); 
}
N.Singh
  • 109
  • 1
  • 5