我只能将此代码用于我在ms word中创建的图像,并进行屏幕截图然后再使用这些图像。其余的其他图像无法很好地识别,有时我会收到类似“错误:OpenCV(4.1.0)C:\ projects \ opencv-python \ opencv \ modules \ imgproc \ src \ resize.cpp:3718:error:( -215:Assertion失败)在函数'cv :: resize“中的!ssize.empty()
我只尝试了2个基本班轮代码 然后我尝试了
import pytesseract
import cv2
import numpy as np
image='bill11.PNG'
print('Editing image for better OCR result..........')
img = cv2.imread(image)
img = cv2.resize(img, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_CUBIC)
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
img = cv2.bilateralFilter(img, kernel,9,75,75)
img_grey = cv2.cvtColor(img, kernel, cv2.COLOR_BGR2GRAY)
new_image = 'edited' + '_' + image
cv2.imwrite(new_image, img)
read = pytesseract.image_to_string(new_image)
file = open("yesno.txt","w")
print(read)
file.write(read)
file.close()
我希望有比这更好的代码,对于其他图像,它也可以工作得更好或比这更好