c++ - 使用tesseract在图片中的文字周围绘制一个矩形

标签 c++ ocr tesseract

我想知道如何在我的 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/

相关文章:

c++ - 'this' 与继承的奇怪行为

c++ - 通过 move 语义和右值引用提高性能

ocr - pytesseract - 无效分辨率 0 dpi

vb.net - 如何在 Visual Basic 中实现 Tesseract OCR?

c++ - 如何定义 tesseract 用于识别(而不是训练)的字体类型?

c++ - 照明不适用于 OpenGL - 纯色

c++ - STL set_intersection 运行时错误

java - 从图像中提取孟加拉语文本[可能包含孟加拉语和英语]

safari - 如何设置网页表单以支持移动 Safari 中的 iOS 8 信用卡扫描?

java - 线程 "main"java.lang.NoClassDefFoundError : com/sun/jna/Pointer 中出现异常