Hi Jakaskerl,
For the tests I ran the 2 scripts above on the camera (along with the suggestions you provided in your first comment applied to both RGB and PCL inputs to the Script node). It runs on an OAK-D SR ToF camera with bootloader version 0.0.28 and depthai-python
version 2.28.0.
To retrieve images from the camera the script attached to this comment is used.
import requests
import cv2
import numpy as np
import open3d as o3d
import time
def yuv420_to_bgr(yuv_bytes, width, height):
# Size of Y, U, and V planes
y_size = width * height
uv_size = (width // 2) * (height // 2)
# Split the YUV data into Y, U, and V planes
y_plane = np.frombuffer(yuv_bytes[0:y_size], dtype=np.uint8).reshape(
(height, width)
)
u_plane = np.frombuffer(
yuv_bytes[y_size : y_size + uv_size], dtype=np.uint8
).reshape((height // 2, width // 2))
v_plane = np.frombuffer(yuv_bytes[y_size + uv_size :], dtype=np.uint8).reshape(
(height // 2, width // 2)
)
# Upsample the U and V planes to the size of Y plane
u_plane_up = cv2.resize(u_plane, (width, height), interpolation=cv2.INTER_LINEAR)
v_plane_up = cv2.resize(v_plane, (width, height), interpolation=cv2.INTER_LINEAR)
# Stack the Y, U, and V planes into a YUV image
yuv_img = np.stack((y_plane, u_plane_up, v_plane_up), axis=-1)
# Convert YUV to RGB using OpenCV
bgr_img = cv2.cvtColor(yuv_img, cv2.COLOR_YUV2BGR)
return bgr_img
def retrieve_image_and_pointcloud(server_url):
# Define the endpoints for image and pointcloud
image_url = f"{server_url}/img"
pointcloud_url = f"{server_url}/pointcloud"
ping_url = f"{server_url}/ping"
# Retrieve the image
# print(f"Requesting image from {image_url}")
t0 = time.time()
image_response = requests.get(image_url)
t1 = time.time()
print(f"Time to retrieve image: {t1 - t0:.4f} seconds")
t2 = time.time()
pointcloud_response = requests.get(pointcloud_url)
t3 = time.time()
print(f"Time to retrieve pointcloud: {t3 - t2:.4f} seconds")
t4 = time.time()
ping_response = requests.get(ping_url)
t5 = time.time()
print(f"Time to ping server: {t5 - t4:.4f} seconds")
print(f"Total retrieval time: {t5 - t0:.4f} seconds")
if image_response.status_code == 200:
height = 400
width = 640
yuv_bytes = image_response.content
# Convert YUV420 to RGB
bgr_image_array = yuv420_to_bgr(yuv_bytes, width, height)
cv2.imwrite("image.jpg", bgr_image_array)
else:
print(f"Failed to retrieve image. Status code: {image_response.status_code}")
if pointcloud_response.status_code == 200:
# Save the point cloud as a PLY file
pcl_buffer = np.frombuffer(pointcloud_response.content, np.float32)
pcl_np = np.reshape(pcl_buffer, (-1, 3))
print(f"Point cloud shape: {pcl_np.shape}")
colors_np = (
np.reshape(cv2.cvtColor(bgr_image_array, cv2.COLOR_BGR2RGB), (-1, 3))
/ 255.0
)
# Save the point cloud as a PLY file
pcl = o3d.geometry.PointCloud()
pcl.points = o3d.utility.Vector3dVector(pcl_np)
pcl.colors = o3d.utility.Vector3dVector(colors_np)
o3d.io.write_point_cloud("pointcloud.ply", pcl)
if __name__ == "__main__":
# Example usage
server_url = "http://192.168.100.100:8080" # Replace this with the actual server address
while True:
t0 = time.time()
retrieve_image_and_pointcloud(server_url)
time.sleep(1)
t1 = time.time()
print("-----" * 10)
I hope this helps to reproduce the error, in the meanwhile I have observed that with FPS set to 1 the camera restarts after approximately 3 hours, while with the FPS at 3 the camera restarts after 23 minutes.
Kind regards,
Georg