-
Notifications
You must be signed in to change notification settings - Fork 0
/
anaglyphcam.py
executable file
·67 lines (52 loc) · 2.23 KB
/
anaglyphcam.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
#!/usr/bin/env python3
import cv2
import numpy as np
import depthai as dai
import pyvirtualcam
from pyvirtualcam import PixelFormat
pipeline = dai.Pipeline()
Left = pipeline.create(dai.node.MonoCamera)
Right = pipeline.create(dai.node.MonoCamera)
stereo = pipeline.create(dai.node.StereoDepth)
xoutLeft = pipeline.create(dai.node.XLinkOut)
xoutRight = pipeline.create(dai.node.XLinkOut)
xoutRectifLeft = pipeline.create(dai.node.XLinkOut)
xoutRectifRight = pipeline.create(dai.node.XLinkOut)
xoutMerged = pipeline.create(dai.node.XLinkOut)
Left.setBoardSocket(dai.CameraBoardSocket.LEFT)
Left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
Right.setBoardSocket(dai.CameraBoardSocket.RIGHT)
Right.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
stereo.initialConfig.setMedianFilter(dai.StereoDepthProperties.MedianFilter.KERNEL_7x7) # KERNEL_7x7 default
xoutLeft.setStreamName("left")
xoutRight.setStreamName("right")
xoutRectifLeft.setStreamName("rectifiedLeft")
xoutRectifRight.setStreamName("rectifiedRight")
xoutMerged.setStreamName("merged")
Left.out.link(stereo.left)
Right.out.link(stereo.right)
stereo.syncedLeft.link(xoutLeft.input)
stereo.syncedRight.link(xoutRight.input)
stereo.rectifiedLeft.link(xoutRectifLeft.input)
stereo.rectifiedRight.link(xoutRectifRight.input)
streams = ["left", "right", "rectifiedLeft", "rectifiedRight"]
blackImg = np.full((720,1280,1), (0), np.uint8)
camera = pyvirtualcam.Camera(1280, 720, 20, fmt=PixelFormat.BGR, print_fps=True, device='/dev/video23')
with dai.Device(pipeline) as device:
qList = [device.getOutputQueue(stream, 8, blocking=False) for stream in streams]
while True:
for q in qList:
name = q.getName()
frame = q.get().getCvFrame()
if name == "rectifiedLeft":
frameleft = frame
elif name == "rectifiedRight":
frameright = frame
framemerged = cv2.merge((frameright, blackImg, frameleft))
cv2.imshow("Anaglyph View", framemerged)
camera.send(framemerged)
if cv2.waitKey(1) == ord("q"):
break
cv2.destroyAllWindows()
camera.close()