当前位置:网站首页>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
边栏推荐
- 第六届”蓝帽杯“全国大学生网络安全技能大赛半决赛部分WriteUp
- 托米的咒语
- LeetCode 61. 旋转链表
- 力扣练习——61 根据字符出现频率排序
- Not just running away, but saving the guy who mishandled rm -rf /*
- 中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
- 【Untitled】
- LeetCode 83. Remove Duplicate Elements in Sorted List
- Database management tool: dynamic read-write separation
- LeetCode 369. Plus One Linked List
猜你喜欢
推荐6个自媒体领域,轻松易上手
再有人问你分布式事务,把这篇扔给他
Since the media hot style title how to write?Taught you how to write the title
StoneDB Document Bug Hunting Season 1
LAXCUS分布式操作系统安全管理
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
皕杰报表在传参乱码
3款不同类型的自媒体免费工具,有效提高创作、运营效率
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
随机推荐
有哪些好用的性能测试工具推荐?性能测试报告收费标准
LeetCode 86. 分隔链表
Apple bucks the trend and expands iPhone 14 series stocking, with a total of 95 million units
Database management tool: dynamic read-write separation
AutoCAD Map 3D功能之一暴力处理悬挂点(延伸)
Configuration swagger
Analysis of the implementation principle of UUID from the perspective of source code
微信小程序,全局变量一个地方改变了其他地方的状态也跟着改变。
LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)
LeetCode 21. 合并两个有序链表
ViT结构详解(附pytorch代码)
网络套接字(UDP和TCP编程)
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
搜索--09
快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?
暑期总结4
LeetCode 362. Design Hit Counter
不止跑路,拯救误操作rm -rf /*的小伙儿
常量及数据类型你还记得多少?
2016,还是到了最后