当前位置:网站首页>Color map and depth map to point cloud
Color map and depth map to point cloud
2022-08-10 12:05:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
环境:windows10、VS2013、opencv 2.49、openNi、PCL1.8
opencv 环境搭建参考
VS2013+opencv2.4.9(10)配置[zz] – yifeier12 – 博客园
OpenCV3.1.0+VS2013开发环境配置_Such a coincidence blog-CSDN博客
PCL1.8+openNi搭建参考
Windows10下VS2013+PCL1.8环境配置_Summit_Yue的博客-CSDN博客
windows系统下配置PCL1.8.0和VS2013_大作家佚名的博客-CSDN博客
将上面的opencv和pclThe configuration is saved to the property sheet,for a quick reference next time.
新建项目,Select Solution Configuration SelectionDebug x64,property managerDebug|x64Add the above two property sheets to the
RGBDtoPC.cpp
#include "stdafx.h"
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <opencv2/opencv.hpp>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <pcl/visualization/cloud_viewer.h>
using namespace std;
// 定义点云类型
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloud;
// 相机内参
const double camera_factor = 1000;
const double camera_cx = 325.5;
const double camera_cy = 253.5;
const double camera_fx = 518.0;
const double camera_fy = 519.0;
// 主函数
int main(int argc, char** argv)
{
// 读取./data/rgb.png和./data/depth.png,并转化为点云
// 图像矩阵
cv::Mat rgb, depth;
// 使用cv::imread()来读取图像
// API: http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#cv2.imread
rgb = cv::imread("color.png");
cout << "read rgb"<<endl;
// rgb 图像是8UC3的彩色图像
// depth 是16UC1的单通道图像,注意flags设置-1,表示读取原始数据不做任何修改
depth = cv::imread("depth.png");
cout << "read depth" << endl;
// 点云变量
// 使用智能指针,创建一个空点云.这种指针用完会自动释放.
PointCloud::Ptr cloud(new PointCloud);
// 遍历深度图
for (int m = 0; m < depth.rows; m++)
for (int n = 0; n < depth.cols; n++)
{
// 获取深度图中(m,n)处的值
ushort d = depth.ptr<ushort>(m)[n];
// d 可能没有值,若如此,跳过此点
if (d == 0)
continue;
// d 存在值,则向点云增加一个点
PointT p;
// 计算这个点的空间坐标
p.z = double(d) / camera_factor;
p.x = (n - camera_cx) * p.z / camera_fx;
p.y = (m - camera_cy) * p.z / camera_fy;
// 从rgb图像中获取它的颜色
// rgb是三通道的BGR格式图,所以按下面的顺序获取颜色
p.b = rgb.ptr<uchar>(m)[n * 3];
p.g = rgb.ptr<uchar>(m)[n * 3 + 1];
p.r = rgb.ptr<uchar>(m)[n * 3 + 2];
// 把p加入到点云中
cloud->points.push_back(p);
//cout << cloud->points.size() << endl;
}
// 设置并保存点云
cloud->height = 1;
cloud->width = cloud->points.size();
cout << "point cloud size = " << cloud->points.size() << endl;
cloud->is_dense = false;
try{
//Save the point cloud map
pcl::io::savePCDFile("E:\\Visual Studio2013\\project\\RGBDtoPC\\data\\pcd.pcd", *cloud);
}
catch (pcl::IOException &e){
cout << e.what()<< endl;
}
//Display point cloud map
pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");//直接创造一个显示窗口
viewer.showCloud(cloud);//再这个窗口显示点云
while (!viewer.wasStopped())
{
}
//pcl::io::savePCDFileASCII("E:\\Visual Studio2013\\projectpointcloud.pcd", *cloud);
// 清除数据并退出
cloud->points.clear();
cout << "Point cloud saved." << endl;
return 0;
}
May return directly after running,提示pcl::io Exception
Step through discoverycv::imread()The picture was not read.原因如下
opencv有cvLoadImage()和cv::imread()读图片的方法
And the link library version of the latter is incorrect:(debugThe corresponding library is belowxxxd.lib,release的为xxx.lib) i.e. the additional dependencies in the linker are also added with the bandd和不带d's dependencies will go wrong,如果用DebugDebug only adds the back bandd的即可,将不带d的删除.
I added these
opencv_calib3d249d.lib opencv_contrib249d.lib opencv_core249d.lib opencv_features2d249d.lib opencv_flann249d.lib opencv_gpu249d.lib opencv_highgui249d.lib opencv_imgproc249d.lib opencv_legacy249d.lib opencv_ml249d.lib opencv_nonfree249d.lib opencv_objdetect249d.lib opencv_photo249d.lib opencv_stitching249d.lib opencv_ts249d.lib opencv_video249d.lib opencv_videostab249d.lib
Displays the point cloud map reference:
2 pcl读取pcd文件并显示_HxShine的博客-CSDN博客_pcd文件查看器
//Display point cloud map
pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");//直接创造一个显示窗口
viewer.showCloud(cloud);//再这个窗口显示点云
color.png
depth.png
运行结果
The depth map and color map are not aligned,The possible reason is that the camera internal parameter settings in the code do not match.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129913.html原文链接:https://javaforall.cn
边栏推荐
- LeetCode 86. 分隔链表
- LeetCode 82. Remove Duplicate Elements in Sorted List II
- 建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
- LeetCode 362. Design Hit Counter(计数器)
- 开源的作者,也有个生活问题
- How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
- gpu-admission 源码分析
- 网络套接字(UDP和TCP编程)
- 不止跑路,拯救误操作rm -rf /*的小伙儿
- jlink 与 swd 接口定义
猜你喜欢
Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
单目操作符(含原码反码补码转换)
孩子自律性不够?猿辅导:计划表要注意“留白”给孩子更多掌控感
LAXCUS分布式操作系统安全管理
态路小课堂丨如何为CXP光模块选择光纤跳线?
mpf6_Time Series Data_quandl_更正kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull
项目部署、
StoneDB 文档捉虫活动第一季
从源码角度分析UUID的实现原理
Where can I view the version record of WeChat applet submission review history?
随机推荐
制品库是什么?
A case of violent parameter tuning in machine learning
力扣练习——56 寻找右区间
10 个 Reduce 常用“奇技淫巧”
3款不同类型的自媒体免费工具,有效提高创作、运营效率
快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?
零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?
Cannot find symbol log because lombok is not found
面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
个推数据资产管理经验 | 教你打造数据质量心电图,智能检测数据“心跳”异常
AutoCAD Map 3D功能之一暴力处理悬挂点(延伸)
彩色图和深度图转点云
codevs 2370 Small room tree (LCA)
力扣练习——59 从二叉搜索树到更大和树
LeetCode 109. 有序链表转换二叉搜索树
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
leetcode 823. Binary Trees With Factors(因子二叉树)
LeetCode 21. 合并两个有序链表
网络基础(第一节)
How many constants and data types do you remember?