Hi,
After successfully running python face detection example, I tried to modify the code in order to run vehicle and licence plate detection, but the model didn't detect anything. As I haven't figured out what's the issue, I would appreciate any suggestion regarding the problem.
The script I wrote looks as follows:
import cv2
def predict(frame, net):
# Prepare input blob and perform an inference
blob = cv2.dnn.blobFromImage(frame, size=(300, 300), ddepth=cv2.CV_8U)
net.setInput(blob)
out = net.forward()
predictions = []
# The net outputs a blob with the shape: [1, 1, N, 7], where N is the number of detected bounding boxes.
# For each detection, the description has the format: [image_id, label, conf, x_min, y_min, x_max, y_max]
# Draw detected faces on the frame
for detection in out.reshape(-1, 7):
image_id, label, conf, x_min, y_min, x_max, y_max = detection
if conf > 0.5:
predictions.append(detection)
# return the list of predictions to the calling function
return predictions
# Load the model
net = cv2.dnn.readNet('models/vehicle-license-plate-detection-barrier-0106.xml', 'models/vehicle-license-plate-detection-barrier-0106.bin')
# Specify target device
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
# Read an image
frame = cv2.imread('screenshots/mercedes.jpg')
predictions = predict(frame, net)
# Draw detected faces on the frame
for prediction in predictions:
confidence = float(detection[2])
xmin = int(detection[3] * frame.shape[1])
ymin = int(detection[4] * frame.shape[0])
xmax = int(detection[5] * frame.shape[1])
ymax = int(detection[6] * frame.shape[0])
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
# Save the frame to an image file
cv2.imwrite('out.png', frame)
Basically, I have downloaded the model files from this adddress and then modified input dimensions according to specifications.