-
-
Save Erol444/4cead08da26adb1fddf4d7a8ec2d66e2 to your computer and use it in GitHub Desktop.
DepthAI - Rotate and crop (300x300) rgb frame
This file contains 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 depthai as dai | |
# Create pipeline | |
pipeline = dai.Pipeline() | |
# Rotate color frames | |
camRgb = pipeline.createColorCamera() | |
camRgb.setPreviewSize(640, 400) | |
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) | |
camRgb.setInterleaved(False) | |
manipRgb = pipeline.createImageManip() | |
rgbRr = dai.RotatedRect() | |
rgbRr.center.x, rgbRr.center.y = camRgb.getPreviewWidth() // 2, camRgb.getPreviewHeight() // 2 | |
rgbRr.size.width, rgbRr.size.height = camRgb.getPreviewHeight(), camRgb.getPreviewWidth() | |
rgbRr.angle = 90 | |
manipRgb.initialConfig.setCropRotatedRect(rgbRr, False) | |
camRgb.preview.link(manipRgb.inputImage) | |
cropManip = pipeline.createImageManip() | |
cropManip.initialConfig.setResize(300, 300) | |
manipRgb.out.link(cropManip.inputImage) | |
manipRgbOut = pipeline.createXLinkOut() | |
manipRgbOut.setStreamName("manip_rgb") | |
cropManip.out.link(manipRgbOut.input) | |
with dai.Device(pipeline) as device: | |
qRgb = device.getOutputQueue(name="manip_rgb", maxSize=8, blocking=False) | |
while True: | |
inRgb = qRgb.tryGet() | |
if inRgb is not None: | |
frame = inRgb.getCvFrame() | |
print(frame.shape) | |
cv2.imshow('Color rotated', frame) | |
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