【问题标题】:Processing an IplImage(OpenCV) data in Tesseract在 Tesseract 中处理 IplImage(OpenCV) 数据
【发布时间】:2011-12-13 13:45:15
【问题描述】:

我需要处理从 OpenCV 获取的图像。

到目前为止我写的:

IplImage* img=0;

img=cvLoadImage("paket2.tif");


api.SetRectangle(0,0,img->width, img->height);
api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->width*(img->depth/8));
//i tried also below line
//api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->widthStep);

int left,top,right,bottom;
left=0;top=0;right=0;bottom=0;
api.Recognize(NULL);
tesseract::ResultIterator *ri=api.GetIterator();
char * sonuc=(*ri).GetUTF8Text(tesseract::RIL_SYMBOL);

if((*ri).BoundingBox(tesseract::RIL_SYMBOL,&left,&top,&right,&bottom))
{printf("bb dogru\n");printf("%d,%d,%d,%d",left,top,right,bottom);}
printf("sonuc:%s",sonuc);

如果我将 IplImage->widthStep 传递给每行字节数,我在左右值中有“错误”边界框,并且无法读取图像中的所有文本。

如果我通过 IplImage->width*(IplImage->depth/8),boundingBox 函数返回 false。

我希望你有一些想法。 提前致谢。

【问题讨论】:

  • IplImage* img=0; img=cvLoadImage("paket2copy.png"); printf("width:%d",img->width); printf("byte depth:%d",img->depth/8); printf("widthStep:%d",img->widthStep); 结果:width:642 byte depth:1 widthStep:1928;这是正常的吗,每像素字节为 1 但宽度步长是宽度的 3 倍?
  • 如果您在此期间找到了可行的解决方案,能否请您发布您的代码?
  • 不幸的是不是一个精确的解决方案。但我认为用opencv获取字母(作为结合的黑色形状)并逐字母发送到tesseract以识别它们。但在我的情况下,这已经足够了,因为我不需要左右边界,我只需要上下边界。

标签: opencv tesseract


【解决方案1】:

将您的子矩阵复制到新的 IplImage。使用正确的信息(宽度、高度、步长)创建一个正方体图像标题。将 tesseract 数据指针链接到 iplImage 数据指针。

我不记得如何访问 tesseract 指针,但对于 opencv 是 image->data.ptr

【讨论】:

    【解决方案2】:

    这里的代码对我有用:

    tesseract::TessBaseAPI tess; 
    tess.Init(argv[0], "eng", tesseract::OEM_DEFAULT); 
    cv::Mat image = cv::imread("...");
    tess.SetImage((uchar*)image .data, image.size().width, image.size().height, image.channels(),     image.step1());
    tess.Recognize(0);
    const char* out = tess.GetUTF8Text();
    

    【讨论】:

    • 您的代码与处理无关。而且你的结果一定很糟糕。
    猜你喜欢
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多