当前位置:网站首页>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
边栏推荐
- Centos7 environment uses Mysql offline installation package to install Mysql5.7
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- 再有人问你分布式事务,把这篇扔给他
- 配置druid数据源「建议收藏」
- LeetCode 86. 分隔链表
- 力扣练习——61 根据字符出现频率排序
- Apple bucks the trend and expands iPhone 14 series stocking, with a total of 95 million units
- mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull
- 微信小程序提交审核历史版本记录从哪里查看
- LeetCode 82. Remove Duplicate Elements in Sorted List II
猜你喜欢

three.js模糊玻璃效果
Database management tool: dynamic read-write separation

std::move()

即时零售业态下如何实现自动做账?

零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?

怎么加入自媒体,了解这5种变现模式,让账号快速变现

单目操作符(含原码反码补码转换)

mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull

Where can I view the version record of WeChat applet submission review history?

机器学习之暴力调参案例
随机推荐
模块九 - 设计电商秒杀系统
传三星3nm斩获第二家客户,目前产能已供不应求
LeetCode 19. Delete the Nth last node of the linked list
An enhanced dynamic packet buffer management.论文核心部分
Network sockets (UDP and TCP programming)
可视化服务编排在金融APP中的实践
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
ssm框架搭建过程[通俗易懂]
LeetCode 138. Copy a linked list with random pointers
项目部署、
16、Pytorch Lightning入门
[E-commerce operation] Do you really understand social media marketing (SMM)?
Pulling drills - 56 Finding the right interval
因为找不到lombok而找不到符号log
第六届”蓝帽杯“全国大学生网络安全技能大赛半决赛部分WriteUp
Module 9 - Designing an e-commerce seckill system
三星计划2023年开始在越南生产半导体零部件
7、Instant-ngp
网络基础(第一节)
StoneDB Document Bug Hunting Season 1