C++环境下Kinect采集图像和PCL点云数据

本文介绍了如何在C++环境中利用Kinect设备采集图像和PCL库处理点云数据。首先,需要编译Kinect和PCL库。通过Kinect获取cameraSpace的三维坐标点和colorSpace的RGB图像,将两者结合得到pointxyzrgb点云数据。CMakeLists.txt、definition.h、KinectPointcloud.cpp和main.cpp是实现过程的关键文件,详细步骤和代码解释有助于理解点云数据的采集和处理。最后,提供了在Python中读取PCD文件的参考资料。
摘要由CSDN通过智能技术生成

事先需要先编译好Kinect和PCL的库

先用Kinect获取视野里cameraSpace的三维坐标点和colorSpace的rgb图像,因为这两个数据都是depthFrame map过去的,所以这两组点可以看做是一一对应的,把三维坐标和颜色结合就能得到点云的pointxyzrgb数据了。

CMakeLists.txt文件如下:


# cmake needs this line
cmake_minimum_required(VERSION 3.1)

# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

#Define project name
project(robotCalibrate)

set(KINECT_INC "C:\\Program Files\\Microsoft SDKs\\Kinect\\v2.0_1409\\inc")
set(KINECT_LIB "C:\\Program Files\\Microsoft SDKs\\Kinect\\v2.0_1409\\Lib\\x64")



find_package(OpenCV REQUIRED)
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS} ${KINECT_INC} )
message("${PCL_LIBRARIES}")

link_directories(${PCL_LIBRARY_DIRS} ${KINECT_LIB})
add_definitions(${PCL_DEFINITIONS})

add_executable(robotCalibrate main.cpp lib.cpp definition.h KinectPointcloud.cpp)
target_link_libraries(robotCalibrate ${PCL_LIBRARIES} ${OpenCV_LIBS} kinect20.lib)

 definition.h文件里如下

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <pcl/visualization/pcl_visualizer.h>
#include <kinect.h>

using namespace std;

typedef pcl::PointXYZRGB PointRGB;
typedef pcl::PointCloud<pcl::PointXYZ> PointCloudXYZ;
typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;

#define depthWidth 512
#define depthHeight 424
#define rgbWidth 1920
#define rgbHeight 1080
#define depthSize 424 * 512
#define rgbSize 1920 * 1080

class KinectPointcloud
{

public:

	template<class Interface>
	inline void SafeRelease(Interface *& pInterfaceToRelease);

	KinectPointcloud();
	void getPointcloudData();
	PointCloudRGB::Ptr getPointcloud();
	ColorSpacePoint* colorSpacePts = new ColorSpacePoint[depthSize];     // Maps depth pixels to rgb pixels
	CameraSpacePoint* cameraSpacePts = new CameraSpacePoint[depthSize];    // Maps depth pixels to 3d coordinates
	cv::Mat getRGBImg();
	cv::Mat getDepthImg();
	~KinectPointcloud();

private:
	IKinectSensor* _sensor = nullptr;

	std::string _filepath;
	PointCloudRGB::Ptr _cloud = PointCloudRGB::Ptr(new PointCloudRGB);
	cv::Mat _rgbImg;
	cv::Mat _depthImg;
	PointRGB _neckPoint;

};

template<
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值