I have the OAK-D Pro PoE and have this simple test pipeline that uses the qr_code_detection_384x384 NN model, and uses a script node to send an output message via MQTT.
import depthai as dai
import blobconverter
pipeline = dai.Pipeline()
# Define camera node
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setPreviewSize(384, 384)
camRgb.setInterleaved(False)
camRgb.initialControl.setManualFocus(145)
camRgb.setFps(10)
# Define a neural network that will detect qr codes based on the source frames
nn = pipeline.create(dai.node.MobileNetDetectionNetwork)
nn.setBlobPath(blobconverter.from_zoo(name="qr_code_detection_384x384", zoo_type="depthai", shaves=6))
# Create a script node that publishes to an MQTT server
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
# Change the IP to your MQTT broker!
MQTT_BROKER = "192.168.0.38"
MQTT_BROKER_PORT = 1883
MQTT_TOPIC = "oak_d/detection"
script_text = f"""
import time
mqttc = Client()
node.warn('Connecting to MQTT broker...')
mqttc.connect("{MQTT_BROKER}", {MQTT_BROKER_PORT}, 120)
node.warn('Successfully connected to MQTT broker!')
mqttc.loop_start()
cnt = 0
while True:
cnt+=1
if cnt > 50000:
node.warn(str(cnt))
cnt = 0
detections = node.io['detections'].get().detections
if len(detections) > 0:
msg = 'qr code detected'
else:
msg = 'no qr code detected'
node.warn('sending: ' + msg)
(ok, id) = mqttc.publish("{MQTT_TOPIC}", msg, qos=2)
if (ok == 0):
node.warn('published successfully, id: '+ str(id))
"""
with open("utils/paho-mqtt.py", "r") as f:
paho_script = f.read()
script.setScript(f"{paho_script}\n{script_text}")
# Link camera to NN input
camRgb.preview.link(nn.input)
# Link NN output to script input
nn.out.link(script.inputs['detections'])
This pipeline works fine in host mode with the following piece of code. Using MQTT Explorer, I can see messages being published continuously.
## Host method
import time
with dai.Device(pipeline) as device:
print('Connected to OAK')
while not device.isClosed():
time.sleep(1)
However, the same pipeline doesn't work in standalone mode. I've used the following piece of code to flash the above pipeline to device.
## Standalone method
(f, deviceInfo) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(deviceInfo)
print_progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
# Flash pipeline to device directly
success, msg = bootloader.flash(print_progress, pipeline, applicationName="QRCode")
msg = f"Flashing was successful." if success else f"Flashing failed. Error: {msg}"
print(msg)
The flashing finishes successfully. After about a minute, I hear a click from the camera, indicating that it has rebooted. However, there are no messages being published. The camera seems to be rebooting repeatedly as I hear a click from the camera after every minute has passed. So, it looks like the application is crashing.
This might have something to do with the qr_code_detection_384x384 NN model as the pipeline runs fine (in both host and standalone model). Things are fine when I replace that model with a different model ("mobilenet-ssd", and "mask_detection_300x300", for example, which I have tried).
I know how to enable logging when using host mode, but is there any way of getting/accessing logging information in standalone mode? Is there something that needs to be done differently to get models like "qr_code_detection_384x384" working in standalone mode?