【问题标题】:Draw a rectangle around the words in picture using tesseract使用 tesseract 在图片中的单词周围画一个矩形
【发布时间】:2012-11-20 09:47:55
【问题描述】:

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

【问题讨论】:

    标签: c++ ocr tesseract


    【解决方案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 是矩形的高度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多