我正在尝试使用Python-tesseract通过光学字符识别(OCR)从这个(picture)中提取数字。由于某些原因,pytesseract无法识别数字,我不完全理解原因(数字之间的距离?)。
有人可以帮助我理解如何正确地从这张图像中提取数字吗?
下面的代码没有打印任何内容
im.save("sudo.png")
text = pytesseract.image_to_string(im)
print(text)发布于 2019-07-05 02:35:12
一些预处理和使用ROI来指定单词的位置将会有所帮助。默认情况下,OCR使用页面布局分析来确定文本块。在这种情况下,图像看起来不像是普通的文本页面(例如PDF文章)。为了使OCR更容易,首先可以使用regionprops查找单词的位置,然后将单词的位置(作为边界框)传递给OCR函数。请看下面的代码和结果。它们看起来很准确。您可能需要更多地处理预处理,以使其对不同图像的集合具有健壮性。但希望这能给你一个如何继续下去的想法:
capture = imread('Captura.PNG');
% Increase image size by 3x
my_image = imresize(capture, 3);
figure
imshow(my_image)
% Localize words
BW = imbinarize(rgb2gray(my_image));
BW1 = imdilate(BW,strel('disk',6));
s = regionprops(BW1,'BoundingBox');
bboxes = vertcat(s(:).BoundingBox);
% Sort boxes by image height
[~,ord] = sort(bboxes(:,2));
bboxes = bboxes(ord,:);
% Pre-process image to make letters thicker
BW = imdilate(BW,strel('disk',1));
% Call OCR and pass in location of words. Also, set TextLayout to 'word'
ocrResults = ocr(BW,bboxes,'CharacterSet','.0123456789','TextLayout','word');
words = {ocrResults(:).Text}';
words = deblank(words)https://stackoverflow.com/questions/55170670
复制相似问题