cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
// 创建点云对象
// 读取深度图像
cv::Mat depthImage = cv::imread(fullFilename, cv::IMREAD_UNCHANGED);
depthImage.convertTo(depthImage, CV_32FC1);
// 遍历深度图像,将符合条件的点添加到点云中
float minDepth = 0.1; // 最小深度阈值(单位:米)
float maxDepth = 3.0; // 最大深度阈值(单位:米)
for (int y = 0; y < depthImage.rows; ++y)
{
for (int x = 0; x < depthImage.cols; ++x)
{
// 获取深度值
float depth = depthImage.at<float>(y, x);
// 忽略深度值为0的点
if (depth == 0)
continue;
如果深度值不在指定的范围内,则忽略该点
//if (depth < minDepth || depth > maxDepth)
// continue;
// 计算三维坐标
double X = (x - cx) * depth / fx;
double Y = (y - cy) * depth / fy;
double Z = -depth;
// 创建点云点并设置坐标
pcl::PointXYZ point;
point.x = X;
point.y = Y;
point.z = Z;
// 将点添加到点云中
cloud->push_back(point);
}
PCL:深度图转点云
最新推荐文章于 2024-05-20 14:07:12 发布