调用pcl计算法向量,并将法向量可视化

在ubuntu 14.04上,利用pcl库处理双边滤波后的640*480深度图(DEPTH_METRIC_FILTERED.txt),计算得到法向量并进行可视化。输出包括二维法向量图像和三维点云数据。该过程借助qtCreator 4.8和opencv2.4.9完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编译环境: ubuntu 14.04, qtCreator 4.8, pcl 1.8, opencv2.4.9

input: 双边滤波处理后的深度图(图像大小640*480,深度值范围0~2.226)生成的txt文件("DEPTH_METRIC_FILTERED.txt")

txt文件链接:(明明上传到我的资源里了,可是就是不显示)

output: 法向量可视化二位图和三维点云数据


main.cpp

#include <pcl/PCLPointCloud2.h>
#include <pcl/io/pcd_io.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/visualization/pcl_visualizer.h>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>

using namespace std;
using namespace cv;

//using namespace pcl;
//using namespace pcl::io;
//using namespace pcl::console;

typedef pcl::PointXYZRGB PointT;

int main()
{
    ifstream fin_depth("DEPTH_METRIC_FILTERED.txt");//DEPTH_METRIC_FILTERED DEPTH_RAW
    ifstream fin_color("colorBuff.txt");
    assert(fin_depth.is_open());//if open file failure,then stop
    assert(fin_color.is_open());//if open file failure,then stop

    float depth[480][640];
    //Mat depth_map(480,640,CV_8UC1);
    float color[480][640*3];
    Mat color_map(480,640,CV_8UC3);


    for(int i=0 ; i<480 ; i++)
    {
        for(int j=0;j<640;j++)
        {
            fin_depth>>depth[i][j];

            fin_color>>color[i][j*3];
            fin_color>>color[i][j*3+1];
            fin_color>>color[i][j*3+2];
        }
    }
    fin_depth.close();
    fin_color.close();

       // 点云变量
        // 使用智能指针,创建一个空点云。这种指针用完会自动释放。
    pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
    int ifvalid[640*480]={0};
        // 遍历深度图
        for (int i = 0; i < 480; i++)
        {
            for (int j=0; j < 640; j++)
            {
                // 获取深度图中(m,n)处的值
//                float d = depth[.ptr<ushort>[i][j];
                // d 可能没有值,若如此,跳过此点
                if (fabs(depth[i][j])< 0.001)
                {
                    ifvalid[640*i+j]=0;
                    continue;
                }
               else
                {
                    ifvalid[640*i+j]=1;

                    // d 存在值,则向点云增加一个点
                    PointT p;

                    // 计算这个点的空间坐标
                    p.z = double(depth[i][j]) ;///1000.0;
                    p.y = (i-241.0)*p.z/558.0 ;
                    p.x = (j-315.0)*p.z/558.0 ;

                    // 从rgb图像中获取它
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值