Replace harcascade with DNN
Kingbadger3d opened this issue · comments
Hi again Serengil, Thanks for the help.
Im trying to replace the harcascade with the dnn module from opencv, Ive got the dnn working recogniseing the faces but the bounding box's return are rectangles, not box's.
The perfect ratio seems to be 1.35 * dnn_rect.width, here's the origninal code:
# compute the (x, y)-coordinates of the bounding box for the
# object
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
# draw the bounding box of the face along with the associated
# probability
text = "{:.2f}%".format(confidence * 100)
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(frame, (startX, startY ), (endX, endY), (255, 255, 255), 1)
cv2.putText(frame, text, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (255, 255, 255), 1)
How is best to change the above code to take the bounding rectangle width from the dnn and do the 1.35 * dnn_rect.width to still be able to run the face emotion detector code on the resulting cropped square.
Cheers J
This project will help you: https://github.com/serengil/tensorflow-101/blob/master/python/age-gender-prediction-real-time.py
Regards