gherodes
Have ran this script below (not sure if I even changed anything besides the blocking) and I have waited god know how long and I can not get it to crash. Even after multiple hours. Script is flashed to the device, and your retrieval script is always running.
import depthai as dai
import time
from datetime import timedelta
def create_pipeline(camera_ip, camera_port, script_path):
pipeline = dai.Pipeline()
RGB_SOCKET = dai.CameraBoardSocket.CAM_C
TOF_SOCKET = dai.CameraBoardSocket.CAM_A
# Create nodes
camRgb = pipeline.create(dai.node.ColorCamera)
tof = pipeline.create(dai.node.ToF)
camTof = pipeline.create(dai.node.Camera)
align = pipeline.create(dai.node.ImageAlign)
pointcloud = pipeline.create(dai.node.PointCloud)
script = pipeline.create(dai.node.Script)
# Configure nodes
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P)
camRgb.setBoardSocket(RGB_SOCKET)
camRgb.setIspScale(1,2)
FPS = 10
camRgb.setFps(FPS)
# ToF settings
camTof.setFps(FPS)
camTof.setImageOrientation(dai.CameraImageOrientation.ROTATE_180_DEG)
camTof.setBoardSocket(TOF_SOCKET)
# Higher number => faster processing. 1 shave core can do 30FPS.
tof.setNumShaves(1)
# Median filter, kernel size 3x3
tof.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_3x3)
tofConfig = tof.initialConfig.get()
# Temporal filter averages shuffle/non-shuffle frequencies
tofConfig.enablePhaseShuffleTemporalFilter = True
# Phase unwrapping, for longer range.
tofConfig.phaseUnwrappingLevel = 2
tofConfig.phaseUnwrapErrorThreshold = 500
tof.initialConfig.set(tofConfig)
pointcloud.initialConfig.setSparse(False)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript(f"""
from http.server import BaseHTTPRequestHandler
import socketserver
import socket
import fcntl
import struct
ctrl = CameraControl() # Assuming CameraControl can handle point clouds
ctrl.setCaptureStill(True)
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(), -1071617759, # SIOCGIFADDR
struct.pack('256s', ifname[:15].encode())
)[20:24])
class HTTPHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write(b'<h1>[DepthAI] Hello, world!</h1><p>Click <a href="img">here</a> for an image</p><p>Click <a href="pointcloud">here</a> for a pointcloud</p>')
elif self.path == '/img':
# Capture the image from the camera
node.io['out'].send(ctrl)
image = node.io['rgb'].get()
self.send_response(200)
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', str(len(image.getData())))
self.end_headers()
print(f"Image size: {{len(image.getData())}}")
self.wfile.write(image.getData())
elif self.path == '/pointcloud':
# Capture the point cloud data
node.io['out'].send(ctrl)
pointcloud = node.io['pcl'].get()
self.send_response(200)
self.send_header('Content-Type', 'application/octet-stream') # Binary file
self.send_header('Content-Length', str(len(pointcloud.getData())))
self.end_headers()
self.wfile.write(pointcloud.getData())
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Url not found...')
with socketserver.TCPServer(("0.0.0.0", {camera_port}), HTTPHandler) as httpd:
print("Server started")
httpd.serve_forever()
""")
# Linking
print("Linking nodes...")
camRgb.isp.link(script.inputs["rgb"])
script.inputs["rgb"].setBlocking(False)
script.inputs["rgb"].setQueueSize(1)
camRgb.isp.link(align.inputAlignTo)
camTof.raw.link(tof.input)
tof.depth.link(align.input)
align.outputAligned.link(pointcloud.inputDepth)
pointcloud.outputPointCloud.link(script.inputs["pcl"])
script.outputs['out'].link(camRgb.inputControl)
print("Nodes linked")
return pipeline
if __name__ == "__main__":
camera_ip = '10.12.118.118'
camera_port = '8080'
pipeline = create_pipeline(camera_ip, camera_port, None)
ret, device_info = dai.Device.getFirstAvailableDevice()
if not ret:
print("No available devices")
exit(1)
(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
(r, errmsg) = bootloader.flash(progress, pipeline, memory=dai.DeviceBootloader.Memory.FLASH, compress=True)
if r: print("Flash OK")
else: print("Flash ERROR:", errmsg)
# device = dai.Device(pipeline)
# while True:
# time.sleep(1)
# pass
# # retrieve_image_and_pointcloud(server_url)
Thanks,
Jaka