效果
下载链接,下载后安装一路next就可以
https://digi.bib.uni-mannheim.de/tesseract/
安装后在环境变量path中添加路径C:Program FilesTesseract-OCR
在终端测试是否有tesseract,输入tesseract -v,显示版本为存在
然后pip install pytesseract
import pytesseract
import cv2
img = cv2.imread('img01.png')
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
# print(pytesseract.image_to_string(img))
htmg,wimg,_ = img.shape
boxes = pytesseract.image_to_boxes(img)
# print(boxes)
# Python splitlines() 按照行('r', 'rn', n')分隔
for b in boxes.splitlines():
b = b.split(' ')
print(b)
x,y,w,h = int(b[1]),int(b[2]),int(b[3]),int(b[4])
cv2.rectangle(img,(x,htmg-y),(w,htmg-h),(0,0,255),3)
cv2.putText(img,b[0],(x,htmg-y+25),cv2.FONT_HERSHEY_COMPLEX,1,(0,0,255),2)
cv2.imshow('res',img)
cv2.waitKey(0)



