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 に答える