Created
March 1, 2023 11:27
-
-
Save Erol444/0502ee9355aaa03265878d807517169a to your computer and use it in GitHub Desktop.
Blend 3 camera frames together
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import cv2 | |
import numpy as np | |
import depthai as dai | |
# Optional. If set (True), the ColorCamera is downscaled from 1080p to 720p. | |
# Otherwise (False), the aligned depth is automatically upscaled to 1080p | |
downscaleColor = True | |
fps = 30 | |
# The disparity is computed at this resolution, then upscaled to RGB resolution | |
monoResolution = dai.MonoCameraProperties.SensorResolution.THE_720_P | |
streams = ['left', 'right', 'rgb'] | |
# Create pipeline | |
pipeline = dai.Pipeline() | |
# Define sources and outputs | |
camRgb = pipeline.create(dai.node.ColorCamera) | |
left = pipeline.create(dai.node.MonoCamera) | |
right = pipeline.create(dai.node.MonoCamera) | |
for stream in streams: | |
xout = pipeline.create(dai.node.XLinkOut) | |
xout.setStreamName(stream) | |
if stream == 'left': | |
left.out.link(xout.input) | |
if stream == 'right': | |
right.out.link(xout.input) | |
elif stream == 'rgb': | |
camRgb.video.link(xout.input) | |
#Properties | |
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB) | |
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) | |
camRgb.setFps(fps) | |
camRgb.setIspScale(2, 3) | |
left.setResolution(monoResolution) | |
left.setBoardSocket(dai.CameraBoardSocket.LEFT) | |
left.setFps(fps) | |
right.setResolution(monoResolution) | |
right.setBoardSocket(dai.CameraBoardSocket.RIGHT) | |
right.setFps(fps) | |
with dai.Device(pipeline) as device: | |
leftQ = device.getOutputQueue(name="left", maxSize=4, blocking=False) | |
rightQ = device.getOutputQueue(name="right", maxSize=4, blocking=False) | |
rgbQ = device.getOutputQueue(name="rgb", maxSize=4, blocking=False) | |
while True: | |
frameLeft = cv2.cvtColor(leftQ.get().getCvFrame(), cv2.COLOR_GRAY2BGR) | |
frameRight = cv2.cvtColor(rightQ.get().getCvFrame(), cv2.COLOR_GRAY2BGR) | |
frameRgb = rgbQ.get().getCvFrame() | |
blended = cv2.addWeighted(frameRgb, 0.5, frameLeft, 0.5, 0) | |
blended = cv2.addWeighted(blended, 0.66, frameRight, 0.33, 0) | |
cv2.imshow('blended', blended) | |
if cv2.waitKey(1) == ord('q'): | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment