herrDeng網內搜尋

自訂搜尋

Ads

2023年7月13日 星期四

mediapipe安裝python版與測試人臉識別

 
Python程式碼如下:
  1. print('簡易測試mediapipe')
  2. import cv2
  3. import mediapipe as mp
  4. print(cv2.__version__)
  5. print(mp.__version__)
  6. print('要先會用cv2.VideoCapture')
  7. mp_face_detect=mp.solutions.face_detection
  8. mp_draw=mp.solutions.drawing_utils
  9. cap=cv2.VideoCapture(0)
  10. face_detect=mp_face_detect.FaceDetection()
  11. while cap.isOpened():
  12. ret, im=cap.read()
  13. if ret==False:
  14. break
  15. else:
  16. im2=cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
  17. result=face_detect.process(im2)
  18. if result.detections:
  19. for detect in result.detections:
  20. mp_draw.draw_detection(im, detect)
  21. cv2.imshow('video', im)
  22. if cv2.waitKey(1)>0:
  23. break
  24. face_detect.close()
  25. cv2.destroyAllWindows()
  26. cap.release()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章