Pointcloud value at a given index
Hi,
I am using RealSense-415 camera to get RGB color image of size(480X640) and pointcloud data of length (307200 i.e., 480X640). I achieve this using the Python code below.
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import PointCloud2
from sensor_msgs import point_cloud2
def callback_ptclud(ptcloud_data):
assert isinstance(ptcloud_data, PointCloud2)
pt_gen = point_cloud2.read_points(ptcloud_data)
for pt in pt_gen:
print(pt)
def listener():
rospy.Subscriber("/camera/depth_registered/points", PointCloud2, callback_ptclud)
rospy.spin()
if __name__ == '__main__':
rospy.init_node("realsense_subscriber", anonymous=True)
listener()
Now my questions are as follows,
As you can see that inside the
callback_ptclud()
function, I need to loop through all the data points ofpt_gen
to access point-cloud data. Suppose, I need to access only the data inpt_gen
at indexi=1000
. Is there a way to get to index value ati
directly instead of looping through all999
points?Suppose that pointcloud data is aligned with color image and I want to retrieve the pointcloud value corresponding to the color image pixel index
px=240, py=320
. Then what will be the corresponding index value ofpt_gen
?
Any help is appreciated.