-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_hand_detection_mediapipe.py
70 lines (55 loc) · 2.14 KB
/
run_hand_detection_mediapipe.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import argparse
import threading
from grasp_int import HandDetectors as hd
from grasp_int import ObjectDetectors as od
from grasp_int import Devices as dv
from grasp_int import Scene as sc
import pickle
import cv2
class GraspingDetector:
def __init__(self, hand_detection='hybridOAKMediapipe', object_detection='cosypose') -> None:
self.hand_detection_mode = hand_detection
self.object_detection_mode = object_detection
self.hand_detector = hd.get_hand_detector(hand_detection, None)
self.scene = sc.Scene( hand_detector= self.hand_detector)
self.object_task_done = True
def run(self):
print(self.__dict__)
self.hand_detector.start()
print('start')
while self.hand_detector.isOn():
success, img = self.hand_detector.next_frame()
if not success:
continue
hands = self.hand_detector.get_hands()
self.scene.update_hands(hands)
#img.flags.writeable = False
img.flags.writeable = True
if self.scene.render(img):
print('end')
self.stop()
break
exit()
def stop(self):
self.hand_detector.stop()
self.scene.stop()
G=self.scene.mesh_scene.copy().graph
with open('my_graph', 'wb') as f:
pickle.dump(G, f)
exit()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-hd', '--hand_detection', choices=['mediapipe', 'depthai', 'hybridOAKMediapipe'],
default = 'hybridOAKMediapipe', help="Hand pose reconstruction solution")
parser.add_argument('-od', '--object_detection', choices=['cosypose, megapose'],
default = 'cosypose', help="Object pose reconstruction detection")
args = vars(parser.parse_args())
# if args.hand_detection == 'mediapipe':
# import mediapipe as mp
# else:
# import depthai as dai
# if args.object_detection == 'cosypose':
# import cosypose
grasp_int = GraspingDetector(**args)
grasp_int.run()