1、opencv外加上PIL和 pytesseract 两个包
2、安转tesserac还需要安转OCR引擎
sudo apt-get install tesseract-ocr
import cv2 as cv
from PIL import Image
import pytesseract as tess
def recongnize_text(image):
blur = cv.GaussianBlur(image,(55,55),0)
gray = cv.cvtColor(blur, cv.COLOR_BGR2GRAY)
ret, binary= cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (8, 8))
bin = cv.morphologyEx(binary, cv.MORPH_OPEN, kernel)
cv.imshow("binary_image", bin)
cv.bitwise_not(bin, bin) #变成白色背景
cv.imshow("binary_image2", bin)
textImage = Image.fromarray(bin)
text = tess.image_to_string(textImage)
print("识别结果:%s" % text)