欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Visual Studio 2017 双目开发(一)——opencv及PCL配置

程序员文章站 2022-03-21 21:37:01
...

Visual Studio 2017 双目开发

Visual Studio 2017 双目开发项目主要包含下面几个方法:

  • opencv及PCL配置
  • MSRA-OpenPAI介绍及配置
  • 调用摄像头及图片分隔
  • opencv及流处理分割
  • 摄像头畸变矫正及匹配
  • 深度图生成及点云
  • 待续

opencv介绍及下载

 OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库。OpenCV是由英特尔公司发起并参与开发,以BSD许可证授权发行,可以在商业和研究领域中免费使用。OpenCV可用于开发实时的图像处理、计算机视觉以及模式识别程序。
 OpenCV项目最早由英特尔公司于1999年启动,致力于CPU密集型的任务,是一个包括如光线追踪和3D显示的计划的一部分。早期OpenCV的主要目标是:

  • 为推进机器视觉的研究,提供一套开源且优化的基础库。不重造*。
  • 提供一个共同的基础库,使得开发人员的代码更容易阅读和转让,促进了知识的传播。
  • 通过提供一个不需要开源或免费的软件许可,促进商业应用软件的开发。
  • OpenCV现在也集成了对CUDA的支持.

其现在一般于解决例如增强现实、人脸识别、手势交互、人机交互、动作识别、运动跟踪、舞台识别、图像分割等问题。
下载地址:https://opencv.org/releases.html
(本系列所用的为3.4.1版本)
Visual Studio 2017 双目开发(一)——opencv及PCL配置
下载完成后点击安装就好了,这是一个自解压文件,在你配置环境前可以*复制移动到你想要的任何地方。

PCL介绍及下载

Visual Studio 2017 双目开发(一)——opencv及PCL配置
Point Cloud Library是点云处理任务和3D几何处理的开源算法库,例如三维计算机视觉中出现的算法。该库包含用于特征估计,表面重构,3D配准,模型拟合和分割的算法。它是用C ++编写的,并且在BSD许可下发布。
下载地址:https://github.com/PointCloudLibrary/pcl/releases
(本系列所用的为1.8.1版本,请下载AllInOne和pdb两个对应版本的)
Visual Studio 2017 双目开发(一)——opencv及PCL配置
之后运行.exe文件进行安装,在安装过程中选择

Add PCL to the system PATH

以自动添加环境变量,省去人工添加的问题。
安装过程中,如果不确定是否不需要其他库,请选点上安装全部组件。

之后安装会弹出OpenNI2的安装窗口,可以一路next,但是请记住其安装路径,这在之后的系统环境配置中会用到。

系统环境变量配置

opencv
在Windows10(本系列默认开发环境为Windows 10 Pro 64-bit)下,点开系统属性,在系统变量中设置path,添加

"your opencv location"\build\x64\vc15\bin                       /*前面的内容取决于opencv所在路径*/

到Windows的环境变量中

PCL

同上的系统变量,添加下面的目录到PATH中

%PCL_ROOT%\bin
%PCL_ROOT%\3rdParty\VTK\bin
%PCL_ROOT%\3rdParty\FLANN\bin
%OPENNI2_REDIST64%
%PCL_ROOT%\3rdParty\Qhull\bin
"your OpenNI location"\Tools           /*前面的内容取决于openNI2所在路径*/

配置好系统环境变量后,建议重启电脑来应用环境变量(虽然不重启也可以,但是重启会减少某些设备报错的概率)

VS2017 开发环境配置

opencv
在右侧的解决方案管理器中找到“属性页”(Properties),点开VC++ Directories,将

"your opencv location"\build\include\opencv2
"your opencv location"\build\include\opencv
"your opencv location"\build\include
/*前面的内容取决于opencv所在路径*/

添加到 Include Directories中去

再将

"your opencv location"\build\x64\vc15\lib
/*前面的内容取决于opencv所在路径*/

添加到Library Directories中去

最后是添加lib库,在右侧的Linker中的Input,编辑Additional Dependencies,使用debug就添加

"your opencv location"\build\x64\vc15\lib\opencv_world341d.lib
/*前面的内容取决于opencv所在路径*/

Visual Studio 2017 双目开发(一)——opencv及PCL配置
使用release就添加

