简体   繁体   English

在裁剪后的图像上使用pytesseract

[英]Using pytesseract on cropped image

I am cropping an image and then using pytesseract on it to read digits from it. 我正在裁剪图像,然后在其上使用pytesseract从中读取数字。 However, I have to first save the cropped image and then load it again for this code to work. 但是,我必须先保存裁剪后的图像,然后再次加载它才能使此代码正常工作。 Is there a way I can avoid doing this and improve efficiency? 有没有办法可以避免这样做并提高效率? If I pass cropped directly to the image_to_string it crashes with: 如果我将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