Created
February 26, 2024 08:04
-
-
Save VanDavv/80b420dcfed1d5a957fa39e92a3cd535 to your computer and use it in GitHub Desktop.
Convert RGB stream to grayscale using DepthAI ImageManip node
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
import cv2 | |
import depthai as dai | |
pipeline = dai.Pipeline() | |
cam = pipeline.create(dai.node.ColorCamera) | |
cam.setCamera("color") | |
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) | |
manip = pipeline.create(dai.node.ImageManip) | |
manip.initialConfig.setResize(300, 300) | |
manip.initialConfig.setFrameType(dai.ImgFrame.Type.GRAY8) | |
manipOut = pipeline.create(dai.node.XLinkOut) | |
manipOut.setStreamName("manip") | |
camOut = pipeline.create(dai.node.XLinkOut) | |
camOut.setStreamName("cam") | |
cam.video.link(manip.inputImage) | |
manip.out.link(manipOut.input) | |
cam.video.link(camOut.input) | |
with dai.Device(pipeline) as device: | |
qManip = device.getOutputQueue("manip", maxSize=4, blocking=False) | |
qCam = device.getOutputQueue("cam", maxSize=4, blocking=False) | |
while True: | |
inManip = qManip.tryGet() | |
inCam = qCam.tryGet() | |
if inManip is not None: | |
cv2.imshow("manip", inManip.getCvFrame()) | |
if inCam is not None: | |
cv2.imshow("cam", inCam.getCvFrame()) | |
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