"your opencv location"\build\x64\vc15\lib\opencv_world341.lib
/*前面的内容取决于opencv所在路径*/

最后还需要将“opencv\build\x64\vc15\bin”路径下的三个dll文件拷贝到C:\Windows\System32与C:\Windows\SysWOW64下面,完成动态库的链接

PCL
同opencv,PCL的配置方法也是先打开“属性页”(Properties),这里仅讲解debug模式下的配置方法。
点开VC++ Directories,将

"your  OpenNI location"\Include
/*前面的内容取决于OpenNI2所在路径*/
"your PCL location"\include\pcl-1.8
"your PCL location"\3rdParty\VTK\include\vtk-8.0
"your PCL location"\3rdParty\QHull\include
"your PCL location"\3rdParty\FLANN\include
"your PCL location"\3rdParty\Eigen\eigen3
"your PCL location"\3rdParty\Boost\include\boost-1_64
/*前面的内容取决于PCL所在路径*/

添加到 Include Directories中去(PS:请注意以上路径末尾数字版本号与你的本地文件是一致的)

再将

"your  OpenNI location"\Lib
/*前面的内容取决于OpenNI2所在路径*/
"your PCL location"\lib
"your PCL location"\3rdParty\VTK\lib
"your PCL location"\3rdParty\QHull\lib
"your PCL location"\3rdParty\FLANN\lib
"your PCL location"\3rdParty\Boost\lib
/*前面的内容取决于PCL所在路径*/

添加到Library Directories中去
Visual Studio 2017 双目开发(一)——opencv及PCL配置
最后是在C/C++下的Preprocessor中的Preprocessor Definitions中添加
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS

最后是添加lib库,在右侧的Linker中的Input,编辑Additional Dependencies,添加

