Crop pictures with Leptonica API -> OR which image processing Lib to use?

▼魔方 西西 提交于 2019-12-22 08:22:21

问题


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);


来源:https://stackoverflow.com/questions/8605513/crop-pictures-with-leptonica-api-or-which-image-processing-lib-to-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!