我正在编写代码,借助opencv
和Python
来识别汽车上的车牌。为此,我使用了haarcascades。我从这里下载了haarcascades(如果您有更好的资源,请告诉我):
https://github.com/opencv/opencv/tree/master/data/haarcascades
这是图片:
在我第一次进行大型联运时,它只能检测到右车*的车牌(两次),但是不能识别白车上的车牌。
第二次上课时,出现错误,我不知道它是什么意思,以及如何解决它,这是错误:
cascadedetect.cpp:567: error: (-2:Unspecified error) in function 'bool __thiscall cv::HaarEvaluator::Feature::read(const class cv::FileNode &,const class cv::Size_<int> &)'
> Invalid HAAR feature (expected: 'rw.r.x < W'),where
> 'rw.r.x' is 32
> must be less than
> 'W' is 16
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\nenad\OneDrive\Desktop\open cv slika\Tablice\tablica.py",line 14,in <module>
plates_cascade = cv2.Cascadeclassifier('haarcascade_licence_plate_rus_16stages.xml')
SystemError: <class 'cv2.Cascadeclassifier'> returned a result with an error set
我认为问题不在于这些级联飞机具有俄文车牌,我在网上看到了很多,俄文车牌看起来与其他相似。 这是我写的代码:
# Standard imports
import cv2
import numpy as np
# Read image
img = cv2.imread("slika2.jpg",1)
gray = cv2.cvtColor(img,0)
cv2.imshow('img',gray)
cv2.waitKey(0)
#read haarcascade
#plates_cascade = cv2.Cascadeclassifier('haarcascade_russian_plate_number.xml') #does not give me error,but result is not correct
plates_cascade = cv2.Cascadeclassifier('haarcascade_licence_plate_rus_16stages.xml') #gives me error
plates = plates_cascade.detectMultiScale(gray,1.2,4)
for (x,y,w,h) in plates:
#detect plate with rectangle
#rec. start point (x,y),rec. end point (x+w,y+h),blue color(255,0),line width 1
plates_rec = cv2.rectangle(img,(x,(x+w,(0,255,1)
#cv2.putText(plates_rec,'Text',y-3),cv2.FONT_HERSHEY_SIMPLEX,0.5,1)
gray_plates = gray[y:y+h,x:x+w]
color_plates = img[y:y+h,x:x+w]
#cv2.imshow('img',gray_plates)
#cv2.waitKey(0)
height,width,chanel = gray_plates.shape
print(height,width)
cv2.imshow('img',img)
cv2.waitKey(0)
print('Number of detected licence plates:',len(plates))
任何建议如何改善我的代码,并解决此问题? 另外,如果您能告诉我如何创建自己的haar级联,我已经遍及整个网络,但是找不到任何可行的解决方案。