简体   繁体   English

如何从 ply 文件中获取 python 中给定点 ( x, y ) 的 z 轴坐标?

[英]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.

相关问题 如何在python中给定点(x,y)和线与y轴的夹角的情况下找到线的斜率(m)? - How do I find the slope (m) for a line given a point (x,y) on the line and the line's angle from the y axis in python? Python/matplotlib mplot3d-如何设置 z 轴的最大值? - Python/matplotlib mplot3d- how do I set a maximum value for the z-axis? Python:将点数据导出到csv文件中,每列对应于x,y,z坐标 - Python: export point data to csv file with each column corresponding with the x, y, z coordinate 如何使用x和y坐标进行点的透视变换 - How do I make perspective transform of point with x and y coordinate Python-如何在表面离散3D点(x,y,z)之后从给定的x,y获取z值 - Python - How to get z value from given x, y after surface discrete 3D points (x,y,z) 在预处理 function 后,如何保持图像和坐标(z 轴)之间的关联? - How can I keep the association between image and coordinate (z-axis) after a preprocess function? 如何使用 geopandas 在 geojson map 上找到相应 XY 坐标的任意 Z 坐标? - How do I find an arbitrary Z coordinate for a corresponding X Y coordinate on a geojson map with geopandas? Python:使用到点 A 的距离(x0,y0)和角度找到给定点 B 的 ax,y 坐标 - Python: find a x,y coordinate for a given point B using the distance from the point A (x0, y0) and the angle 如何在Python中计算x / y坐标的长度? - How do I calculate the length of an x/y coordinate in Python? 简单的热图,其中 2 个 1D 列作为 x 和 y 轴,1 个 1D 列作为 z 轴 - Simple heatmap with 2 1D columns as x and y-axis, and 1 1D column as z-axis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM