Hi all,
I am just starting to experiment with some features of depthai. In order to speed up transfer and reduce computation time, i would like to do some image manipulation such as cropping on the still image. But the cropping leads to unexpected sizes or even crashes. Here is what I've tried. Am I getting something wrong?
Version: 2.17.3.1
OAK-D Lite
Thanks,
Christoph
import depthai as dai
import cv2
pipeline = dai.Pipeline()
cam = pipeline.createColorCamera()
cam.setBoardSocket(dai.CameraBoardSocket.RGB)
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_13_MP)
cam.setIspScale(1,4)
w0,h0 = cam.getStillWidth(), cam.getStillHeight()
still_manip = pipeline.create(dai.node.ImageManip)
still_manip.setMaxOutputFrameSize(3*w0*h0)
still_manip.inputConfig.setWaitForMessage(True)
cam.still.link(still_manip.inputImage)
xout_still = pipeline.createXLinkOut()
xout_still.setStreamName("still")
still_manip.out.link(xout_still.input)
control_in = pipeline.create(dai.node.XLinkIn)
control_in.setStreamName('control')
control_in.out.link(cam.inputControl)
still_config_in = pipeline.create(dai.node.XLinkIn)
still_config_in.setStreamName('still_config')
still_config_in.out.link(still_manip.inputConfig)
device = dai.Device(pipeline)
stream_still = device.getOutputQueue(name="still", maxSize=1, blocking=False)
control_queue = device.getInputQueue('control')
still_config_queue = device.getInputQueue('still_config')
print("orig size")
print(w0,h0) # --> 1048 780
#rect = (0.0, 0.0, 1, 1) # --> crop size: 1024 780 (why not original size?)
#rect = (0.0, 0.0, 0.5, 0.5) # --> crop size: 512 390, but not from 0,0 but some arbitrary point.
# Also image is stretched by a factor of (approximately?) 2
rect = (0.0, 0.0, 0.8, 0.8) # crashes at frame = stream_still.get().getCvFrame() with
# color.simd_helpers.hpp:108: error: (-215:Assertion failed) sz.width % 2 == 0 && sz.height % 3 == 0
print(rect)
cfg = dai.ImageManipConfig()
cfg.setCropRect(*rect)
still_config_queue.send(cfg)
ctrl = dai.CameraControl()
ctrl.setCaptureStill(True)
control_queue.send(ctrl)
frame = stream_still.get().getCvFrame()
print("crop size")
print(*frame.shape[1::-1])
cv2.imshow("frame", frame)
cv2.waitKey(0)