-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAK_Cam.py
150 lines (110 loc) · 4.15 KB
/
OAK_Cam.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import cv2
import depthai as dai
import time
def make_color_pipe():
# Create pipeline
pipeline = dai.Pipeline()
# Define source and output
camRgb = pipeline.create(dai.node.ColorCamera)
xoutVideo = pipeline.create(dai.node.XLinkOut)
controlIn = pipeline.create(dai.node.XLinkIn)
controlIn.setStreamName("control")
xoutVideo.setStreamName("video")
# Properties
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
camRgb.setVideoSize(1280, 720)
camRgb.setFps(35)
# xoutVideo.input.setBlocking(False)
# xoutVideo.input.setQueueSize(1)
# Linking
camRgb.video.link(xoutVideo.input)
controlIn.out.link(camRgb.inputControl)
return (pipeline)
def make_mono_right_pipe():
pipeline = dai.Pipeline()
monoRight = pipeline.create(dai.node.MonoCamera)
xoutRight = pipeline.create(dai.node.XLinkOut)
controlIn = pipeline.create(dai.node.XLinkIn)
controlIn.setStreamName("control")
xoutRight.setStreamName("right")
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_480_P)
monoRight.setFps(99)
monoRight.out.link(xoutRight.input)
controlIn.out.link(monoRight.inputControl)
return(pipeline)
def make_mono_left_pipe():
pipeline = dai.Pipeline()
monoLeft = pipeline.create(dai.node.MonoCamera)
xoutLeft = pipeline.create(dai.node.XLinkOut)
controlIn = pipeline.create(dai.node.XLinkIn)
controlIn.setStreamName("control")
xoutLeft.setStreamName("left")
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_480_P)
monoLeft.setFps(99)
monoLeft.out.link(xoutLeft.input)
controlIn.out.link(monoLeft.inputControl)
return(pipeline)
def make_stereo_pipe():
ext = False
sub = True
lr = True
pipeline = dai.Pipeline()
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
depth = pipeline.create(dai.node.StereoDepth)
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('disparity')
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
depth.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
depth.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7)
depth.setLeftRightCheck(lr)
depth.setExtendedDisparity(ext)
depth.setSubpixel(sub)
monoLeft.out.link(depth.left)
monoRight.out.link(depth.right)
depth.disparity.link(xout.input)
return(pipeline,depth)
# pipeline = make_mono_left_pipe()
# with dai.Device(pipeline,usb2Mode=True) as device:
# qRight = device.getOutputQueue(name="right", maxSize=1, blocking=False)
# times = []
# for i in range(1000):
# s = time.time()
# inRight = qRight.get()
# frame = inRight.getCvFrame()
# # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# frame = cv2.resize(frame,(720,480))
# cv2.imshow('frame',frame)
# if cv2.waitKey(1) == ord('q'):
# break
# e = time.time()
# print(i)
# times.append(e-s)
# i+=1
# ave = sum(times)/len(times)
# print('mean: '+str(ave))
# pipeline = make_color_pipe()
# # Connect to device and start pipeline
# with dai.Device(pipeline,usb2Mode=True) as device:
# video = device.getOutputQueue(name="video", maxSize=1, blocking=False)
# times = []
# for i in range(1000):
# s = time.time()
# videoIn = video.get()
# frame = videoIn.getCvFrame()
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# # frame = cv2.resize(frame,(720,480))
# cv2.imshow('frame',frame)
# if cv2.waitKey(1) == ord('q'):
# break
# e = time.time()
# print(e-s)
# times.append(e-s)
# i+=1
# ave = sum(times)/len(times)
# print('mean: '+str(ave))