OpenCV和Tesseract之间是否存在任何冲突

Is there any conflict between opencv and tesseract?

本文关键字:存在 任何 冲突 是否 之间 Tesseract OpenCV      更新时间:2023-10-16

我在项目中使用tesseract和opencv。

但是问题是当我使用openCV显示图像时,只出现图像窗口,但图像没有出现,并且完全是灰色的。

如果我评论与Tesseract相关的代码,则OpenCV可以正确拍摄图像。

太奇怪了。有身体可以帮助我吗?

预先感谢!

#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

int main() {
// [1]
const char* imagename = "phototest.tif";
Mat img = imread(imagename);
if(img.empty())
{
    fprintf(stderr, "Can not load image %sn", imagename);
    return -1;
}
imshow("image", img);
tesseract::TessBaseAPI *myOCR = 
        new tesseract::TessBaseAPI();
// [2]
printf("Tesseract-ocr version: %sn",
       myOCR->Version());
printf("Leptonica version: %sn",
       getLeptonicaVersion());
// [3]
if (myOCR->Init(NULL, "eng")) {
  fprintf(stderr, "Could not initialize tesseract.n");
  exit(1);
}
// [4]
Pix *pix = pixRead("phototest.tif");
myOCR->SetImage(pix);
// [5]
char* outText = myOCR->GetUTF8Text();
printf("OCR output:nn");
printf(outText);
// [6]
myOCR->Clear();
myOCR->End();
delete [] outText;
pixDestroy(&pix);
system("pause");
return 0;
}   

您可以尝试在iMshow之后的某个地方添加CV :: Waitkey(10),这可能会解决您的问题。您可以通过CV :: Waitkey(-1)替换系统(暂停)。

相关文章: