I use tesseract and opencv in my project.
But the problem is when I use opencv to show the image, there only appear the image window but the image didn’t appear and it was totally grey.
If I comment the codes related to tesseract, the opencv can shoow image properly.
It’s so weird. Can any body help me?
Thanks in advance!
#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 %s\n", imagename);
return -1;
}
imshow("image", img);
tesseract::TessBaseAPI *myOCR =
new tesseract::TessBaseAPI();
// [2]
printf("Tesseract-ocr version: %s\n",
myOCR->Version());
printf("Leptonica version: %s\n",
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:\n\n");
printf(outText);
// [6]
myOCR->Clear();
myOCR->End();
delete [] outText;
pixDestroy(&pix);
system("pause");
return 0;
}
Can you try to add a cv::waitkey(10) somewhere after your imshow, that may solve your problem.
You can replace system(pause) by cv::waitkey(-1) also.