gpt4 book ai didi

opencv - OCR:未获得理想的结果

转载 作者:行者123 更新时间:2023-12-02 16:49:40 25 4
gpt4 key购买 nike

我有这张图片enter image description here。我正在尝试对该图像中的字母进行OCR。对于字母“9”和“R”,我没有得到期望的结果。首先,我裁剪了这两个字母enter image description hereenter image description here并执行以下命令。

tesseract 9.png stdout -psm 8
.
它只是返回“。”
所有其他字母的OCR都可以正常工作,但对于这两个字母而言却不能正常工作(尽管我认为它们的图像质量还不错)。
任何建议/帮助表示赞赏。

最佳答案

我自己没有tesseract的经验,但根据google结果,复制了角色并在内部使用tesseract的https://www.newocr.com/上添加了一些背景作品。

所以我用它作为输入:

enter image description here

这会在该网络应用上给出正确的结果:99999999,而单个字符不起作用。也许您可以使用tesseract实现来验证这一点,也许它可以帮助您调整孤立的提取字符以与tesseract一起使用。例如尝试将相邻提取的轮廓重复缝合在一起,以改善tesseract的输出-因为您知道将轮廓缝合在一起的频率,所以您会知道,如果识别出相同的字符,那么输出可能是正确的。 ..

同样的作品

enter image description here

边框看起来很重要,如果边框不足,它将无法识别P。一般来说,您应该尝试用纯黑色和纯白色替换背景和前景!不确定网络应用使用哪种预处理...

该代码可用于使用C++和OpenCV重复图像,但不会在周围添加边框。为此,您将非常相似地工作,但是需要执行一些附加步骤,并且必须为边框分配一些颜色。

编辑:我已更新代码,以在每个方向上使用4像素的边框(您可以调整变量),并使用黑色背景色。

这段代码非常简单,对于java,python等中的opencv应该非常相似。

int main(int argc, char * argv[])
{
//cv::Mat input = cv::imread("../inputData/ocrR.png");

if(argc != 3)
{
std::cout << "usage: .exe filename #Repetitions" << std::endl;
return 0;
}

std::string filename = argv[1];
int nRepetitions = atoi(argv[2]);

cv::Mat inputImage = cv::imread(filename);
if(inputImage.empty())
{
std::cout << "image file " << filename << " could not be loaded" << std::endl;
return 0;
}

// you instead should try to extract the background color from the image (e.g. from the image border)
cv::Scalar backgroundColor(0,0,0);

// size of the border in each direction
int border = 4;

cv::Mat repeatedImage = cv::Mat(inputImage.rows + 2*border, nRepetitions*inputImage.cols + 2*border, inputImage.type() , backgroundColor);

cv::Rect roi = cv::Rect(border,border,inputImage.cols, inputImage.rows);

for(int i=0; i<nRepetitions; ++i)
{
// copy original image to subimage of repeated image
inputImage.copyTo(repeatedImage(roi));

// update roi position
roi.x += roi.width;
}

// now here you could send your repeated image to tesseract library and test whether nRepetitions times a letter was found.

cv::imwrite("repeatedImage.png", repeatedImage);
cv::imshow("repeated image" , repeatedImage);
cv::waitKey(0);
return 0;
}

得到这个结果:

enter image description here

关于opencv - OCR:未获得理想的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34176517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com