-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpcv.py
44 lines (33 loc) · 1.36 KB
/
mpcv.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
#pip install mediapipe
#pip install opencv-contrib-python
import cv2
import mediapipe as mp
import time
mp_objectron = mp.solutions.objectron
mp_drawing = mp.solutions.drawing_utils
cap = cv2.VideoCapture(0)
objectron = mp_objectron.Objectron(static_image_mode=False,
max_num_objects=5,
min_detection_confidence=0.4,
min_tracking_confidence=0.70,
model_name='Cup')
while cap.isOpened():
success, image = cap.read()
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = objectron.process(image)
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.detected_objects:
for detected_object in results.detected_objects:
mp_drawing.draw_landmarks(image,
detected_object.landmarks_2d,
mp_objectron.BOX_CONNECTIONS)
mp_drawing.draw_axis(image,
detected_object.rotation,
detected_object.translation)
cv2.imshow('MediaPipe Objectron', cv2.flip(image, 1))
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()