serengil / tensorflow-101

TensorFlow 101: Introduction to Deep Learning

Home Page:https://www.youtube.com/watch?v=YjYIMs5ZOfc&list=PLsS_1RYmYQQGxpKV44jsxXNgjEpRoW61w&index=2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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