I am trying to create a number plate detection with the following code but it fails when I try to get the plate from the processed image.
plate_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'https://raw.githubusercontent.com/SarthakV7/AI-based-indian-license-plate-detection/master/indian_license_plate.xml')
def detect_plate(img, text=''):
plate_img = img.copy()
roi = img.copy()
plate_rect = plate_cascade.detectMultiScale(plate_img, scaleFactor = 1.2, minNeighbors = 7) # detects numberplates and returns the coordinates and dimensions of detected license plate's contours.
for (x,y,w,h) in plate_rect:
roi_ = roi[y:y+h, x:x+w, :]
plate = roi[y:y+h, x:x+w, :]
cv2.rectangle(plate_img, (x+2,y), (x+w-3, y+h-5), (51,181,155), 3)
if text!='':
plate_img = cv2.putText(plate_img, text, (x-w//2,y-h//2),
cv2.FONT_HERSHEY_COMPLEX_SMALL , 0.5, (51,181,155), 1, cv2.LINE_AA)
return plate_img, plate # returning the processed image.
# Testing the above function
def display(img_, title=''):
img = cv2.cvtColor(img_, cv2.COLOR_BGR2RGB)
fig = plt.figure(figsize=(10,6))
ax = plt.subplot(111)
ax.imshow(img)
plt.axis('off')
plt.title(title)
plt.show()
img = io.imread('https:///automatic-giggle/cef27d2274a17835ac4b9c044382131e0fba139d/car_test.jpeg')
display(img, 'input image')
# Getting plate prom the processed image
output_img, plate = detect_plate(img)
I then receive the following error message:
Error: OpenCV(4.6.0) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'