0

我想知道如何在我的 c++ 应用程序中使用 tesseract-ocr 围绕段落图片中的单词绘制一个矩形。我也想从图片中裁剪一些单词!任何想法?

4

1 回答 1

1

我搜索并尝试过,所以我发现了这个:

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 是矩形的高度。

于 2012-11-20T14:11:45.267 回答