- Okay, Thank you so much for the correction. I am saving the image, point cloud and depth map using .write() function only. I will read it with .read() from now on.
After running the code with suggested changes, I am getting the following output:
`Point_Cloud: (SUCCESS, array([ -40.71487808, 23.08045769, 2844.52709961, nan]))
x: 1104 y: 621
Distance to Camera at {1104;621}: 2844.9120951685723
n/a Ts 1711647054325184993 sl::Mat of size [2208,1242], with 1 channels of type float allocated on CPU (memory owned).
Saved Image, Point Cloud, and Depth Map as zz20240328_183054
zz20240328_183054.ply
Point Cloud at x and Y: (SUCCESS, 2.9388984276775804e-39)
Depth Map Value: (SUCCESS, 7.255130313343095e-39)`
I am not able to understand what does these values show? Why there is a change in the output before and after saving the files. Please explain?
Point Cloud at x and Y: (SUCCESS, 2.9388984276775804e-39)
Depth Map Value: (SUCCESS, 7.255130313343095e-39)
This is the code I wrote:
import cv2
import pyzed.sl as sl
import math
from datetime import datetime
if __name__ == "__main__":
# Create a Camera object
cam = sl.Camera()
# Create an InitParameters object and set configuration parameters
cam_init_params = sl.InitParameters()
cam_init_params.camera_resolution = sl.RESOLUTION.HD2K
cam_init_params.camera_fps = 15
# Depth Mode
# Depth Modes Available: NEURAL, ULTRA, QUALITY, PERFORMANCE(default)
cam_init_params.depth_mode = sl.DEPTH_MODE.NEURAL #Recommended by ZED: "ULTRA" mode
# cam_init_params.depth_stabilization = True (It is True by default and stables the image)
#############################################################
cam_init_params.coordinate_units = sl.UNIT.MILLIMETER # Use millimetre units (for depth measurements)
# cam_init_params.coordinate_units = sl.UNIT.CENTIMETER #default: Millimeters
cam_init_params.depth_minimum_distance= 35 # min possible 15 cm/ 150 mm/ 0.15 mtrs
cam_init_params.depth_maximum_distance = 35000 # Setting maximum depth perception distance to 35m
# Open the camera
cam.open(cam_init_params)
# Set the selected sensor for retrieving the image: from the left sensor
view = sl.VIEW.LEFT_GRAY
# set the measure types for getting the depth information. This is done based on the selected view
measure_depth = sl.MEASURE.DEPTH
point_cloud_mode = sl.MEASURE.XYZRGBA
# Create the parameters types required for retrieving the image from the camera
cam_runtime_parameters = sl.RuntimeParameters()
print("Stream View. Press 's' to save image and cloud points")
print("Stream View. Press 'q' to exit")
frame_time_ms = int(1000 / 30)
# camera_parameters=cam.get_camera_information().camera_configuration.calibration_parameters.left_cam
# for attr in dir(camera_parameters):
# if not attr.startswith("__"):
# print(f"{attr}: {getattr(camera_parameters, attr)}")
# print('fxcccc:', getattr(camera_parameters, 'fx'))
while True:
# StereoLabs data type for grabbing the images
zed_image = sl.Mat()
zed_point_cloud = sl.Mat()
zed_depth_map= sl.Mat()
if cam.grab(cam_runtime_parameters) == sl.ERROR_CODE.SUCCESS:
# Retrieve image from the selected view
cam.retrieve_image(zed_image, view)
# Retrieve point cloud. Point cloud is aligned on the selected view
cam.retrieve_measure(zed_point_cloud, point_cloud_mode)
cam.retrieve_measure(zed_depth_map, measure_depth) # Retrieve depth
image = zed_image.get_data()
points_cloud = zed_point_cloud.get_data()
x = int(zed_image.get_width() / 2)
y = int(zed_image.get_height() / 2)
cv2.imshow("Image", image)
# Single call to cv2.waitKey()
key = cv2.waitKey(5) # Adjust time as needed
# press s to save image and the cloud points
if key == ord('s'):
point_cloud_value = zed_point_cloud.get_value(x, y)
print('Point_Cloud:', point_cloud_value)
print('x:', x, 'y:', y)
distance = math.sqrt(point_cloud_value[1][0]*point_cloud_value[1][0] + point_cloud_value[1][1]*point_cloud_value[1][1] + point_cloud_value[1][2]*point_cloud_value[1][2])
print(f"Distance to Camera at {{{x};{y}}}: {distance}")
print(zed_depth_map)
#cv2.circle(image, (x,y), 5, (0,255,0), thickness=1)
# save the captured image
file_name = "zz"+datetime.now().strftime("%Y%m%d_%H%M%S")
cv2.imwrite(file_name+".png", image)
zed_point_cloud.write(file_name+".ply")
zed_depth_map.write(file_name+".pgm")
print(f"Saved Image, Point Cloud, and Depth Map as {file_name}")
point_cloud=sl.Mat()
print(file_name+".ply")
point_cloud.read(file_name+".ply")
#point_cloud_get_data= point_cloud.get_data()
print("Point Cloud at x and Y:", point_cloud.get_value(x, y))
dp=sl.Mat()
dp.read(file_name+".ply")
print("Depth Map Value:", dp.get_value(x,y))
if key == ord('q'):
break
# Close camera
status = cam.close()
- And on second issue, I found the location of the pyzed folder. What to do now to get the auto completion feature working in vscode? Sorry to ask this but I didnât understand it and I was looking to solve this auto completion thing from a very long time.