Шаги:
import cv2
import pytesseract
import matplotlib.pyplot as plt
import matplotlib
img = cv2.imread('pan2.jpg')
image= img.copy()
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = 255 - cv2.threshold(blur, 0,255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
# Dilate to combine adjacent text contours
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (4,2))
dilate = cv2.dilate(thresh, kernel, iterations=2)
# Find contours, highlight text areas, and extract ROIs
cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
ROI_number = 0
ROI_images = []
for c in cnts:
area = cv2.contourArea(c)
x,y,w,h = cv2.boundingRect(c)
if area > 1000 and 12<h<18:
cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 3)
ROI = img[y:y+h, x:x+w]
# cv2.imwrite('ROI_{}.png'.format(ROI_number), ROI)
ROI_number += 1
ROI_images.append(ROI)
plt.subplot(131)
plt.imshow(thresh)
plt.subplot(132)
plt.imshow(dilate)
plt.subplot(133)
plt.imshow(image)
plt.show()
![enter image description here](https://i.stack.imgur.com/yBjXU.png)
for i in ROI_images:
text = pytesseract.image_to_string(i,config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
print("text:",text)
plt.imshow(i)
plt.show()
![enter image description here](https://i.stack.imgur.com/seBba.png)