Crop pictures with Leptonica API -> OR which image

2019-05-13 06:36发布

问题:

I'm trying to do two things -> First I need to read in an image and crop it ( coordinates / frame will be provided by the user ). Then I want to run an OCR over it. ( Actually the cropping an the OCR shall be strictly divided ). Now to my problem:

For the OCR I'm using Tesseract, which is using the Leptonica API for the image processing. Since I'm programing for an embedded device I want to keep the count of different libraries low. So my best interest is to crop my image with Leptonica, so I don't need a third library just to do this task.

So my question is now, how can I cut out frames with Leptonica? Is there even a way?

回答1:

There's an example in the unofficial documentation which seems to incorporate the cropping: http://tpgit.github.com/Leptonica/croptext_8c_source.html

To be more specific, you should create a box (ie. cropping window) and then call pixClipRectangle() function to crop the image:

BOX* cropWindow = boxCreate(x, y, w, h);
PIX* croppedImage = pixClipRectangle(image, cropWindow, NULL);


回答2:

stativ's answer works, but you must delete created objects:

BOX* box = boxCreate(startX, startY, width, height);
PIX* pixd= pixClipRectangle(pixs, box, NULL);
boxDestroy(&box);

and for PIX* there's

pixDestroy(&pix);