获取方向pytesseract Python3
我想获取扫描文档的方向。我看到了这篇文章,并尝试使用获取方向pytesseract Python3,python,tesseract,python-tesseract,Python,Tesseract,Python Tesseract,我想获取扫描文档的方向。我看到了这篇文章,并尝试使用--psm 0来获得方向 target = pytesseract.image_to_string(text, lang='eng', boxes=False, \ config='--psm 0 tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz') 但我有一个错误: FileNotFoundError: [Errno 2] No such file or directo
--psm 0
来获得方向
target = pytesseract.image_to_string(text, lang='eng', boxes=False, \
config='--psm 0 tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz')
但我有一个错误:
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/jy/np7p4twj4bx_k396hyc_bnxw0000gn/T/tess_dzgtpadd_out.txt'
我找到了另一种使用pytesseract获得方向的方法:
print(pytesseract.image_to_osd(Image.open(file_name)))
这是输出:
Page number: 0
Orientation in degrees: 270
Rotate: 90
Orientation confidence: 21.27
Script: Latin
Script confidence: 4.14
@lads已经提到了可以找到方向的方法。 我刚刚用re得到了旋转图像需要多少度
imPath='path_to_image'
im = cv2.imread(str(imPath), cv2.IMREAD_COLOR)
newdata=pytesseract.image_to_osd(im)
re.search('(?<=Rotate: )\d+', newdata).group(0)
imPath='path\u到图像'
im=cv2.imread(str(imPath),cv2.imread\u颜色)
newdata=pytesseract.image\u to\u osd(im)
重新搜索(“(?不是写入regex从字符串获取输出,而是传递参数output.DICT
以获取结果作为DICT
来自PyteSeract导入输出的
im=cv2.imread(str(imPath),cv2.imread\u颜色)
newdata=pytesseract.image\u to\u osd(im,output\u type=output.DICT)
示例输出如下所示:使用dict键访问这些值
{
'page_num': 0,
'orientation': 90,
'rotate': 270,
'orientation_conf': 1.2,
'script': 'Latin',
'script_conf': 1.11
}
它可以检测脚本或字体?如果文档包含不同的字体怎么办?