深度图转点云图记录

深度图转点云图

包含了单应性矩阵的使用

单应性矩阵主要是负责像素坐标到世界坐标的转换

每个点云图都由三个维度组成xLineyLinezLine

那么Point[0]的坐标就是(xLine[0], yLine[1], zLine[2])

void LT360XWindow::onConverToPointMap()
{
    const QString xmlStr = "D:\\Document\\GtCode\\apps\\bin\\x64\\Release\\temp\\OIS-IMG\\OIS0%1.xml";
    const QString matStr = "D:\\Document\\GtCode\\apps\\bin\\x64\\Release\\temp\\OIS-IMG\\OIS0%1.mat";
    const QString pmpStr = "D:\\Document\\GtCode\\apps\\bin\\x64\\Release\\temp\\OIS-IMG\\OIS0%1.pmf";
    for (int i=1;i<=3;++i)
    {
        QString xmlFile = xmlStr.arg(i);
        cv::FileStorage cvFile;
        bool isOk = cvFile.open(xmlFile.toStdString(), cv::FileStorage::READ);
        if (!isOk)
        {
            OiWarning() << "Fail to open: " << xmlFile;
            continue;
        }
        cv::Mat curHomo;
        cvFile["Homo1"] >> curHomo;
        curHomo.at<double>(2, 2) = 1.0;
        cvFile.release();
        QString matFile = matStr.arg(i);
        Core::RangeMapPtr rmPtr = Core::RangeMap::create(matFile);
        int rowNum = rmPtr->rows();
        if (rowNum > 10)
        {
            rowNum = 10;
        }
        int colNum = rmPtr->cols();
        Core::PointMapPtr pmp = Core::PointMap::create(colNum, rowNum);
        pmp->resize(rowNum);
        for (int r = 0; r < rowNum; ++r)
        {
            float* rmLine = rmPtr->profile(r);
            float* xLine = pmp->xLine(r);
            float* yLine = pmp->yLine(r);
            float* zLine = pmp->zLine(r);
            for (int c = 0; c < colNum; ++c)
            {
                double rx = c;
                double ry = rmLine[c];
                float denum = curHomo.at<double>(2, 0) * rx + curHomo.at<double>(2, 1) * ry + curHomo.at<double>(2, 2);
                float x = (curHomo.at<double>(0, 0) * rx + curHomo.at<double>(0, 1) * ry + curHomo.at<double>(0, 2)) / denum;
                float y = (curHomo.at<double>(1, 0) * rx + curHomo.at<double>(1, 1) * ry + curHomo.at<double>(1, 2)) / denum;

                xLine[c] = x;
                yLine[c] = 0.1 * r;
                zLine[c] = y;
            }
        }
        QString pmpFile = pmpStr.arg(i);
        pmp->save(pmpFile);
    }
}
### 点云图处理方法、算法及其实现方式 #### 文本形式点云数据的读取与可视化展示 对于文本形式的点云数据,可以采用特定的方法将其读入并进行初步的数据清洗和预处理工作。之后通过合适的API接口或者函数调用来完成这些点云数据的可视化表示[^1]。 ```python import open3d as o3d import numpy as np # 假设从文件加载点坐标到numpy数组points points = np.loadtxt('point_cloud.txt', delimiter=',') pcd = o3d.geometry.PointCloud() pcd.points = o3d.utility.Vector3dVector(points) o3d.visualization.draw_geometries([pcd]) ``` #### 使用Open3D进行点云图展示 为了更好地理解和分析点云图像,在实际应用中通常会先计算深度图,再由该深度图构建三维点云模型最后借助于像Open3D这样的专用库来进行高质量渲染效果下的交互式查看[^2]。 ```python from PIL import Image import cv2 def depth_to_pointcloud(depth_image_path, fx, fy, cx, cy): """Convert a depth image to point cloud.""" # Load the depth image using OpenCV or any other library. depth_img = cv2.imread(depth_image_path, cv2.IMREAD_UNCHANGED).astype(np.float32)/1000 rows, cols = depth_img.shape[:2] c, r = np.meshgrid(np.arange(cols), np.arange(rows)) points_z = depth_img / 1000.0 points_x = (c - cx) * points_z / fx points_y = (r - cy) * points_z / fy mask = points_z > 0 xyz_points = np.stack((points_x[mask], points_y[mask], points_z[mask]), axis=-1) pcd = o3d.geometry.PointCloud() pcd.points = o3d.utility.Vector3dVector(xyz_points.reshape(-1, 3)) return pcd depth_pcd = depth_to_pointcloud("path/to/your_depth_image.png", 585, 585, 320, 240) o3d.visualization.draw_geometries([depth_pcd]) ``` #### Python中的TVTK用于标量和矢量数据的空间轮廓线可视化 除了上述提到的技术之外,还有其他一些强大的工具可用于更复杂的场景下对多维科学数据集执行高级别的图形化表达;比如Python里的TVTK模块就提供了很好的支持来创建结构化的网格边界框以及绘制各种类型的场(如温度分布等)。这同样适用于某些特殊情况下需要特别关注内部几何特征变化趋势的研究领域[^4]。 ```python from tvtk.api import tvtk from mayavi.sources.vtk_data_source import VTKDataSource from mayavi.modules.outline import Outline from mayavi.core.pipeline_base import PipelineBase from mayavi import mlab outline_filter = tvtk.StructuredGridOutlineFilter(input_connection=polydata.GetProducerPort()) mlab.pipeline.surface(outline_filter.output_port) mlab.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值