Skip to content

Commit 5fda1f7

Browse files
committed
Fixed example code. TODO: docs
1 parent 6a1069a commit 5fda1f7

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

examples/Script/script_change_pipeline_flow.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
cam = pipeline.createColorCamera()
1313
cam.setBoardSocket(dai.CameraBoardSocket.RGB)
14+
cam.setInterleaved(False)
1415
cam.setIspScale(2,3)
1516
cam.setVideoSize(720,720)
1617
cam.setPreviewSize(300,300)
@@ -27,11 +28,11 @@
2728

2829
cam.preview.link(script.inputs['rgb'])
2930
script.setScript("""
30-
toggle = True
31+
toggle = False
3132
while True:
3233
msg = node.io['toggle'].tryGet()
3334
if msg is not None:
34-
toggle = not toggle
35+
toggle = msg.getData()[0]
3536
node.warn('Toggle! Perform NN inferencing: ' + str(toggle))
3637
3738
frame = node.io['rgb'].get()
@@ -54,20 +55,20 @@
5455
qRgb = device.getOutputQueue("rgb")
5556
qNn = device.getOutputQueue("nn")
5657

58+
runNn = False
59+
5760
def frameNorm(frame, bbox):
5861
normVals = np.full(len(bbox), frame.shape[0])
5962
normVals[::2] = frame.shape[1]
6063
return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int)
6164

65+
color = (255, 127, 0)
6266
def drawDetections(frame, detections):
63-
color = (255, 0, 0)
6467
for detection in detections:
6568
bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax))
66-
cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color)
69+
cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, color)
6770
cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color, 2)
6871

69-
def send_trigger():
70-
inQ.send(dai.Buffer())
7172

7273
while True:
7374
frame = qRgb.get().getCvFrame()
@@ -76,11 +77,15 @@ def send_trigger():
7677
detections = qNn.get().detections
7778
drawDetections(frame, detections)
7879

80+
cv2.putText(frame, f"NN inferencing: {runNn}", (20,20), cv2.FONT_HERSHEY_TRIPLEX, 0.7, color)
7981
cv2.imshow('Color frame', frame)
8082

8183
key = cv2.waitKey(1)
8284
if key == ord('q'):
8385
break
8486
elif key == ord('t'):
85-
print('send trigger to IR filter')
86-
send_trigger()
87+
runNn = not runNn
88+
print(f"{'Enabling' if runNn else 'Disabling'} NN inferencing")
89+
buf = dai.Buffer()
90+
buf.setData(runNn)
91+
inQ.send(buf)

0 commit comments

Comments
 (0)