当前位置:   article > 正文

使用mediapipe进行人脸识别_mediapipe人脸识别

mediapipe人脸识别
  1. import cv2
  2. import mediapipe as mp
  3. import time
  4. cap = cv2.VideoCapture('C:/Users/Curry\Desktop/Kobe.mp4',0)
  5. mpFace_dec = mp.solutions.face_detection
  6. mpdraw = mp.solutions.drawing_utils
  7. face_dec = mpFace_dec.FaceDetection(0.75)
  8. Pre_time = 0
  9. while 1:
  10. res, img = cap.read()
  11. img_rgb = cv2.cvtColor(img, code=cv2.COLOR_BGR2RGB)
  12. Results = face_dec.process(img_rgb)
  13. # print(Results)
  14. if Results.detections:
  15. for id, detection in enumerate(Results.detections):
  16. # mpdraw.draw_detection(img, detection)
  17. # print(id, detection)
  18. # print(detection.score)
  19. # print(detection.location_data.relative_bounding_box)
  20. bboxC = detection.location_data.relative_bounding_box
  21. h,w,c = img.shape
  22. bbox = int(bboxC.xmin*w),int(bboxC.ymin*h),\
  23. int(bboxC.width*w),int(bboxC.height*h)
  24. cv2.rectangle(img, bbox, (255, 0, 255), 2)
  25. cur_Time = time.time()
  26. fps = 1/(cur_Time-Pre_time)
  27. Pre_time = cur_Time
  28. cv2.putText(img, 'FPS:{}'.format(int(fps)), (20, 70),
  29. cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 2)
  30. cv2.imshow('kobe', img)
  31. cv2.waitKey(1)

  1. import cv2
  2. import mediapipe as mp
  3. import time
  4. cap = cv2.VideoCapture('C:/Users/Curry\Desktop/kobe.mp4',0)
  5. mpFace_dec = mp.solutions.face_detection
  6. mpdraw = mp.solutions.drawing_utils
  7. face_dec = mpFace_dec.FaceDetection(0.75)
  8. Pre_time = 0
  9. while 1:
  10. res, img = cap.read()
  11. img_rgb = cv2.cvtColor(img, code=cv2.COLOR_BGR2RGB)
  12. Results = face_dec.process(img_rgb)
  13. # print(Results)
  14. if Results.detections:
  15. for id, detection in enumerate(Results.detections):
  16. # mpdraw.draw_detection(img, detection)
  17. # print(id, detection)
  18. # print(detection.score)
  19. # print(detection.location_data.relative_bounding_box)
  20. bboxC = detection.location_data.relative_bounding_box
  21. h,w,c = img.shape
  22. bbox = int(bboxC.xmin * w), int(bboxC.ymin * h), \
  23. int(bboxC.width * w), int(bboxC.height * h)
  24. cv2.rectangle(img, bbox, (255, 0, 255), 2)
  25. cv2.putText(img, f'{int(detection.score[0]*100)}%',(bbox[0],bbox[1]-20),
  26. cv2.FONT_HERSHEY_PLAIN,2,(255, 0, 255), 2)
  27. cur_Time = time.time()
  28. fps = 1/(cur_Time-Pre_time)
  29. Pre_time = cur_Time
  30. cv2.putText(img, 'FPS:{}'.format(int(fps)), (20, 70),
  31. cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 2)
  32. cv2.imshow('kobe', img)
  33. cv2.waitKey(1)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/906152
推荐阅读
相关标签
  

闽ICP备14008679号