OpenCV面临一个错误,即使在安装后也找不到tesseract moule
pip安装tesseract
opencv重新安装也完成了,但它不会工作。
opencv安装命令包括
pip安装opencv-python
pip安装打开控件-Python
使用此github指南安装tesseract.exe-link
我仍然面临以下错误
错误-未找到tesseract模块
from PIL.Image import ImageTransformHandler
import cv2
import numpy as np
import pytesseract
pytesseract.pytesseract.tesseract_cmd='C:\Program Files(x86)\Tesseract-OCR\tesseract.exe'
cascade= cv2.CascadeClassifier("haarcascade_russian_plate_number.xml")
states={"AN":"Andaman and Nicobar",
"AP":"Andhra Pradesh","AR":"Arunachal Pradesh",
"AS":"Assam","BR":"Bihar","CH":"Chandigarh",
"DN":"Dadra and Nagar Haveli","DD":"Daman and Diu",
"DL":"Delhi","GA":"Goa","GJ":"Gujarat",
"HR":"Haryana","HP":"Himachal Pradesh",
"JK":"Jammu and Kashmir","KA":"Karnataka","KL":"Kerala",
"LD":"Lakshadweep","MP":"Madhya Pradesh","MH":"Maharashtra","MN":"Manipur",
"ML":"Meghalaya","MZ":"Mizoram","NL":"Nagaland","OD":"Odissa",
"PY":"Pondicherry","PN":"Punjab","RJ":"Rajasthan","SK":"Sikkim","TN":"TamilNadu",
"TR":"Tripura","UP":"Uttar Pradesh", "WB":"West Bengal","CG":"Chhattisgarh",
"TS":"Telangana","JH":"Jharkhand","UK":"Uttarakhand"}
def extract_num(img_filename):
img=cv2.imread(img_filename)
#Img To Gray
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
nplate=cascade.detectMultiScale(gray,1.1,4)
#crop portion
for (x,y,w,h) in nplate:
wT,hT,cT=img.shape
a,b=(int(0.02*wT),int(0.02*hT))
plate=img[y+a:y+h-a,x+b:x+w-b,:]
#make the img more darker to identify LPR
kernel=np.ones((1,1),np.uint8)
plate=cv2.dilate(plate,kernel,iterations=1)
plate=cv2.erode(plate,kernel,iterations=1)
plate_gray=cv2.cvtColor(plate,cv2.COLOR_BGR2GRAY)
(thresh,plate)=cv2.threshold(plate_gray,127,255,cv2.THRESH_BINARY)
#read the text on the plate
read=pytesseract.image_to_string(plate)
read=''.join(e for e in read if e.isalnum())
stat=read[0:2]
cv2.rectangle(img,(x,y),(x+w,y+h),(51,51,255),2)
cv2.rectangle(img,(x-1,y-40),(x+w+1,y),(51,51,255),-1)
cv2.putText(img,read,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,0.9,(255,255,255),2)
cv2.imshow("plate",plate)
cv2.imwrite("Result.png",img)
cv2.imshow("Result",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
extract_num('car_img.png')
1条答案
按热度按时间bfnvny8b1#
修复此错误后,将文件路径(C:\Program Files(x86)\Tesseract-OCR\tesseract.exe)更改为-〉(C:\Program Files\Tesseract-OCR\tesseract.exe),工作正常
无论您在windows中的路径是什么programfiles,都不要使用**Program Files(x86)**它不会工作
仍然显示或不安装错误,你面临的,然后按Windows + R键,并运行您的文件路径(C:\Program Files\Tesseract-OCR\Tesseract.exe)它会为我工作,
第一节第一节第一节第一节第一节第二节第一节
此错误已修复-未找到tesseract模块
希望能对一些人有所帮助。