我正在裁剪图像,然后在其上使用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))
答案 0 :(得分:0)
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))