-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetection
31 lines (27 loc) · 967 Bytes
/
detection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
import mediapipe as mp
#to draw
mpd=mp.solutions.drawing_utils
mpp=mp.solutions.pose
#for camera
cap=cv2.VideoCapture(0)#change to 1 if there is external camera
with mpp.Pose(min_detection_confidence=0.5,min_tracking_confidence=0.5) as pose:
while cap.isOpened():
ret,frame=cap.read()
#recolor image
image=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
image.flags.writeable=False
#make detections
r=pose.process(image)
image.flags.writeable=True
image=cv2.cvtColor(image,cv2.COLOR_RGB2BGR)
print(r)
#renderdetection
mpd.draw_landmarks(image,r.pose_landmarks,mpp.POSE_CONNECTIONS,
mpd.DrawingSpec(color=(254,120,69),thickness=2,circle_radius=2),
mpd.DrawingSpec(color=(254,156,89),thickness=2,circle_radius=2)) #changecolor as your wish (255,255,255)
cv2.imshow("ars",image)
if cv2.waitKey(10) & 0xff==ord('q'):
break
cap.release()
cv2.destroyAllWindows()