I use '--psm 6' as config. And i have pytesseract 4.1.1. Language: 'deu' which is German
In various documents pytesseract recognizes chars which are not there.
For example I have this image. We can see that there are strings which are not in the document. And this is not a once time result, all of my documents have this kind of problem.
Another example is this one. There is no "re"enter image description here in the document.
Any suggestions? How can I solve it?
Until now I tried some image preparation.
def prepare_image_advanced(image): cv2_image = np.array(image) cv2_image = cv2.resize(src=cv2_image, dsize=None, fx=1, fy=1) cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2GRAY) _, binary = cv2.threshold(cv2_image, 240, 255, cv2.THRESH_BINARY) kernel = np.ones((25, 25), np.uint8) closed = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel) contours, hierarchy = cv2.findContours( closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE ) for j, contour in enumerate(contours[:-1]): x, y, w, h = cv2.boundingRect(contour) cv2_image[y : y + h, x : x + w] = 255 prepared_image = Image.fromarray(cv2_image) # brightener = ImageEnhance.Brightness(prepared_image) # prepared_image = brightener.enhance(1.5) # contraster = ImageEnhance.Contrast(prepared_image) # prepared_image = contraster.enhance(1.5) # sharpener = ImageEnhance.Sharpness(prepared_image) # prepared_image = sharpener.enhance(1.5) # prepared_image = np.array(prepared_image) return prepared_image
Which looks like this. It does not help actually.