[英]How do I get z-axis coordinate from ply file for a given point ( x, y ) in python?
I hope this finds you in good health.我希望这能让你身体健康。 I am really really new to working with 3d objects.
我对使用 3d 对象真的很陌生。 I have been working with an Object Detection Algorithm (YOLO) recently.
我最近一直在研究对象检测算法(YOLO)。 As Yolo returns the bounding box coordinates of an object, we can easily get the (x,y) coordinates of the bounding boxes.
由于 Yolo 返回对象的边界框坐标,我们可以轻松获得边界框的 (x,y) 坐标。 However recently, I have added a TOF camera to the project that can sense dept(z-axis coordinate) for each pixel.
但是最近,我在项目中添加了一个 TOF 相机,可以感应每个像素的深度(z 轴坐标)。 All of this data are stored in a corresponding ".ply".
所有这些数据都存储在相应的“.ply”中。 I want to get the z-axis value for each bounding-box coordinates that yolo outputs.
我想获取 yolo 输出的每个边界框坐标的 z 轴值。
Right now my .ply file shows this output:现在我的 .ply 文件显示了这个输出:
array([[-818.5 , -830.75, 1949.25],
[-748. , -814.5 , 1918.5 ],
[-704. , -806.75, 1905.25],
...,
[ 903.75, 790. , 1844.25],
[ 906.75, 789.5 , 1843. ],
[ 915. , 793.75, 1852.25]], dtype=float32)
I am using python's plyfile library to read the data from my .ply file我正在使用 python 的 plyfile 库从我的 .ply 文件中读取数据
This is how far I have gone:这是我走了多远:
def read_ply(filename):
""" read XYZ point cloud from filename PLY file """
plydata = PlyData.read(filename)
x = np.asarray(plydata.elements[0].data['x'])
y = np.asarray(plydata.elements[0].data['y'])
z = np.asarray(plydata.elements[0].data['z'])
return np.stack([x,y,z], axis=1)
coors = read_ply("test.ply")
coors
This script reads the given .ply file and outputs the following vertexes (x,y,z) value from the ply file:此脚本读取给定的 .ply 文件并从 ply 文件输出以下顶点 (x,y,z) 值:
array([[-818.5 , -830.75, 1949.25],
[-748. , -814.5 , 1918.5 ],
[-704. , -806.75, 1905.25],
...,
[ 903.75, 790. , 1844.25],
[ 906.75, 789.5 , 1843. ],
[ 915. , 793.75, 1852.25]], dtype=float32)
Now I want to find the z-axis for the corresponding pixels that are present in the bounding box that YOLO outputs.现在我想找到 YOLO 输出的边界框中存在的相应像素的 z 轴。
Finally figured out what i was doing wrong.终于弄清楚我做错了什么。 This is the correct working code.
这是正确的工作代码。 Cheers!
干杯!
#Enter your x & y coors to get corresponding z-axis value
x = 2300
y = 1822
xy = np.array([x, y])
z = coors[np.all(np.isclose(coors[:, :2], xy), axis=1), 2][0]
print("x= {} y= {} z= {}".format(x, y, z))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.