I am having a lot of trouble with the PoE Camera. Reconnecting to it after running my program.
I have a program based on the example provided with connects to the camera and saves the information is retrreives on a continuous basis. We have both USB and PoE OAK-D S-2 Cameras.
Everything works fine with the USB but the PoE version is giving problems.
I have a small network set up with the Camera, a PoE Switch and a connection to my PC. These are the only devices on this network and I disconnect the PC from other networks while trying to diagnose this. There is no DHCP and the PoE Camera reverts to it's default ip address of 169.254.1.222.
I power up all the equipment and start the program running, after a show while it connects to the camera and everything works fine. I can tell from the LEDs on the switch when this connection is working because they start flickering quickly. I then exit by clicking on the image and pressing 'q'. After a few seconds the python program stops and gives the message 'Exiting cleanly'. This should indicate that the context manager created by the line 'with dai.Device(pipeline, device_info, maxUsbSpeed=dai.UsbSpeed.HIGH) as device:' has exited cleanly.
However restarting this program (by running python main.py) fails with the following message
===========================================================
PS C:\code\cadds-visual-tyre-handler\source\recorder> python .\main.py
StereoDepth config options:
Left-Right check: True
Extended disparity: False
Subpixel: True
Median filtering: MedianFilter.KERNEL_7x7
C:\code\cadds-visual-tyre-handler\source\recorder\main.py:39: DeprecationWarning: LEFT is deprecated, use CAM_B or address camera by name instead.
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
C:\code\cadds-visual-tyre-handler\source\recorder\main.py:43: DeprecationWarning: RIGHT is deprecated, use CAM_C or address camera by name instead.
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
C:\code\cadds-visual-tyre-handler\source\recorder\main.py:89: DeprecationWarning: RGB is deprecated, use CAM_A or address camera by name instead.
stereo.setDepthAlign(dai.CameraBoardSocket.RGB)
[2023-07-13 14:35:35.502] [depthai] [warning] Monitor thread (device: 19443010B1937F1300 [169.254.1.222]) - ping was missed, closing the device connection
Traceback (most recent call last):
File "C:\code\cadds-visual-tyre-handler\source\recorder\main.py", line 154, in <module>
with dai.Device(pipeline, device_info, maxUsbSpeed=dai.UsbSpeed.HIGH) as device:
depthai.XLinkWriteError: Couldn't write data to stream: '__bootloader' (X_LINK_ERROR)
PS C:\code\cadds-visual-tyre-handler\source\recorder>
=======================================================================================
The error message may sometimes be different, but this one is very common.
depthai version ==2.22.0.0
Operating System Windows 10
Python Version 3.10.7
=====main.py source code===================================
#!/usr/bin/env python3
from queue import Full
import time
from sys import maxsize
import cv2
import depthai as dai
import os
import shutil
import zipfile
import pickle
from multiprocessing import Queue
from tyre_detector.saver import Saver, SaveRecord, SaverCommand
import sys
import time
COLOR = True
SAVE_FREQUENCY = 0
lrcheck = True # Better handling for occlusions
extended = False # Closer-in minimum depth, disparity range is doubled
subpixel = True # Better accuracy for longer distance, fractional disparity 32-levels
# Options: MEDIAN_OFF, KERNEL_3x3, KERNEL_5x5, KERNEL_7x7
median = dai.StereoDepthProperties.MedianFilter.KERNEL_7x7
print("StereoDepth config options:")
print(" Left-Right check: ", lrcheck)
print(" Extended disparity:", extended)
print(" Subpixel: ", subpixel)
print(" Median filtering: ", median)
pipeline = dai.Pipeline()
monoLeft = pipeline.create(dai.node.MonoCamera)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoRight = pipeline.create(dai.node.MonoCamera)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
stereo = pipeline.createStereoDepth()
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
stereo.initialConfig.setMedianFilter(median)
stereo.setLeftRightCheck(lrcheck)
stereo.setExtendedDisparity(extended)
stereo.setSubpixel(subpixel)
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
config = stereo.initialConfig.get()
config.postProcessing.speckleFilter.enable = False
config.postProcessing.speckleFilter.speckleRange = 50
config.postProcessing.temporalFilter.enable = True
config.postProcessing.spatialFilter.enable = True
config.postProcessing.spatialFilter.holeFillingRadius = 2
config.postProcessing.spatialFilter.numIterations = 1
config.postProcessing.thresholdFilter.minRange = 400
config.postProcessing.thresholdFilter.maxRange = 200000
config.postProcessing.decimationFilter.decimationFactor = 1
stereo.initialConfig.set(config)
xout_depth = pipeline.createXLinkOut()
xout_depth.setStreamName("depth")
stereo.depth.link(xout_depth.input)
xout_colorize = pipeline.createXLinkOut()
xout_colorize.setStreamName("colorize")
xout_rect_left = pipeline.createXLinkOut()
xout_rect_left.setStreamName("rectified_left")
xout_rect_right = pipeline.createXLinkOut()
xout_rect_right.setStreamName("rectified_right")
if COLOR:
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setIspScale(1, 3)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
camRgb.initialControl.setManualFocus(130)
stereo.setDepthAlign(dai.CameraBoardSocket.RGB)
camRgb.isp.link(xout_colorize.input)
else:
stereo.rectifiedRight.link(xout_colorize.input)
stereo.rectifiedLeft.link(xout_rect_left.input)
stereo.rectifiedRight.link(xout_rect_right.input)
class HostSync:
def __init__(self):
self.arrays = {}
def add_msg(self, name, msg):
if not name in self.arrays:
self.arrays[name] = []
# Add msg to array
self.arrays[name].append({"msg": msg, "seq": msg.getSequenceNum()})
synced = {}
for name, arr in self.arrays.items():
for i, obj in enumerate(arr):
if msg.getSequenceNum() == obj["seq"]:
synced[name] = obj["msg"]
break
# If there are 4 (all) synced msgs, remove all old msgs
# and return synced msgs
if len(synced) == 4: # color, depth, rectified_left, rectified_right
# Remove old msgs
for name, arr in self.arrays.items():
for i, obj in enumerate(arr):
if obj["seq"] < msg.getSequenceNum():
arr.remove(obj)
else:
break
return synced
return False
if name == 'main':
device_info = dai.DeviceInfo('169.254.1.222')
with dai.Device(pipeline, device_info, maxUsbSpeed=dai.UsbSpeed.HIGH) as device:
device.setIrLaserDotProjectorBrightness(1200)
qs = []
qs.append(device.getOutputQueue("depth", maxSize=1, blocking=False))
qs.append(device.getOutputQueue("colorize", maxSize=1, blocking=False))
qs.append(device.getOutputQueue("rectified_left", maxSize=1, blocking=False))
qs.append(device.getOutputQueue("rectified_right", maxSize=1, blocking=False))
serial_no = device.getMxId()
sync = HostSync()
depth_vis, color = None, None
image_queue = Queue()
saver = Saver(image_queue, os.path.join(os.path.dirname(__file__), 'data'))
saver.start()
previous_save_time = 0.0
any_output = False
while True:
for q in qs:
new_msg = q.tryGet()
if new_msg is not None:
msgs = sync.add_msg(q.getName(), new_msg)
if msgs:
depth = msgs["depth"].getFrame()
color = msgs["colorize"].getCvFrame()
cv2.imshow("color", color)
any_output = True
now = time.time() \* 1000.0
if any_output and now > previous_save_time + SAVE_FREQUENCY:
previous_save_time = now
try:
image_queue.put(
SaverCommand(
save_record=SaveRecord(color, depth, now, serial_no, None, None, None, None),
exit_now=False,
max_telemetry_size=None),
block=False
)
except Full:
print("Queue was reported full")
key = cv2.waitKey(1)
if key == ord("q"):
print("Attempting to terminate saver")
image_queue.put(
SaverCommand(
save_record=None,
exit_now=True,
max_telemetry_size=None)
)
print("Waiting to join saver")
saver.join()
print("Saver joined")
break
print("Waiting to shutdown")
time.sleep(5)
print("Exiting cleanly")
====================================================================================================================
Any help would be much appreciated