【发布时间】:2021-12-10 16:25:44
【问题描述】:
tesseract rsa-out.jpg stdout
Warning. Invalid resolution 0 dpi. Using 70 instead.
Empty page!!
Empty page!!
【问题讨论】:
标签: tesseract
tesseract rsa-out.jpg stdout
Warning. Invalid resolution 0 dpi. Using 70 instead.
Empty page!!
Empty page!!
【问题讨论】:
标签: tesseract
图像的元数据可能不包括图像分辨率。如果您知道,您可以使用--dpi 命令选项为输入图像指定 DPI。运行tesseract --help-extra 以获取更多信息。
已更新版本信息和 cmd 输出:
>tesseract -v
tesseract 4.1.1
leptonica-1.79.0 (Jan 2 2020, 22:29:02) [MSC v.1924 DLL Release x64]
libgif 5.1.4 : libjpeg 9c : libpng 1.6.37 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.3 : libopenjp2 2.3.1
>tesseract --help-extra
Usage:
tesseract --help | --help-extra | --help-psm | --help-oem | --version
tesseract --list-langs [--tessdata-dir PATH]
tesseract --print-parameters [options...] [configfile...]
tesseract imagename|imagelist|stdin outputbase|stdout [options...] [configfile...]
OCR options:
--tessdata-dir PATH Specify the location of tessdata path.
--user-words PATH Specify the location of user words file.
--user-patterns PATH Specify the location of user patterns file.
--dpi VALUE Specify DPI for input image.
-l LANG[+LANG] Specify language(s) used for OCR.
-c VAR=VALUE Set value for config variables.
Multiple -c arguments are allowed.
--psm NUM Specify page segmentation mode.
--oem NUM Specify OCR Engine mode.
NOTE: These options must occur before any configfile.
Page segmentation modes:
0 Orientation and script detection (OSD) only.
1 Automatic page segmentation with OSD.
2 Automatic page segmentation, but no OSD, or OCR. (not implemented)
3 Fully automatic page segmentation, but no OSD. (Default)
4 Assume a single column of text of variable sizes.
5 Assume a single uniform block of vertically aligned text.
6 Assume a single uniform block of text.
7 Treat the image as a single text line.
8 Treat the image as a single word.
9 Treat the image as a single word in a circle.
10 Treat the image as a single character.
11 Sparse text. Find as much text as possible in no particular order.
12 Sparse text with OSD.
13 Raw line. Treat the image as a single text line,
bypassing hacks that are Tesseract-specific.
OCR Engine modes:
0 Legacy engine only.
1 Neural nets LSTM engine only.
2 Legacy + LSTM engines.
3 Default, based on what is available.
Single options:
-h, --help Show minimal help message.
--help-extra Show extra help for advanced users.
--help-psm Show page segmentation modes.
--help-oem Show OCR Engine modes.
-v, --version Show version information.
--list-langs List available languages for tesseract engine.
--print-parameters Print tesseract parameters.
【讨论】:
警告告诉您输入图像的元数据中不包含分辨率信息,因此 Tesseract 会发出警告,然后尝试自行估计分辨率。 您可以参考此issue 了解更多信息。
【讨论】:
要测试图像是否具有正确的标题,您可以使用 magick identify -verbose 文件名或等效工具
并确保设置了这两个值 分辨率:118.11x118.11 单位:像素每厘米 以上是 300 dpi PNG
【讨论】:
您应该能够使用以下行正常加载它:
import cv2
import pytesseract
image = cv2.imread('FS313.jpg')
text = pytesseract.image_to_string(image,lang='eng',config='--psm 3')
但是,无论 psm 如何,您都无法获得准确的 OCR 结果,因为 Tesseract 没有针对此类数字进行训练。如果您愿意,有一个视频可以帮助您自己训练它,名为“Tesseract OCR - 为七段创建训练数据(示例)”。
【讨论】:
public class Test {
public static void main(String[] args) {
File imageFile = new File("C:\\Users\\data.jpg");
ITesseract instance = new Tesseract();
instance.setTessVariable("user_defined_dpi", "96");
System.err.println(instance.getClass().getName().toString());
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
添加这一行:instance.setTessVariable("user_defined_dpi", "96");
【讨论】: