2014-10-20 72 views
-1

我使用OpenCV查找照片上车牌的坐标。接下来,我试图通过函数SetRectangle将这些坐标发送到tesseract。Tesseract:从矩形读取

... 
CvRect rect; 
rect=cvBoundingRect(contourLow, NULL); // finding rects among contours 
Pix *image = pixRead("auto.jpg"); 
api->SetImage(image); 
api->SetRectangle(rect.x,rect.y,rect.width, rect.height); 
outText = api->GetUTF8Text(); 
printf("OCR output:\n%s", outText);  
... 

问题是输出为空。

我确定坐标是正确的(检查它)。另外,如果我在tesseract中设置了切割号牌的图像,它可以正常工作。

那么,如何设置正确的矩形形式?

+0

'api'的数据类型是什么? auto.jpg看起来像什么?你可以分享吗? – karlphillip 2014-10-20 21:36:25

回答

0

这里有些代码是我用过的。它工作正常。 (正方体3.02)

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); 
api->TesseractRect(_imgTemp.data,1,_imgTemp.step1(),0,0,_imgTemp.cols,_imgTemp.rows); 
char* text = api->GetUTF8Text(); 
api->Clear(); 
0

包括必要的头文件的Tesseract/baseapi.h和leptonica/allheaders.h使它编译你的机器上。

char *outText; 
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); 
// you can specify in input language as eng or fre or any other language the doc relates to 
if (api->Init(NULL, "eng")) { 
    fprintf(stderr, "Could not initialize tesseract.\n"); 
    exit(1); 
} 

Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif"); 
api->SetImage(image); 
// SetRectangle(left, top, width, height) 
api->SetRectangle(30, 86, 590, 100); 
// Get OCR result 
outText = api->GetUTF8Text(); 
printf("OCR output:\n%s", outText); 

// Destroy used object and release memory 
api->End(); 
delete [] outText; 
pixDestroy(&image); 

return 0;