I've been attempting to setup my OAKD-LR as a standalone device and have been successfully able to pull the camera feeds with the standalone example found here luxonis/depthai-experimentstree/master/gen2-cumulative-object-counting/standalone.
However when attempting to modify this script to pull the depth maps off the camera I am getting connection refused. I am able to ping my camera so I am assuming it is failing to run the script and bind to the socket. The code I am attempting to use is shown below - I am on depthAI version 2.24.0.0.
#!/usr/bin/env python3
import depthai as dai
pipeline = dai.Pipeline()
# Stereo settings
extended_disparity = True
subpixel = True
lr_check = True
left = pipeline.create(dai.node.ColorCamera)
center = pipeline.create(dai.node.ColorCamera)
right = pipeline.create(dai.node.ColorCamera)
LC_depth = pipeline.create(dai.node.StereoDepth)
LR_depth = pipeline.create(dai.node.StereoDepth)
CR_depth = pipeline.create(dai.node.StereoDepth)
left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
left.setCamera("left")
left.setIspScale(2, 3)
center.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
center.setCamera("center")
center.setIspScale(2, 3)
right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
right.setCamera("right")
right.setIspScale(2, 3)
for depth_node in (LC_depth, LR_depth, CR_depth):
depth_node.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
depth_node.initialConfig.setMedianFilter(dai.MedianFilter.MEDIAN_OFF)
depth_node.setLeftRightCheck(lr_check)
depth_node.setExtendedDisparity(extended_disparity)
depth_node.setSubpixel(subpixel)
# 5) Link ISP outputs → StereoDepth inputs
# LC: left ISP → LC_depth.left, center ISP → LC_depth.right
left.isp.link(LC_depth.left)
center.isp.link(LC_depth.right)
left.isp.link(LR_depth.left)
right.isp.link(LR_depth.right)
center.isp.link(CR_depth.left)
right.isp.link(CR_depth.right)
disp_enc_LC = pipeline.create(dai.node.VideoEncoder)
disp_enc_LR = pipeline.create(dai.node.VideoEncoder)
disp_enc_CR = pipeline.create(dai.node.VideoEncoder)
for enc in (disp_enc_LC, disp_enc_LR, disp_enc_CR):
enc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.MJPEG)
t
LC_depth.disparity.link(disp_enc_LC.input)
LR_depth.disparity.link(disp_enc_LR.input)
CR_depth.disparity.link(disp_enc_CR.input)
script_node = pipeline.create(dai.node.Script)
script_node.setScript(r"""
import socket
import struct
# Immediately notify over the ‘log’ output
node.warn("Standalone Script started!")
# Open a TCP server on port 8000 (bind to all interfaces)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("0.0.0.0", 8000))
server_socket.listen(1)
node.warn("Listening on 0.0.0.0:8000…")
conn, addr = server_socket.accept()
node.warn(f"Host connected from {addr}")
while True:
# 1) Read next LC MJPEG packet
pkt_lc = node.io["encoded_LC_disp"].get()
data_lc = pkt_lc.getData() # raw JPEG bytes
# Prefix with: [1-byte stream ID][4-byte big-endian length][JPEG data]
conn.sendall(b"\\x00" + struct.pack(">I", len(data_lc)) + data_lc)
# 2) Read next LR MJPEG packet
pkt_lr = node.io["encoded_LR_disp"].get()
data_lr = pkt_lr.getData()
conn.sendall(b"\\x01" + struct.pack(">I", len(data_lr)) + data_lr)
# 3) Read next CR MJPEG packet
pkt_cr = node.io["encoded_CR_disp"].get()
data_cr = pkt_cr.getData()
conn.sendall(b"\\x02" + struct.pack(">I", len(data_cr)) + data_cr)
""")
# 9) Link each encoder output → Script node’s input streams
disp_enc_LC.bitstream.link(script_node.inputs["encoded_LC_disp"])
disp_enc_LR.bitstream.link(script_node.inputs["encoded_LR_disp"])
disp_enc_CR.bitstream.link(script_node.inputs["encoded_CR_disp"])
xout_warning = pipeline.create(dai.node.XLinkOut)
xout_warning.setStreamName("script_warning")
# The Script node’s built-in ‘log’ output (where node.warn() goes) is “outputs['log']”
script_node.outputs["log"].link(xout_warning.input)
if name == "main":
(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
progress = lambda p: print(f"Flashing progress: {p\*100:.1f}%")
bootloader.flash(progress, pipeline)