C++调用tensorflow模型捕捉摄像头采集图像做物体检测-opencv4.2.0

  • 你需要拥有的基础
  • 主要操作流程
  • 遇到的问题

你需要拥有的基础

你需要拥有一个编译过的不低于3.3版本的opencv,一定要保证有opencv_contrib-4.2.0这个库,这是我编译好的opencv4.2.0的文件夹

opencvsharp目标识别与跟踪_ide


如果你的版本低于3.3,而你又不想重新换一个新的版本,那你就需要重新对contrib库进行编译,网上有各种不同版本的编译教程(但我觉得都挺蛮烦的,懒人一个了。。。所以还是找个高版本的吧)

另外我的是win10系统和VS2015,大家愿意的话还是保持一致可以避免一点版本不同类似的烦恼。

主要操作流程

大家可以参考这篇博客:我也是基础查看的这篇,感谢作者的分享

遇到的问题

1、“未定义的外部命令”

VS中出现这种问题,一般情况下是opencv配置的问题,你需要找到你的属性页,然后去配置包含目录、库目录、和链接器->输入->可附加依赖项。opencv4的配置和opencv3的配置还是有点不太一样的,一下是我的配置,方便大家相互对照,直接配置自己的(注意一定要是你自己的路径)。

opencvsharp目标识别与跟踪_opencvsharp目标识别与跟踪_02


opencvsharp目标识别与跟踪_opencvsharp目标识别与跟踪_03


由于可附加依赖项过多,我基本上就是全部添加进去了,对自己需要比较了解的也可以只添加自己需要的,我把我添加的东西列一下方便复制。

opencv_aruco420d.lib
 opencv_bgsegm420d.lib
 opencv_bioinspired420d.lib
 opencv_calib3d420d.lib
 opencv_ccalib420d.lib
 opencv_core420d.lib
 opencv_cudaarithm420d.lib
 opencv_cudabgsegm420d.lib
 opencv_cudacodec420d.lib
 opencv_cudafeatures2d420d.lib
 opencv_cudafilters420d.lib
 opencv_cudaimgproc420d.lib
 opencv_cudalegacy420d.lib
 opencv_cudaobjdetect420d.lib
 opencv_cudaoptflow420d.lib
 opencv_cudastereo420d.lib
 opencv_cudawarping420d.lib
 opencv_cudev420d.lib
 opencv_datasets420d.lib
 opencv_dnn420d.lib
 opencv_dnn_objdetect420d.lib
 opencv_dnn_superres420d.lib
 opencv_dpm420d.lib
 opencv_face420d.lib
 opencv_features2d420d.lib
 opencv_flann420d.lib
 opencv_fuzzy420d.lib
 opencv_gapi420d.lib
 opencv_hfs420d.lib
 opencv_highgui420d.lib
 opencv_imgcodecs420d.lib
 opencv_imgproc420d.lib
 opencv_img_hash420d.lib
 opencv_line_descriptor420d.lib
 opencv_ml420d.lib
 opencv_objdetect420d.lib
 opencv_optflow420d.lib
 opencv_phase_unwrapping420d.lib
 opencv_photo420d.lib
 opencv_plot420d.lib
 opencv_quality420d.lib
 opencv_reg420d.lib
 opencv_rgbd420d.lib
 opencv_saliency420d.lib
 opencv_shape420d.lib
 opencv_stereo420d.lib
 opencv_stitching420d.lib
 opencv_structured_light420d.lib
 opencv_superres420d.lib
 opencv_surface_matching420d.lib
 opencv_text420d.lib
 opencv_tracking420d.lib
 opencv_video420d.lib
 opencv_videoio420d.lib
 opencv_videostab420d.lib
 opencv_xfeatures2d420d.lib
 opencv_ximgproc420d.lib
 opencv_xobjdetect420d.lib
 opencv_xphoto420d.lib

opencvsharp目标识别与跟踪_2d_04


2、这时候如果不报错,但是未能达到效果,就要去注意一下你的摄像头了,一定要看好自己摄像头的驱动装了没有。在保证摄像头驱动装好的情况下,基本上就可以正常运行了。