当前位置:网站首页>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
边栏推荐
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- 10 个 Reduce 常用“奇技淫巧”
- Buckle Exercise - 61 Sort by frequency of characters
- 力扣练习——63 找到字符串中所有字母异位词
- If someone asks you about distributed transactions again, throw this to him
- LeetCode 92. Reverse Linked List II
- 力扣练习——64 最长和谐子序列
- Ssm framework construction process [easy to understand]
- LeetCode 19. Delete the Nth last node of the linked list
- Apple bucks the trend and expands iPhone 14 series stocking, with a total of 95 million units
猜你喜欢

Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability

VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions

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

从源码角度分析UUID的实现原理

孩子自律性不够?猿辅导:计划表要注意“留白”给孩子更多掌控感

推荐6个自媒体领域,轻松易上手

使用哈工大LTP测试分词并且增加自定义字典

Module 9 - Designing an e-commerce seckill system

一文读懂NFT数字藏品为何风靡全球?

微信小程序,全局变量一个地方改变了其他地方的状态也跟着改变。
随机推荐
LeetCode 109. 有序链表转换二叉搜索树
第六届”蓝帽杯“全国大学生网络安全技能大赛半决赛部分WriteUp
孩子自律性不够?猿辅导:计划表要注意“留白”给孩子更多掌控感
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
网络套接字(UDP和TCP编程)
What are some useful performance testing tools recommended? Performance testing report charging standards
16、Pytorch Lightning入门
An enhanced dynamic packet buffer management.论文核心部分
制品库是什么?
LeetCode 24. 两两交换链表中的节点
LeetCode 109. Sorted Linked List Conversion Binary Search Tree
ViT结构详解(附pytorch代码)
7、Instant-ngp
LeetCode 362. Design Hit Counter(计数器)
three.js模糊玻璃效果
力扣练习——59 从二叉搜索树到更大和树
LeetCode 237. 删除链表中的节点
搜索--01
Network Fundamentals (Section 1)
微信小程序提交审核历史版本记录从哪里查看