I try to create different imageManipConfig in script node to cover the entire region of interest (it's big). however, the script get stuck for some reasons
#!/usr/bin/env python3
import cv2
import depthai as dai
DEBUG = True
WITH_IDENTITY = True
# Create pipeline
pipeline = dai.Pipeline()
# Define source and output
camRgb = pipeline.create(dai.node.ColorCamera)
nnManip = pipeline.create(dai.node.ImageManip)
trackerManip = pipeline.create(dai.node.ImageManip)
xoutNNManip = pipeline.create(dai.node.XLinkOut)
xoutTrackerManip = pipeline.create(dai.node.XLinkOut)
script = pipeline.createScript()
script.setScript("""
import time
msgs = []
configs = [
{
"width": 300,
"height": 200,
"x": lambda x: x // 100 * 28,
"y": lambda y: y // 100 * 45,
},
{
"width": 700,
"height": 700,
"x": lambda x: x // 100 * 26,
"y": lambda y: y // 100 * 70
},
{
"width": 1080,
"height": 1080,
"x": lambda x: x // 100 * 28,
"y": lambda y: y // 100 * 88,
},
]
while True:
time.sleep(0.001) # Avoid lazy looping
img = node.io['preview'].get()
node.warn(f'Got frame {img}')
for i, config in enumerate(configs):
cfg1 = ImageManipConfig()
cfg2 = ImageManipConfig()
node.warn(f"Sending {i + 1}")
rgbRect = RotatedRect()
rgbRect.center.x = config['x'](img.getWidth())
rgbRect.center.y = config['y'](img.getHeight())
rgbRect.size = Size2f(config['width'], config['height'])
cfg1.setCropRotatedRect(rgbRect, False)
cfg1.setReusePreviousImage(True)
cfg1.setResize(300, 300)
cfg2.setCropRotatedRect(rgbRect, False)
cfg2.setReusePreviousImage(True)
node.io['manip_img'].send(img)
node.io['cfg1'].send(cfg1)
node.io['cfg2'].send(cfg2)
""")
nnManip.setWaitForConfigInput(True)
nnManip.setResize(300, 300)
nnManip.setMaxOutputFrameSize(300*300*3)
trackerManip.setWaitForConfigInput(True)
trackerManip.setResize(1080, 1080)
trackerManip.setMaxOutputFrameSize(1080*1080*3)
xoutNNManip.setStreamName("manip_img")
xoutTrackerManip.setStreamName("tracker_img")
camRgb.setPreviewSize(1920, 1080)
camRgb.setInterleaved(False)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
camRgb.preview.link(script.inputs['preview'])
script.outputs['manip_img'].link(xoutNNManip.input)
script.outputs['cfg1'].link(nnManip.inputConfig)
script.outputs['manip_img'].link(trackerManip.inputImage)
script.outputs['cfg2'].link(trackerManip.inputConfig)
nnManip.out.link(xoutNNManip.input)
trackerManip.out.link(xoutTrackerManip.input)
def run_camera():
print('starting')
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
qNNManip = device.getOutputQueue("manip_img", 4, False)
qTrackerManip = device.getOutputQueue("tracker_img", 4, False)
while True:
nnFrameObj = qNNManip.get()
cv2.imshow("nn", nnFrameObj.getCvFrame())
trackerFrameObj = qTrackerManip.get()
cv2.imshow("tracker", trackerFrameObj.getCvFrame())
if cv2.waitKey(1) == ord('q'):
break
run_camera()
[18443010310B6D0E00] [1.5] [1.431] [Script(5)] [warning] Got frame <lpb.ImgFrame object at 0x8277da60>
[18443010310B6D0E00] [1.5] [1.431] [Script(5)] [warning] Sending 1
[18443010310B6D0E00] [1.5] [1.437] [Script(5)] [warning] Sending 2
[18443010310B6D0E00] [1.5] [1.455] [Script(5)] [warning] Sending 3
[18443010310B6D0E00] [1.5] [1.463] [Script(5)] [warning] Got frame <lpb.ImgFrame object at 0x8277d980>
[18443010310B6D0E00] [1.5] [1.463] [Script(5)] [warning] Sending 1
[18443010310B6D0E00] [1.5] [1.468] [Script(5)] [warning] Sending 2
[18443010310B6D0E00] [1.5] [1.471] [Script(5)] [warning] Sending 3
[18443010310B6D0E00] [1.5] [1.476] [Script(5)] [warning] Got frame <lpb.ImgFrame object at 0x8277d960>
[18443010310B6D0E00] [1.5] [1.477] [Script(5)] [warning] Sending 1
[18443010310B6D0E00] [1.5] [1.509] [Script(5)] [warning] Sending 2
[18443010310B6D0E00] [1.5] [1.512] [Script(5)] [warning] Sending 3
[18443010310B6D0E00] [1.5] [1.518] [Script(5)] [warning] Got frame <lpb.ImgFrame object at 0x8277da00>
[18443010310B6D0E00] [1.5] [1.518] [Script(5)] [warning] Sending 1