获取方向Python

2024-10-01 09:28:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道扫描文件的方向。我看到了这篇文章Pytesseract OCR multiple config options,我试图使用**--psm0**来获得方向。在

target = pytesseract.image_to_string(text, lang='eng', boxes=False, \
    config='--psm 0 tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz')

但我得到一个错误:

^{pr2}$

Tags: 文件totextimageconfigtargetstringmultiple
2条回答

我找到了另一种使用pytesseract获取方向的方法:

print(pytesseract.image_to_osd(Image.open(file_name)))

这是输出:

^{pr2}$

@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)

相关问题 更多 >