只是玩弄用opencv和openalpr在网络摄像头流上绘图,我让他们两个都在自己工作,但是当我把它们加在一起时,我得到了这个错误。
Invalid pattern provided: auwide
Valid patterns are located in the auwide.patterns file
Plate #1
Plate Confidence
- 6U01 82.790466
Traceback (most recent call last):
File "C:/Users/Alex/PycharmProjects/displayrec/testing.py", line 31, in
<module>
rec = plate.detectMultiScale(frame, 1.3, 5)
AttributeError: 'dict' object has no attribute 'detectMultiScale'
Process finished with exit code 1
我在这里读过Python OpenCV 人脸检测代码有时会引发“元组”对象没有属性“形状”
我尝试将其添加到我的代码中,但仍然出现相同的错误。
这很奇怪,因为它工作了一秒钟并抛出了部分板块,但随后因上面的错误而崩溃。
import numpy as np
import cv2
import sys
import os
from openalpr import Alpr
alpr = Alpr("auwide", "openalpr.conf", "runtime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
sys.exit(1)
alpr.set_top_n(1)
alpr.set_default_region("auwide")
plate = cv2.CascadeClassifier('au.xml')
vc = cv2.VideoCapture(0)
while True:
ret, frame = vc.read()
img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
noise_removal = cv2.bilateralFilter(img_gray, 9, 75, 75)
equal_histogram = cv2.equalizeHist(noise_removal)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
morph_image = cv2.morphologyEx(equal_histogram, cv2.MORPH_OPEN, kernel,
iterations=15)
sub_morp_image = cv2.subtract(equal_histogram,morph_image)
rec = plate.detectMultiScale(frame, 1.3, 5)
for (x, y, w, h) in rec:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
roi_gray = frame[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
cv2.imshow("Result",frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if ret:
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.imwrite("img.jpg", sub_morp_image)
results = alpr.recognize_file("img.jpg")
i = 0
for plate in results['results']:
i += 1
print("Plate #%d" % i)
print(" %12s %12s" % ("Plate", "Confidence"))
for candidate in plate['candidates']:
prefix = "-"
if candidate['matches_template']:
prefix = "*"
print(" %s %12s%12f" % (prefix, candidate['plate'],
candidate['confidence']))
else:
break;
vc.release()
alpr.unload()
cv2.destroyAllWindows()