genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
513 stars 88 forks source link

Acquiring disparity images from rc visard #397

Open svenkatachalam opened 1 year ago

svenkatachalam commented 1 year ago

I want to acquire Disparity images from rc visard sensor. Acquiring 'Mono8' images is working fine, but acquiring images of pixel format 'Coord3D_C16' isnt working. Getting the 1d array with all zero values.

Setup: The sensor is acquiring an image over a trigger (this is working fine) CTI files coresponding to roboception sensor is used. The ComponentSelector node is set to 'Disparity'. Additonally checked for UDP port and set to 50010.

This is the whole code: `h = Harvester() h.add_file("D:\Venkat\Pre-assembly-cell-process-plan_current\PythonInverseKinematics" \ "\rc_visard_genicam\cti_files_from_roboception\bgapi2_gige.cti") h.add_file("D:\Venkat\Pre-assembly-cell-process-plan_current\PythonInverseKinematics" \ "\rc_visard_genicam\cti_files_from_roboception\rc_sgm_producer.cti") h.update() ia = h.create() ia.remote_device.node_map.ComponentSelector.value = 'Intensity' ia.remote_device.node_map.ComponentEnable.value = False # Disabling Intensity component as it is enabled by default. ia.remote_device.node_map.ComponentSelector.value = 'Disparity' ia.remote_device.node_map.ComponentEnable.value = True ia.remote_device.node_map.DepthQuality.value = 'High' ia.start() buffer = ia.fetch() buffer.queue() print ("buffer : ", buffer.size) print ("Components : ", buffer.payload.components) _1d = buffer.payload.components[0].data payload = buffer.payload component = payload.components[0] print ("Comps : ", payload.components) width = component.width height = component.height print ("height : ", height) print ("width : ", width) data_format = component.data_format print ("data_format : ", data_format)

Following parameters are required to convert disparity to pointcloud

scale_factor = ia.remote_device.node_map.Scan3dCoordinateScale.value focal_length = ia.remote_device.node_map.Scan3dFocalLength.value base_line = ia.remote_device.node_map.Scan3dBaseline.value principal_u = ia.remote_device.node_map.Scan3dPrincipalPointU.value principal_v = ia.remote_device.node_map.Scan3dPrincipalPointV.value

The code is executing the following "if" block as expected for acquiring disparity images.

if data_format in component_16bit_formats: print ("Data format : ",data_format) content = component.data.reshape(height, width) #480 x 640 for Disparity

This content array is completely filled with '0'

else: if data_format in rgb_formats or \ data_format in rgba_formats or \ data_format in bgr_formats or \ data_format in bgra_formats: content = component.data.reshape( height, width, int(component.num_components_per_pixel) # Set of R, G, B, and Alpha ) print (content) if data_format in bgr_formats:

Swap every R and B:

        content = content[:, :, ::-1]
        print ("content : ",content)

disparity_in_pixels = content * scale_factor ia.stop() `