繁体   English   中英

在裁剪后的图像上使用pytesseract

[英]Using pytesseract on cropped image

我正在裁剪图像,然后在其上使用pytesseract从中读取数字。 但是,我必须先保存裁剪后的图像,然后再次加载它才能使此代码正常工作。 有没有办法可以避免这样做并提高效率? 如果我将cropped直接传递给image_to_string它将崩溃:

in image_to_string if len(image.split()) == 4: AttributeError: 'numpy.ndarray' object has no attribute 'split'

cropped = image[1044:2000, 100:1025]
cv2.imwrite("thumbnail.png", cropped)
img = Image.open("thumbnail.png")
print(pytesseract.image_to_string(img, config='-psm 6'))
print("--- %s seconds ---" % (time.time() - start_time))

使用Image.fromarray()

cropped = image[1044:2000, 100:1025] img = Image.fromarray(cropped) print(pytesseract.image_to_string(img, config='-psm 6')) print("--- %s seconds ---" % (time.time() - start_time))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM