所需文件百度云链接----提取码mlyz
VS2015+Kinect for Windows SDK2.0+OpenCV3.1.0+PCL1.8.1
1.Kinect V2.0在W10上的配置及运行
组装Kinect V2.0深度相机并将其通过USB3.0接口连接计算机,W10系统会自动安装驱动,安装完成后将USB接口拔掉,此时需要下载Kinect for Windows SDK2.0并安装,打开SDK Browser v2.0通过Kinect Configuration Verifier进行设备检查,如下
2.OpenCV3.1.0在VS2015上的配置及样例运行
下载OpenCV3.1.0安装并配置环境变量如下(vc14代表VS2015)
Path:
在VS2015中新建W32控制台应用程序,后面最好选择空项目,编译模式转换为Debug x64,在属性管理器中Debug x64目录下新建属性表进行属性编辑(以方便后续使用)
在VC++目录中的包含目录下添加如下
在链接器的输入附加依赖项下添加如下(d代表debug版本)
样例代码运行(读取图片-图片路径改为自己的路径)
#include
#include
#include
using namespace cv;
int main() {
// 读入一张图片(游戏原画)
Mat img = imread("C:/Soft/VS2015/Projects/OpenCV3.1.0/pic.jpg");
// 创建一个名为 "游戏原画"窗口
namedWindow("游戏原画");
// 在窗口中显示游戏原画
imshow("游戏原画", img);
// 等待6000 ms后窗口自动关闭
waitKey(6000);
}
运行结果如下
3.Kinect for Windows SDK2.0在VS2015上的配置及样例运行
(同上)在VS2015中新建W32控制台应用程序,后面最好选择空项目,编译模式转换为Debug x64,在属性管理器中Debug x64目录下新建属性表进行属性编辑(以方便后续使用)
在VC++目录中的包含目录下添加如下
在VC++目录中的库目录下添加如下
在链接器的输入附加依赖项下添加如下
样例代码运行(读取深度图-需要添加刚才创建的OpenCV属性表)
#include //Kinect的头文件
#include
#include //opencv头文件
using namespace std;
using namespace cv;
int main(void)
{
IKinectSensor * mySensor = nullptr;
GetDefaultKinectSensor(&mySensor); //获取感应器
mySensor->Open(); //打开感应器
IDepthFrameSource * mySource = nullptr; //取得深度数据
mySensor->get_DepthFrameSource(&mySource);
int height = 0, width = 0;
IFrameDescription * myDescription = nullptr; //取得深度数据的分辨率
mySource->get_FrameDescription(&myDescription);
myDescription->get_Height(&height);
myDescription->get_Width(&width);
myDescription->Release();
IDepthFrameReader * myReader = nullptr;
mySource->OpenReader(&myReader); //打开深度数据的Reader
IDepthFrame * myFrame = nullptr;
Mat temp(height, width, CV_16UC1); //建立图像矩阵
Mat img(height, width, CV_8UC1);
while (1)
{
if (myReader->AcquireLatestFrame(&myFrame) == S_OK) //通过Reader尝试获取最新的一帧深度数据,放入深度帧中,并判断是否成功获取
{
myFrame->CopyFrameDataToArray(height * width, (UINT16 *)temp.data); //先把数据存入16位的图像矩阵中
temp.convertTo(img, CV_8UC1, 255.0 / 4500); //再把16位转换为8位
imshow("TEST", img);
myFrame->Release();
}
if (waitKey(30) == VK_ESCAPE)
break;
}
myReader->Release(); //释放不用的变量并且关闭感应器
mySource->Release();
mySensor->Close();
mySensor->Release();
return 0;
}
运行结果如下
4.PCL1.8.1在VS2015上的配置及样例运行
下载PCL1.8.1安装,PDB文件解压后放在PCL安装目录的bin目录下(自带OpenNI2安装在PCL安装目录的3rdParty目录下)
若在PCL安装时选择自动加入环境变量,则会有
另需手动配置环境变量如下
Path:
(同上)在VS2015中新建W32控制台应用程序,后面最好选择空项目,编译模式转换为Debug x64,在属性管理器中Debug x64目录下新建属性表进行属性编辑(以方便后续使用)
在VC++目录中的包含目录下添加如下
在VC++目录中的库目录下添加如下
在链接器的输入附加依赖项下添加如下
这里需要添加项太多所以单独列举
pcl_common_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_io_debug.lib
pcl_io_ply_debug.lib
pcl_kdtree_debug.lib
pcl_keypoints_debug.lib
pcl_ml_debug.lib
pcl_octree_debug.lib
pcl_outofcore_debug.lib
pcl_people_debug.lib
pcl_recognition_debug.lib
pcl_registration_debug.lib
pcl_sample_consensus_debug.lib
pcl_search_debug.lib
pcl_segmentation_debug.lib
pcl_stereo_debug.lib
pcl_surface_debug.lib
pcl_tracking_debug.lib
pcl_visualization_debug.lib
libboost_atomic-vc140-mt-gd-1_64.lib
libboost_bzip2-vc140-mt-gd-1_64.lib
libboost_chrono-vc140-mt-gd-1_64.lib
libboost_container-vc140-mt-gd-1_64.lib
libboost_context-vc140-mt-gd-1_64.lib
libboost_coroutine-vc140-mt-gd-1_64.lib
libboost_date_time-vc140-mt-gd-1_64.lib
libboost_exception-vc140-mt-gd-1_64.lib
libboost_fiber-vc140-mt-gd-1_64.lib
libboost_filesystem-vc140-mt-gd-1_64.lib
libboost_graph_parallel-vc140-mt-gd-1_64.lib
libboost_graph-vc140-mt-gd-1_64.lib
libboost_iostreams-vc140-mt-gd-1_64.lib
libboost_locale-vc140-mt-gd-1_64.lib
libboost_log-vc140-mt-gd-1_64.lib
libboost_log_setup-vc140-mt-gd-1_64.lib
libboost_math_c99-vc140-mt-gd-1_64.lib
libboost_math_c99f-vc140-mt-gd-1_64.lib
libboost_math_c99l-vc140-mt-gd-1_64.lib
libboost_math_tr1-vc140-mt-gd-1_64.lib
libboost_math_tr1f-vc140-mt-gd-1_64.lib
libboost_math_tr1l-vc140-mt-gd-1_64.lib
libboost_mpi-vc140-mt-gd-1_64.lib
libboost_numpy3-vc140-mt-gd-1_64.lib
libboost_numpy-vc140-mt-gd-1_64.lib
libboost_prg_exec_monitor-vc140-mt-gd-1_64.lib
libboost_program_options-vc140-mt-gd-1_64.lib
libboost_python3-vc140-mt-gd-1_64.lib
libboost_python-vc140-mt-gd-1_64.lib
libboost_random-vc140-mt-gd-1_64.lib
libboost_regex-vc140-mt-gd-1_64.lib
libboost_serialization-vc140-mt-gd-1_64.lib
libboost_signals-vc140-mt-gd-1_64.lib
libboost_system-vc140-mt-gd-1_64.lib
libboost_test_exec_monitor-vc140-mt-gd-1_64.lib
libboost_thread-vc140-mt-gd-1_64.lib
libboost_timer-vc140-mt-gd-1_64.lib
libboost_type_erasure-vc140-mt-gd-1_64.lib
libboost_unit_test_framework-vc140-mt-gd-1_64.lib
libboost_wave-vc140-mt-gd-1_64.lib
libboost_wserialization-vc140-mt-gd-1_64.lib
libboost_zlib-vc140-mt-gd-1_64.lib
vtkzlib-8.0-gd.lib
vtkViewsContext2D-8.0-gd.lib
vtkhdf5_hl-8.0-gd.lib
vtkFiltersProgrammable-8.0-gd.lib
vtkIOMovie-8.0-gd.lib
vtkexpat-8.0-gd.lib
vtkRenderingLOD-8.0-gd.lib
vtkIOPLY-8.0-gd.lib
vtkpng-8.0-gd.lib
vtkIOVideo-8.0-gd.lib
vtkRenderingImage-8.0-gd.lib
vtkFiltersVerdict-8.0-gd.lib
vtkjpeg-8.0-gd.lib
vtkInteractionImage-8.0-gd.lib
vtkverdict-8.0-gd.lib
vtkoggtheora-8.0-gd.lib
vtkImagingStatistics-8.0-gd.lib
vtkCommonSystem-8.0-gd.lib
vtkFiltersParallelImaging-8.0-gd.lib
vtkFiltersTexture-8.0-gd.lib
vtkCommonMisc-8.0-gd.lib
vtkCommonMath-8.0-gd.lib
vtkFiltersSelection-8.0-gd.lib
vtkImagingFourier-8.0-gd.lib
vtkIOXMLParser-8.0-gd.lib
vtkproj4-8.0-gd.lib
vtkalglib-8.0-gd.lib
vtktiff-8.0-gd.lib
vtksqlite-8.0-gd.lib
vtkImagingSources-8.0-gd.lib
vtkCommonTransforms-8.0-gd.lib
vtkImagingMath-8.0-gd.lib
vtkFiltersGeneric-8.0-gd.lib
vtkexoIIc-8.0-gd.lib
vtkfreetype-8.0-gd.lib
vtkImagingColor-8.0-gd.lib
vtknetcdf_c+±gd.lib
vtkNetCDF-8.0-gd.lib
vtkFiltersImaging-8.0-gd.lib
vtkFiltersHyperTree-8.0-gd.lib
vtkImagingMorphological-8.0-gd.lib
vtkImagingStencil-8.0-gd.lib
vtkRenderingFreeType-8.0-gd.lib
vtkCommonColor-8.0-gd.lib
vtkjsoncpp-8.0-gd.lib
vtkRenderingContext2D-8.0-gd.lib
vtkFiltersAMR-8.0-gd.lib
vtkRenderingContextOpenGL-8.0-gd.lib
vtkIOParallelXML-8.0-gd.lib
vtkViewsCore-8.0-gd.lib
vtkImagingHybrid-8.0-gd.lib
vtkIOExport-8.0-gd.lib
vtkRenderingVolumeOpenGL-8.0-gd.lib
vtkIOImport-8.0-gd.lib
vtkDomainsChemistry-8.0-gd.lib
vtkInteractionStyle-8.0-gd.lib
vtkCommonComputationalGeometry-8.0-gd.lib
vtkDICOMParser-8.0-gd.lib
vtklibxml2-8.0-gd.lib
vtkIOMINC-8.0-gd.lib
vtkIOSQL-8.0-gd.lib
vtkFiltersModeling-8.0-gd.lib
vtkParallelCore-8.0-gd.lib
vtkIOAMR-8.0-gd.lib
vtkGeovisCore-8.0-gd.lib
vtksys-8.0-gd.lib
vtkIOEnSight-8.0-gd.lib
vtkImagingGeneral-8.0-gd.lib
vtkFiltersFlowPaths-8.0-gd.lib
vtkIOLSDyna-8.0-gd.lib
vtkFiltersSMP-8.0-gd.lib
vtkIOParallel-8.0-gd.lib
vtkFiltersGeometry-8.0-gd.lib
vtkInfovisLayout-8.0-gd.lib
vtkIOCore-8.0-gd.lib
vtkFiltersSources-8.0-gd.lib
vtkIOLegacy-8.0-gd.lib
vtkFiltersHybrid-8.0-gd.lib
vtkIONetCDF-8.0-gd.lib
vtkFiltersExtraction-8.0-gd.lib
vtkFiltersParallel-8.0-gd.lib
vtkRenderingLabel-8.0-gd.lib
vtkIOInfovis-8.0-gd.lib
vtkRenderingAnnotation-8.0-gd.lib
vtkImagingCore-8.0-gd.lib
vtkCommonExecutionModel-8.0-gd.lib
vtkhdf5-8.0-gd.lib
vtkViewsInfovis-8.0-gd.lib
vtkIOGeometry-8.0-gd.lib
vtkmetaio-8.0-gd.lib
vtkIOImage-8.0-gd.lib
vtkIOXML-8.0-gd.lib
vtkIOExodus-8.0-gd.lib
vtkRenderingVolume-8.0-gd.lib
vtkChartsCore-8.0-gd.lib
vtkFiltersStatistics-8.0-gd.lib
vtkInfovisCore-8.0-gd.lib
vtkRenderingCore-8.0-gd.lib
vtkInteractionWidgets-8.0-gd.lib
vtkRenderingOpenGL-8.0-gd.lib
vtkFiltersGeneral-8.0-gd.lib
vtkFiltersCore-8.0-gd.lib
vtkCommonDataModel-8.0-gd.lib
vtkCommonCore-8.0-gd.lib
flann_cpp_s-gd.lib
qhullstatic_d.lib
OpenNI2.lib
在C/C++下常规里将SDL检查设置为否(否则程序将报错)
在C/C++下预处理器定义中添加如下(否则程序将报错)
对于Warning C4819编码问题解决方式如下
双击warning
文件→高级保存选项→将编码改为简体中文(GB2312)→点击确定
样例代码运行(点云生成及保存)
#include
#include
#include
#include
#include
int main(int argc, char** argv)
{
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
pcl::PointCloud::Ptr cloud_projected(new pcl::PointCloud);
// Fill in the cloud data
cloud->width = 5;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
}
std::cerr << "Cloud before projection: " << std::endl;
for (size_t i = 0; i < cloud->points.size(); ++i)
std::cerr << " " << cloud->points[i].x << " "
<< cloud->points[i].y << " "
<< cloud->points[i].z << std::endl;
// Create a set of planar coefficients with X=Y=0,Z=1
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
coefficients->values.resize(4);
coefficients->values[0] = coefficients->values[1] = 0;
coefficients->values[2] = 1.0;
coefficients->values[3] = 0;
// Create the filtering object
pcl::ProjectInliers proj;
proj.setModelType(pcl::SACMODEL_PLANE);
proj.setInputCloud(cloud);
proj.setModelCoefficients(coefficients);
proj.filter(*cloud_projected);
std::cerr << "Cloud after projection: " << std::endl;
for (size_t i = 0; i < cloud_projected->points.size(); ++i)
std::cerr << " " << cloud_projected->points[i].x << " "
<< cloud_projected->points[i].y << " "
<< cloud_projected->points[i].z << std::endl;
system("pause");
return (0);
}
参考博客
https://blog.csdn.net/uniqueyyc/article/details/79245009
https://www.jianshu.com/p/d2f48867d578