herrDeng網內搜尋

自訂搜尋

Ads

2023年7月13日 星期四

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

 
Python程式碼如下:
print('簡易測試mediapipe')
import cv2
import mediapipe as mp

print(cv2.__version__)
print(mp.__version__)
print('要先會用cv2.VideoCapture')

mp_face_detect=mp.solutions.face_detection
mp_draw=mp.solutions.drawing_utils

cap=cv2.VideoCapture(0)
face_detect=mp_face_detect.FaceDetection()

while cap.isOpened():
    ret, im=cap.read()
    if ret==False:
        break
    else:
        im2=cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
        result=face_detect.process(im2)
        if result.detections:
            for detect in  result.detections:
                mp_draw.draw_detection(im, detect)
        cv2.imshow('video', im)
        if cv2.waitKey(1)>0:
            break
face_detect.close()
cv2.destroyAllWindows()
cap.release()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章