1+ #!/usr/bin/env python3
2+
3+ import cv2
4+ import depthai as dai
5+
6+ # Create pipeline
7+ pipeline = dai .Pipeline ()
8+
9+ # Rotate color frames
10+ camRgb = pipeline .createColorCamera ()
11+ camRgb .setPreviewSize (640 , 400 )
12+ camRgb .setResolution (dai .ColorCameraProperties .SensorResolution .THE_1080_P )
13+ camRgb .setInterleaved (False )
14+
15+ manipRgb = pipeline .createImageManip ()
16+ rgbRr = dai .RotatedRect ()
17+ rgbRr .center .x , rgbRr .center .y = camRgb .getPreviewWidth () // 2 , camRgb .getPreviewHeight () // 2
18+ rgbRr .size .width , rgbRr .size .height = camRgb .getPreviewHeight (), camRgb .getPreviewWidth ()
19+ rgbRr .angle = 90
20+ manipRgb .initialConfig .setCropRotatedRect (rgbRr , False )
21+ camRgb .preview .link (manipRgb .inputImage )
22+
23+ manipRgbOut = pipeline .createXLinkOut ()
24+ manipRgbOut .setStreamName ("manip_rgb" )
25+ manipRgb .out .link (manipRgbOut .input )
26+
27+ # Rotate mono frames
28+ monoLeft = pipeline .createMonoCamera ()
29+ monoLeft .setResolution (dai .MonoCameraProperties .SensorResolution .THE_400_P )
30+ monoLeft .setBoardSocket (dai .CameraBoardSocket .LEFT )
31+
32+ manipLeft = pipeline .createImageManip ()
33+ rr = dai .RotatedRect ()
34+ rr .center .x , rr .center .y = monoLeft .getResolutionWidth () // 2 , monoLeft .getResolutionHeight () // 2
35+ rr .size .width , rr .size .height = monoLeft .getResolutionHeight (), monoLeft .getResolutionWidth ()
36+ rr .angle = 90
37+ manipLeft .initialConfig .setCropRotatedRect (rr , False )
38+ monoLeft .out .link (manipLeft .inputImage )
39+
40+ manipLeftOut = pipeline .createXLinkOut ()
41+ manipLeftOut .setStreamName ("manip_left" )
42+ manipLeft .out .link (manipLeftOut .input )
43+
44+ with dai .Device (pipeline ) as device :
45+ qLeft = device .getOutputQueue (name = "manip_left" , maxSize = 8 , blocking = False )
46+ qRgb = device .getOutputQueue (name = "manip_rgb" , maxSize = 8 , blocking = False )
47+
48+ while True :
49+ inLeft = qLeft .tryGet ()
50+ if inLeft is not None :
51+ cv2 .imshow ('Left rotated' , inLeft .getCvFrame ())
52+
53+ inRgb = qRgb .tryGet ()
54+ if inRgb is not None :
55+ cv2 .imshow ('Color rotated' , inRgb .getCvFrame ())
56+
57+ if cv2 .waitKey (1 ) == ord ('q' ):
58+ break
0 commit comments