use*_*046 0 ocr opencv tesseract
我正在使用tesseract 3.02和opencv让tesseract实时识别我的相机中的文字.
但效果非常糟糕.结果不可读,无法流畅地显示图像.我认为这是我的代码问题.
有人可以给我一些关于如何修改它的建议吗?
非常感谢!
#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
#include <time.h>
using namespace std;
using namespace cv;
int main() {
// [1]
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);
}
//??IplImage??
IplImage* pFrame = NULL;
//?????
CvCapture* pCapture = cvCreateCameraCapture(-1);
//????
cvNamedWindow("video", 1);
//????
time_t last_time = time(NULL);
while(1)
{
pFrame=cvQueryFrame( pCapture );
if(!pFrame) break;
cvShowImage("video",pFrame);
char c=cvWaitKey(33);
if(c==27)break;
time_t this_time = time(NULL);
if(this_time != last_time)
{
last_time = this_time;
myOCR->SetRectangle(0,0,pFrame->width,pFrame->height);
myOCR->SetImage((uchar*)pFrame->imageData,pFrame->width,pFrame- >height,pFrame->depth/8,pFrame->width*(pFrame->depth/8));
myOCR->Recognize(NULL);
const char* out = myOCR->GetUTF8Text();
printf("%s\n",out);
}
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("video");
cv::waitKey(-1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Tesseract旨在处理扫描的书籍.它在白页上运行,只有黑色文本,清晰可见,失真最小.图像大多是黑与白.你的图像是灰度级的,因此Tesseract的表现非常差.这不是您的代码问题,而是Tesseract的问题.如果你把你的相机指向一本书,你就可以得到文字(假设图像是聚焦的),但是如果你想阅读一般文字(比如街道标志,某人的T恤上的标志比无法做到的那样)抱歉让你失望.
但是,如果您想识别特定文本,例如信用卡号或街道标志,则可以执行此操作.
然后它就能完成你的任务.
| 归档时间: |
|
| 查看次数: |
6138 次 |
| 最近记录: |