我想知道如何在我的 C++ 应用程序中使用 tesseract-ocr 在段落图片中的单词周围绘制一个矩形。 我也想从图片中裁剪一些文字! 有什么想法吗?
最佳答案
我搜索并尝试过,所以我找到了这个:
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
const PIX *pixs = pixRead(image);
STRING text_out;
api.SetImage(pixs);
//api.ProcessPages(image, NULL, 0, &text_out);
//text_out = api.GetUTF8Text();
cout<<text_out.string();
//box
Boxa* bounds = api.GetWords(NULL);
l_int32 count = bounds->n;
for(int i=0; i<count; i++)
{
Box* b = bounds->box[i];
int x = b->x;
int y = b->y;
int w = b->w;
int h = b->h;
cout<<x<<" "<<y<<" "<<w<<" "<<h<<endl;
}
这将导致矩形左下角的 (x,y),w 是矩形的宽度,h 是矩形的高度。
关于c++ - 使用tesseract在图片中的文字周围绘制一个矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13470466/