vtknetcdf_c++-gd.lib
pcl_common_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_io_ply_debug.lib
pcl_io_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-vc141-mt-gd-1_64.lib
libboost_bzip2-vc141-mt-gd-1_64.lib
libboost_chrono-vc141-mt-gd-1_64.lib
libboost_container-vc141-mt-gd-1_64.lib
libboost_context-vc141-mt-gd-1_64.lib
libboost_coroutine-vc141-mt-gd-1_64.lib
libboost_date_time-vc141-mt-gd-1_64.lib
libboost_exception-vc141-mt-gd-1_64.lib
libboost_fiber-vc141-mt-gd-1_64.lib
libboost_filesystem-vc141-mt-gd-1_64.lib
libboost_graph-vc141-mt-gd-1_64.lib
libboost_graph_parallel-vc141-mt-gd-1_64.lib
libboost_iostreams-vc141-mt-gd-1_64.lib
libboost_locale-vc141-mt-gd-1_64.lib
libboost_log-vc141-mt-gd-1_64.lib
libboost_log_setup-vc141-mt-gd-1_64.lib
libboost_math_c99-vc141-mt-gd-1_64.lib
libboost_math_c99f-vc141-mt-gd-1_64.lib
libboost_math_c99l-vc141-mt-gd-1_64.lib
libboost_math_tr1-vc141-mt-gd-1_64.lib
libboost_math_tr1f-vc141-mt-gd-1_64.lib
libboost_math_tr1l-vc141-mt-gd-1_64.lib
libboost_mpi-vc141-mt-gd-1_64.lib
libboost_numpy3-vc141-mt-gd-1_64.lib
libboost_numpy-vc141-mt-gd-1_64.lib
libboost_prg_exec_monitor-vc141-mt-gd-1_64.lib
libboost_program_options-vc141-mt-gd-1_64.lib
libboost_python3-vc141-mt-gd-1_64.lib
libboost_python-vc141-mt-gd-1_64.lib
libboost_random-vc141-mt-gd-1_64.lib
libboost_regex-vc141-mt-gd-1_64.lib
libboost_serialization-vc141-mt-gd-1_64.lib
libboost_signals-vc141-mt-gd-1_64.lib
libboost_system-vc141-mt-gd-1_64.lib
libboost_test_exec_monitor-vc141-mt-gd-1_64.lib
libboost_thread-vc141-mt-gd-1_64.lib
libboost_timer-vc141-mt-gd-1_64.lib
libboost_type_erasure-vc141-mt-gd-1_64.lib
libboost_unit_test_framework-vc141-mt-gd-1_64.lib
libboost_wave-vc141-mt-gd-1_64.lib
libboost_wserialization-vc141-mt-gd-1_64.lib
libboost_zlib-vc141-mt-gd-1_64.lib
flann-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
flann_s-gd.lib
qhull_d.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_r_d.lib
qhull_p_d.lib
qhull_r_d.lib
vtkalglib-8.0-gd.lib
vtkChartsCore-8.0-gd.lib
vtkCommonColor-8.0-gd.lib
vtkCommonComputationalGeometry-8.0-gd.lib
vtkCommonCore-8.0-gd.lib
vtkCommonDataModel-8.0-gd.lib
vtkCommonExecutionModel-8.0-gd.lib
vtkCommonMath-8.0-gd.lib
vtkCommonMisc-8.0-gd.lib
vtkCommonSystem-8.0-gd.lib
vtkCommonTransforms-8.0-gd.lib
vtkDICOMParser-8.0-gd.lib
vtkDomainsChemistry-8.0-gd.lib
vtkexoIIc-8.0-gd.lib
vtkexpat-8.0-gd.lib
vtkFiltersAMR-8.0-gd.lib
vtkFiltersCore-8.0-gd.lib
vtkFiltersExtraction-8.0-gd.lib
vtkFiltersFlowPaths-8.0-gd.lib
vtkFiltersGeneral-8.0-gd.lib
vtkFiltersGeneric-8.0-gd.lib
vtkFiltersGeometry-8.0-gd.lib
vtkFiltersHybrid-8.0-gd.lib
vtkFiltersHyperTree-8.0-gd.lib
vtkFiltersImaging-8.0-gd.lib
vtkFiltersModeling-8.0-gd.lib
vtkFiltersParallel-8.0-gd.lib
vtkFiltersParallelImaging-8.0-gd.lib
vtkFiltersPoints-8.0-gd.lib
vtkFiltersProgrammable-8.0-gd.lib
vtkFiltersSelection-8.0-gd.lib
vtkFiltersSMP-8.0-gd.lib
vtkFiltersSources-8.0-gd.lib
vtkFiltersStatistics-8.0-gd.lib
vtkFiltersTexture-8.0-gd.lib
vtkFiltersTopology-8.0-gd.lib
vtkFiltersVerdict-8.0-gd.lib
vtkfreetype-8.0-gd.lib
vtkGeovisCore-8.0-gd.lib
vtkgl2ps-8.0-gd.lib
vtkhdf5-8.0-gd.lib
vtkhdf5_hl-8.0-gd.lib
vtkImagingColor-8.0-gd.lib
vtkImagingCore-8.0-gd.lib
vtkImagingFourier-8.0-gd.lib
vtkImagingGeneral-8.0-gd.lib
vtkImagingHybrid-8.0-gd.lib
vtkImagingMath-8.0-gd.lib
vtkImagingMorphological-8.0-gd.lib
vtkImagingSources-8.0-gd.lib
vtkImagingStatistics-8.0-gd.lib
vtkImagingStencil-8.0-gd.lib
vtkInfovisCore-8.0-gd.lib
vtkInfovisLayout-8.0-gd.lib
vtkInteractionImage-8.0-gd.lib
vtkInteractionStyle-8.0-gd.lib
vtkInteractionWidgets-8.0-gd.lib
vtkIOAMR-8.0-gd.lib
vtkIOCore-8.0-gd.lib
vtkIOEnSight-8.0-gd.lib
vtkIOExodus-8.0-gd.lib
vtkIOExport-8.0-gd.lib
vtkIOExportOpenGL-8.0-gd.lib
vtkIOGeometry-8.0-gd.lib
vtkIOImage-8.0-gd.lib
vtkIOImport-8.0-gd.lib
vtkIOInfovis-8.0-gd.lib
vtkIOLegacy-8.0-gd.lib
vtkIOLSDyna-8.0-gd.lib
vtkIOMINC-8.0-gd.lib
vtkIOMovie-8.0-gd.lib
vtkIONetCDF-8.0-gd.lib
vtkIOParallel-8.0-gd.lib
vtkIOParallelXML-8.0-gd.lib
vtkIOPLY-8.0-gd.lib
vtkIOSQL-8.0-gd.lib
vtkIOTecplotTable-8.0-gd.lib
vtkIOVideo-8.0-gd.lib
vtkIOXML-8.0-gd.lib
vtkIOXMLParser-8.0-gd.lib
vtkjpeg-8.0-gd.lib
vtkjsoncpp-8.0-gd.lib
vtklibharu-8.0-gd.lib
vtklibxml2-8.0-gd.lib
vtklz4-8.0-gd.lib
vtkmetaio-8.0-gd.lib
vtkNetCDF-8.0-gd.lib
vtkoggtheora-8.0-gd.lib
vtkParallelCore-8.0-gd.lib
vtkpng-8.0-gd.lib
vtkproj4-8.0-gd.lib
vtkRenderingAnnotation-8.0-gd.lib
vtkRenderingContext2D-8.0-gd.lib
vtkRenderingContextOpenGL-8.0-gd.lib
vtkRenderingCore-8.0-gd.lib
vtkRenderingFreeType-8.0-gd.lib
vtkRenderingGL2PS-8.0-gd.lib
vtkRenderingImage-8.0-gd.lib
vtkRenderingLabel-8.0-gd.lib
vtkRenderingLIC-8.0-gd.lib
vtkRenderingLOD-8.0-gd.lib
vtkRenderingOpenGL-8.0-gd.lib
vtkRenderingVolume-8.0-gd.lib
vtkRenderingVolumeOpenGL-8.0-gd.lib
vtksqlite-8.0-gd.lib
vtksys-8.0-gd.lib
vtktiff-8.0-gd.lib
vtkverdict-8.0-gd.lib
vtkViewsContext2D-8.0-gd.lib
vtkViewsCore-8.0-gd.lib
vtkViewsInfovis-8.0-gd.lib
vtkzlib-8.0-gd.lib
opengl32.lib

