ipazc / mtcnn

MTCNN face detection implementation for TensorFlow, as a PIP package.
MIT License
2.18k stars 526 forks source link

Generate a new image with bounding box and circles #25

Open Maxwell2016LeChouchou opened 5 years ago

Maxwell2016LeChouchou commented 5 years ago

Hello, thanks for sharing your code

How to generate a new image with bounding box and circles?

I tried to code:

from mtcnn.mtcnn import MTCNN import cv2

img = cv2.imread("max.jpg") detector = MTCNN() print(detector.detect_faces(img)) image = cv2.imwrite("max_drawn.jpg",img)

(max.jpg is my picture)

thank you

SpeedOfSpin commented 5 years ago

Something like this

image = cv2.imread("max.jpg") result = detector.detect_faces(image)

bounding_box = result[0]['box'] keypoints = result[0]['keypoints']

cv2.rectangle(image, (bounding_box[0], bounding_box[1]), (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]), (0,155,255), 2) cv2.circle(image,(keypoints['left_eye']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['right_eye']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['nose']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['mouth_left']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['mouth_right']), 2, (0,155,255), 2)

cv2.imwrite("max_drawn.jpg", image) cv2.namedWindow("image") cv2.imshow("image",image) cv2.waitKey(0)

Maxwell2016LeChouchou commented 5 years ago

Hello  Yes, thank you, i am using plt plot instead of cv.2 imshow but I have solved the problem. Do you mind if i add you on the wechat? I am chinese, but i have been studying in Canada since 2010. My wechat: wangjianzhou159162 谢谢 Maxwell (汪见舟) On Thursday, November 22, 2018, 12:12:24 PM EST, SpeedOfSpin notifications@github.com wrote:

Something like this

image = cv2.imread("max.jpg") result = detector.detect_faces(image)

bounding_box = result[0]['box'] keypoints = result[0]['keypoints']

cv2.rectangle(image, (bounding_box[0], bounding_box[1]), (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]), (0,155,255), 2) cv2.circle(image,(keypoints['left_eye']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['right_eye']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['nose']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['mouth_left']), 2, (0,155,255), 2) cv2.circle(image,(keypoints['mouth_right']), 2, (0,155,255), 2)

cv2.imwrite("max_drawn.jpg", image) cv2.namedWindow("image") cv2.imshow("image",image) cv2.waitKey(0)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.