I’d like to visualise a point cloud of a video in a specific time (‘–desired_time’)
Currently, I have the following code but it shows point cloud from that time while I want the point cloud to be frozen at the right timestamp:
import sys
import depth_sensing_viewer.viewer as gl
import pyzed.sl as sl
import argparse
import cv2
#python "Visualise_points_cloud\mono_camera\depth_sensing_given_tmstmp.py" --input_svo_file "VideoToBodies\Files\3cameras\14-08-2023_15h55\cam_14-08-2023_15h55_0.svo" --desired_time 10
def parse_args(init, desired_time):
if len(opt.input_svo_file) > 0 and opt.input_svo_file.endswith(".svo"):
init.set_from_svo_file(opt.input_svo_file)
print("[Sample] Using SVO File input: {0}".format(opt.input_svo_file))
elif len(opt.ip_address)>0 :
ip_str = opt.ip_address
if ip_str.replace(':','').replace('.','').isdigit() and len(ip_str.split('.'))==4 and len(ip_str.split(':'))==2:
init.set_from_stream(ip_str.split(':')[0],int(ip_str.split(':')[1]))
print("[Sample] Using Stream input, IP : ",ip_str)
elif ip_str.replace(':','').replace('.','').isdigit() and len(ip_str.split('.'))==4:
init.set_from_stream(ip_str)
print("[Sample] Using Stream input, IP : ",ip_str)
else :
print("Unvalid IP format. Using live stream")
if ("HD2K" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.HD2K
print("[Sample] Using Camera in resolution HD2K")
elif ("HD1200" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.HD1200
print("[Sample] Using Camera in resolution HD1200")
elif ("HD1080" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.HD1080
print("[Sample] Using Camera in resolution HD1080")
elif ("HD720" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.HD720
print("[Sample] Using Camera in resolution HD720")
elif ("SVGA" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.SVGA
print("[Sample] Using Camera in resolution SVGA")
elif ("VGA" in opt.resolution):
init.camera_resolution = sl.RESOLUTION.VGA
print("[Sample] Using Camera in resolution VGA")
elif len(opt.resolution)>0:
print("[Sample] No valid resolution entered. Using default")
else :
print("[Sample] Using default resolution")
def main(desired_time):
print("Running Depth Sensing sample ... Press 'Esc' to quit\nPress 's' to save the point cloud")
init = sl.InitParameters(depth_mode=sl.DEPTH_MODE.ULTRA,
coordinate_units=sl.UNIT.METER,
coordinate_system=sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP)
parse_args(init, desired_time)
zed = sl.Camera()
status = zed.open(init)
if status != sl.ERROR_CODE.SUCCESS:
print(repr(status))
exit()
svo_fps = zed.get_camera_information().camera_configuration.fps
desired_frame = int(svo_fps * desired_time)
# Set the SVO position to the desired frame
zed.set_svo_position(desired_frame)
res = sl.Resolution()
res.width = 720
res.height = 404
camera_model = zed.get_camera_information().camera_model
point_cloud = sl.Mat(res.width, res.height, sl.MAT_TYPE.F32_C4, sl.MEM.CPU)
viewer = gl.GLViewer()
viewer.init(1, sys.argv, camera_model, res)
#point_cloud = sl.Mat(res.width, res.height, sl.MAT_TYPE.F32_C4, sl.MEM.CPU)
while viewer.is_available():
if zed.grab() == sl.ERROR_CODE.SUCCESS:
zed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA,sl.MEM.CPU, res)
viewer.updateData(point_cloud)
viewer.exit()
zed.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input_svo_file', type=str, help='Path to an .svo file', default='')
parser.add_argument('--ip_address', type=str, help='IP Address for streaming setup', default='')
parser.add_argument('--resolution', type=str, help='Resolution setting', default='')
parser.add_argument('--desired_time', type=float, help='Desired time in seconds to display point cloud', default=10.0)
opt = parser.parse_args()
if len(opt.input_svo_file) > 0 and len(opt.ip_address) > 0:
print("Specify only input_svo_file or ip_address, not both. Exit program")
exit()
main(opt.desired_time)