环境验证

opencv
opencv下可以用简单的图片显示来验证,用imshow来显示,笔者写的示例代码如下(去掉注释)

//#include<opencv2/opencv.hpp>
//using namespace cv;
//
//int main() {
//  mat img = imread("c:\\users\\97631\\desktop\\timg.png");
//  imshow("s", img);
//  waitkey(0);
//}

PCL
PCL也可以通过pcl的github上面的各种库进行显示,用cloud viewer 来显示,笔者写的示例代码如下(去掉注释)

#include <iostream> 
#include <string> 
#include <pcl/io/pcd_io.h> 
#include <pcl/point_types.h> 
#include <pcl/visualization/pcl_visualizer.h> 
using namespace std;

int main(int argc, char** argv) {
    typedef pcl::PointXYZRGBA PointT;
    pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);

    std::string dir = "E:\\GitHub\\pcl\\test\\";
    std::string filename = "pcl_logo.pcd";

    if (pcl::io::loadPCDFile<PointT>((dir + filename), *cloud) == -1) {
        //* load the file 
        PCL_ERROR("Couldn't read PCD file \n");
        return (-1);
    }
    printf("Loaded %d data points from PCD\n",
        cloud->width * cloud->height);

    for (size_t i = 0; i < cloud->points.size(); i += 1000)
        printf("%8.3f %8.3f %8.3f %5d %5d %5d %5d\n",
            cloud->points[i].x,
            cloud->points[i].y,
            cloud->points[i].z,
            cloud->points[i].r,
            cloud->points[i].g,
            cloud->points[i].b,
            cloud->points[i].a
        );

    pcl::visualization::PCLVisualizer viewer("Cloud viewer");
    viewer.setCameraPosition(0, 0, -3.0, 0, -1, 0);
    viewer.addCoordinateSystem(0.3);

    viewer.addPointCloud(cloud);
    while (!viewer.wasStopped())
        viewer.spinOnce(100);
    return (0);
}

Visual Studio 2017 双目开发(一)——opencv及PCL配置

引用
1 opencv介绍:https://en.wikipedia.org/wiki/OpenCV
2 PCL介绍:https://en.wikipedia.org/wiki/Point_Cloud_Library
3 PCL环境配置:http://gyshgx868.github.io/2018/03/06/PointCloud/pcl-install/
4 opencv环境配置:https://my.oschina.net/u/3800567/blog/1792040