当前位置:   article > 正文

windows+vscode+opencv源码安装配置_cleaning internal cached variable: webp_library

cleaning internal cached variable: webp_library

一、参考资料

VScode搭建OpenCV环境
OpenCV使用CMake和MinGW-w64的编译安装
win10下VSCode配置opencv4.4.0(超详细教程,亲测有效)
VSCODE中配置C++的OPENCV库
Windows10下Opencv4+CMake+MinGW64+VSC安装教程
CMake和minGW-64 编译安装 OpenCV3.4.11以供 Qt 使用
visual studio 2019 安装 opencv 详细图文流程
win10下使用Cmake的MinGW编译配置Opencv

二、步骤

1. vscode安装并配置

2. MinGW安装并配置

参考博客 【Windows版】配置C/C++开发环境

3. 官网下载OpenCV源码并安装

OpenCV官网

解压OpenCV源码
opencv-4.5.2-vc14_vc15.exe

##begin---------------------2021-06-22补充----------------------------##

OpenCV首页找不到链接,解决办法如下图:

##end---------------------2021-06-22补充----------------------------##

4. CMake安装并配置(配置编译选项)
安装CMake,参考博客 【Windows版】CMake安装教程

(1)打开 cmake-gui,设置源码路径和编译生成路径:
cmake-gui.exe的路径:D:\360Downloads\CMake\cmake-3.20.3-windows-x86_64\bin\cmake-gui.exe
Where is the source code: 
D:/360Downloads/Software/opencv/sources

Where to build the binaries: 
D:/360Downloads/Software/opencv/build/x64/MinGw

MinGw是新建的文件夹,用来存放编译好的OpenCV

(2)点击 Configure,设置编译器

配置好opencv的源码路径和编译生成路径,点击Configure即可触发配置,第一次配置需要输入编译器类型以及Makefile类型:

Compilers C: D:\360Downloads\MinGW\mingw64\bin\gcc.exe
Compilers C++: D:\360Downloads\MinGW\mingw64\bin\g++.exe

勾选 WITH_OPENGL
勾选 ENABLE_CXX11
不勾选 WITH_IPP
不勾选 ENABLE_PRECOMPILED_HEADERS

 第一次Configure,生成红色的,勾选对应的属性之后,再重新Configure。

CMake的 Configure要多点几次, 一直点到上面的配置项没有红色为止。

 (3)勾选配置

  1. 勾选:
  2. BUILD_opencv_world
  3. WITH_OPENGL
  4. BUILD_EXAMPLES
  5. 设置OPENCV_DOWNLOAD_PATH
  6. 不勾选:
  7. WITH_IPP
  8. WITH_MSMF
  9. ENABLE_PRECOMPILED_HEADERS
  10. CPU_DISPATCH

如果要编译 opencv_contrib,则需要在 OPENCV_EXTRA_MODULES_PATH 把路径选择为解压的 opencv_contrib 文件中的“modules”文件夹。  再次点击Configure。

 ======================完整的参数配置=========================

---------------2021-06-04补充--------------- 

  1. General configuration for OpenCV 4.5.2 =====================================
  2. Version control: unknown
  3. Extra modules:
  4. Location (extra): D:/360Downloads/opencv/opencv_contrib-4.5.2/modules
  5. Version control (extra): unknown
  6. Platform:
  7. Timestamp: 2021-06-04T01:58:13Z
  8. Host: Windows 10.0.17763 AMD64
  9. CMake: 3.20.3
  10. CMake generator: Visual Studio 16 2019
  11. CMake build tool: D:/360Downloads/VisualStudio2019/2019/Professional/MSBuild/Current/Bin/MSBuild.exe
  12. MSVC: 1929
  13. Configuration: Debug Release
  14. CPU/HW features:
  15. Baseline: SSE SSE2 SSE3
  16. requested: SSE3
  17. Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
  18. requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  19. SSE4_1 (17 files): + SSSE3 SSE4_1
  20. SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
  21. FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  22. AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  23. AVX2 (31 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  24. AVX512_SKX (7 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
  25. C/C++:
  26. Built as dynamic libs?: YES
  27. C++ standard: 11
  28. C++ Compiler: D:/360Downloads/VisualStudio2019/2019/Professional/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe (ver 19.29.30037.0)
  29. C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MD /O2 /Ob2 /DNDEBUG
  30. C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MDd /Zi /Ob0 /Od /RTC1
  31. C Compiler: D:/360Downloads/VisualStudio2019/2019/Professional/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe
  32. C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MD /O2 /Ob2 /DNDEBUG
  33. C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MDd /Zi /Ob0 /Od /RTC1
  34. Linker flags (Release): /machine:x64 /INCREMENTAL:NO
  35. Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
  36. ccache: NO
  37. Precompiled headers: YES
  38. Extra dependencies: opengl32 glu32 cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:D:/360Downloads/CUDA11.3/NVIDIA GPU Computing Toolkit/CUDA/v11.3/lib/x64
  39. 3rdparty dependencies:
  40. OpenCV modules:
  41. To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
  42. Disabled: world
  43. Disabled by dependency: -
  44. Unavailable: alphamat cnn_3dobj cvv freetype java julia matlab ovis python2 sfm viz
  45. Applications: tests perf_tests examples apps
  46. Documentation: NO
  47. Non-free algorithms: YES
  48. Windows RT support: NO
  49. GUI:
  50. Win32 UI: YES
  51. OpenGL support: YES (opengl32 glu32)
  52. VTK support: NO
  53. Media I/O:
  54. ZLib: build (ver 1.2.11)
  55. JPEG: build-libjpeg-turbo (ver 2.0.6-62)
  56. WEBP: build (ver encoder: 0x020f)
  57. PNG: build (ver 1.6.37)
  58. TIFF: build (ver 42 - 4.2.0)
  59. JPEG 2000: build (ver 2.4.0)
  60. OpenEXR: build (ver 2.3.0)
  61. HDR: YES
  62. SUNRASTER: YES
  63. PXM: YES
  64. PFM: YES
  65. Video I/O:
  66. DC1394: NO
  67. FFMPEG: YES (prebuilt binaries)
  68. avcodec: YES (58.91.100)
  69. avformat: YES (58.45.100)
  70. avutil: YES (56.51.100)
  71. swscale: YES (5.7.100)
  72. avresample: YES (4.0.0)
  73. GStreamer: NO
  74. DirectShow: YES
  75. Parallel framework: Concurrency
  76. Trace: YES (with Intel ITT)
  77. Other third-party libraries:
  78. Lapack: NO
  79. Eigen: NO
  80. Custom HAL: NO
  81. Protobuf: build (3.5.1)
  82. NVIDIA CUDA: YES (ver 11.3, CUFFT CUBLAS)
  83. NVIDIA GPU arch: 35 37 50 52 60 61 70 75 80 86
  84. NVIDIA PTX archs:
  85. cuDNN: YES (ver 8.2.0)
  86. OpenCL: YES (NVD3D11)
  87. Include path: D:/360Downloads/opencv/sources/3rdparty/include/opencl/1.2
  88. Link libraries: Dynamic load
  89. ONNX: NO
  90. Python 3:
  91. Interpreter: D:/360Downloads/Anaconda3/python.exe (ver 3.8.8)
  92. Libraries: D:/360Downloads/Anaconda3/libs/python38.lib (ver 3.8.8)
  93. numpy: D:/360Downloads/Anaconda3/lib/site-packages/numpy/core/include (ver 1.20.1)
  94. install path: D:/360Downloads/Anaconda3/Lib/site-packages/cv2/python-3.8
  95. Python (for build): D:/360Downloads/Anaconda3/python.exe
  96. Java:
  97. ant: NO
  98. JNI: NO
  99. Java wrappers: NO
  100. Java tests: NO
  101. Install to: D:/360Downloads/opencv/build/x64/MinGw/install
  102. -----------------------------------------------------------------
  103. Configuring done

(4)生成的配置信息,并生成MakeFiles文件

  1. Detected processor: AMD64
  2. Could NOT find PythonInterp: Found unsuitable version "2.7.16", but required is at least "3.2" (found D:/Anaconda2/python.exe)
  3. Looking for ccache - not found
  4. AVX_512F is not supported by C++ compiler
  5. AVX512_COMMON is not supported by C++ compiler
  6. AVX512_SKX is not supported by C++ compiler
  7. Dispatch optimization AVX512_SKX is not available, skipped
  8. Cleaning INTERNAL cached variable: ZLIB_LIBRARY
  9. Cleaning INTERNAL cached variable: ZLIB_INCLUDE_DIR
  10. Found ZLIB: D:/Anaconda2/Library/lib/z.lib (found suitable version "1.2.11", minimum required is "1.2.3")
  11. libjpeg-turbo: VERSION = 2.0.6, BUILD = opencv-4.5.2-libjpeg-turbo
  12. Cleaning INTERNAL cached variable: TIFF_LIBRARY
  13. Cleaning INTERNAL cached variable: TIFF_INCLUDE_DIR
  14. Found TIFF: D:/Anaconda2/Library/lib/tiff.lib (found version "4.0.10")
  15. Cleaning INTERNAL cached variable: WEBP_LIBRARY
  16. Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
  17. Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
  18. OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.2-openjp2-2.4.0
  19. OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
  20. Cleaning INTERNAL cached variable: PNG_LIBRARY
  21. Cleaning INTERNAL cached variable: PNG_INCLUDE_DIR
  22. Found ZLIB: D:/Anaconda2/Library/lib/z.lib (found version "1.2.11")
  23. Found PNG: D:/Anaconda2/Library/lib/libpng.lib (found version "1.6.37")
  24. Looking for D:/Anaconda2/Library/include/libpng/png.h
  25. Looking for D:/Anaconda2/Library/include/libpng/png.h - not found
  26. Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
  27. Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
  28. Could NOT find BLAS (missing: BLAS_LIBRARIES)
  29. Could NOT find LAPACK (missing: LAPACK_LIBRARIES)
  30. Reason given by package: LAPACK could not be found because dependency BLAS could not be found.
  31. Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
  32. VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
  33. OpenCV Python: during development append to PYTHONPATH: D:/360Downloads/Software/opencv/build/x64/MinGw/python_loader
  34. Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
  35. Consider adding OPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int/int64_t according to your build configuration
  36. Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx512_skx.cpp
  37. Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx512_skx.cpp
  38. Excluding from source files list: <BUILD>/modules/core/test/test_intrin512.avx512_skx.cpp
  39. Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': D:/360Downloads/Software/opencv/sources/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
  40. opencv_dnn: filter out ocl4dnn source code
  41. opencv_dnn: filter out cuda4dnn source code
  42. Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
  43. Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
  44. OpenCL samples are skipped: OpenCL SDK is required
  45. SYCL/OpenCL samples are skipped: SYCL SDK is required
  46. - check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH
  47. - ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=D:/360Downloads/Software/MinGW/mingw64/bin/g++.exe
  48. CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  49. CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  50. directory
  51. Call Stack (most recent call first):
  52. CMakeLists.txt:1010 (include)
  53. General configuration for OpenCV 4.5.2 =====================================
  54. Version control: unknown
  55. Platform:
  56. Timestamp: 2021-04-09T02:59:22Z
  57. Host: Windows 10.0.18363 AMD64
  58. CMake: 3.20.1
  59. CMake generator: MinGW Makefiles
  60. CMake build tool: D:/360Downloads/Software/MinGW/mingw64/bin/mingw32-make.exe
  61. Configuration: Release
  62. CPU/HW features:
  63. Baseline: SSE SSE2 SSE3
  64. requested: SSE3
  65. Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2
  66. requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  67. SSE4_1 (17 files): + SSSE3 SSE4_1
  68. SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
  69. FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  70. AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  71. AVX2 (31 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  72. C/C++:
  73. Built as dynamic libs?: YES
  74. C++ standard: 11
  75. C++ Compiler: D:/360Downloads/Software/MinGW/mingw64/bin/g++.exe (ver 8.1.0)
  76. C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
  77. C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
  78. C Compiler: D:/360Downloads/Software/MinGW/mingw64/bin/gcc.exe
  79. C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
  80. C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
  81. Linker flags (Release): -Wl,--gc-sections
  82. Linker flags (Debug): -Wl,--gc-sections
  83. ccache: NO
  84. Precompiled headers: NO
  85. Extra dependencies:
  86. 3rdparty dependencies:
  87. OpenCV modules:
  88. To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
  89. Disabled: python2 world
  90. Disabled by dependency: -
  91. Unavailable: java python3
  92. Applications: tests perf_tests examples apps
  93. Documentation: NO
  94. Non-free algorithms: NO
  95. Windows RT support: NO
  96. GUI:
  97. Win32 UI: YES
  98. VTK support: NO
  99. Media I/O:
  100. ZLib: D:/Anaconda2/Library/lib/z.lib (ver 1.2.11)
  101. JPEG: build-libjpeg-turbo (ver 2.0.6-62)
  102. WEBP: build (ver encoder: 0x020f)
  103. PNG: D:/Anaconda2/Library/lib/libpng.lib (ver 1.6.37)
  104. TIFF: D:/Anaconda2/Library/lib/tiff.lib (ver 42 / 4.0.10)
  105. JPEG 2000: build (ver 2.4.0)
  106. OpenEXR: build (ver 2.3.0)
  107. HDR: YES
  108. SUNRASTER: YES
  109. PXM: YES
  110. PFM: YES
  111. Video I/O:
  112. DC1394: NO
  113. FFMPEG: YES (prebuilt binaries)
  114. avcodec: YES (58.91.100)
  115. avformat: YES (58.45.100)
  116. avutil: YES (56.51.100)
  117. swscale: YES (5.7.100)
  118. avresample: YES (4.0.0)
  119. GStreamer: NO
  120. DirectShow: YES
  121. Parallel framework: none
  122. Trace: YES (with Intel ITT)
  123. Other third-party libraries:
  124. Lapack: NO
  125. Eigen: NO
  126. Custom HAL: NO
  127. Protobuf: build (3.5.1)
  128. OpenCL: YES (no extra features)
  129. Include path: D:/360Downloads/Software/opencv/sources/3rdparty/include/opencl/1.2
  130. Link libraries: Dynamic load
  131. Python (for build): D:/Anaconda2/python.exe
  132. Java:
  133. ant: NO
  134. JNI: NO
  135. Java wrappers: NO
  136. Java tests: NO
  137. Install to: D:/360Downloads/Software/opencv/build/x64/MinGw/install
  138. -----------------------------------------------------------------
  139. Configuring done
  140. Generating done

5. 编译OpenCV
进入MakeFiles所在文件夹

>>> cd  D:\360Downloads\opencv\build\x64\MinGw

使用多线程编译,编译时间5-10分钟,根据电脑性能有差异

>>> minGW32-make -j 8

6. 安装OpenCV

minGW32-make install

D:/360Downloads/Software/opencv/build/x64/MinGw/install/x64/mingw/bin 目录下有两个dll文件:  

libopencv_world452.dll
opencv_videoio_ffmpeg452_64.dll

7. 测试OpenCV是否安装成功 

findContours_demo.cpp

  1. /**
  2. * @function findContours_Demo.cpp
  3. * @brief Demo code to find contours in an image
  4. * @author OpenCV team
  5. */
  6. #include "opencv2/imgcodecs.hpp"
  7. #include "opencv2/highgui.hpp"
  8. #include "opencv2/imgproc.hpp"
  9. #include <iostream>
  10. using namespace cv;
  11. using namespace std;
  12. Mat src_gray;
  13. int thresh = 100;
  14. RNG rng(12345);
  15. /// Function header
  16. void thresh_callback(int, void* );
  17. /**
  18. * @function main
  19. */
  20. int main( int argc, char** argv )
  21. {
  22. /// Load source image
  23. CommandLineParser parser( argc, argv, "{@input | HappyFish.jpg | input image}" );
  24. Mat src = imread( samples::findFile( parser.get<String>( "@input" ) ) );
  25. if( src.empty() )
  26. {
  27. cout << "Could not open or find the image!\n" << endl;
  28. cout << "Usage: " << argv[0] << " <Input image>" << endl;
  29. return -1;
  30. }
  31. /// Convert image to gray and blur it
  32. cvtColor( src, src_gray, COLOR_BGR2GRAY );
  33. blur( src_gray, src_gray, Size(3,3) );
  34. /// Create Window
  35. const char* source_window = "Source";
  36. namedWindow( source_window );
  37. imshow( source_window, src );
  38. const int max_thresh = 255;
  39. createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
  40. thresh_callback( 0, 0 );
  41. waitKey();
  42. return 0;
  43. }
  44. /**
  45. * @function thresh_callback
  46. */
  47. void thresh_callback(int, void* )
  48. {
  49. /// Detect edges using Canny
  50. Mat canny_output;
  51. Canny( src_gray, canny_output, thresh, thresh*2 );
  52. /// Find contours
  53. vector<vector<Point> > contours;
  54. vector<Vec4i> hierarchy;
  55. findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE );
  56. /// Draw contours
  57. Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
  58. for( size_t i = 0; i< contours.size(); i++ )
  59. {
  60. Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
  61. drawContours( drawing, contours, (int)i, color, 2, LINE_8, hierarchy, 0 );
  62. }
  63. /// Show in a window
  64. imshow( "Contours", drawing );
  65. }

三、注意事项

(1)在操作cmake-gui前,如果没有翻过墙的话,在C:\Windows\System32\drivers\etc\hosts文件最后追加:

151.101.72.133 raw.githubusercontent.com

因为cmake-gui会下载一些文件,这些文件都在raw.githubusercontent.com上,如果不修改一下hosts,许多文件很可能会下载失败

四、可能存在的问题

(1)编译OpenCV出现错误

如果报错可查阅下面的网址帮助:

https://blog.huihut.com/2018/07/31/CompiledOpenCVWithMinGW64/

一般问题都是可以通过 勾选 和 去勾选 解决的,重新Configure,重新编译即可。

错误原因:
在配置MinGw信息的时候,勾选信息错误


解决办法:

参考上文步骤4,第(3)勾选配置

(2)找不到libopencv_core452

错误原因:

没有把编译好的OpenCV添加到环境变量中


解决办法:

添加环境变量
D:\360Downloads\Software\opencv\build\x64\MinGw\bin

(3)无法找到入口
无法定位程序输入点_ZNSt6thread15_M_start_threadESt10unique_ptrINS_6_StateESt14default_deleteIS1_EEPFvvE

huihut/OpenCV-MinGW-Build
https://github.com/huihut/OpenCV-MinGW-Build/issues/18

错误原因:
anaconda 中的 LIBSTDC++-6.DLL 与 MinGW64 的LIBSTDC++-6.DLL 冲突所导致的,在配置环境变量时将 MinGW64 的 bin 路径移到高于 anaconda 的 mingw-w64/bin 路径更高优先级的位置就可以了

解决办法:

(4)CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
FFMPEG: Download failed: 6;"Couldn't resolve host name"
错误原因:下载ffmpeg失败,需要翻墙
解决办法:见上文【三、注意事项】

(5)如果opencv编译失败,删除目录 D:\360Downloads\Software\opencv\build\x64\MinGw 里的所有文件,重头开始

(6)gcc: error: long: No such file or directory

参考资料:
使用CMake+Qt自带的MinGW编译OpenCV
gcc: error: long: No such file or directory

错误原因:在CMake的configure配置文件勾选中,勾选错误
解决办法:

  1. 在CMake中找到OPENCV_ENABLE_ALLOCATOR_STATS这项,取消勾选
  2. 重新Configure,重新Generate
  3. 重新mingw32-make编译

(7)ImportError: DLL load failed while importing cv2

 参考资料:

opencv cuda加速编译后调用python接口后报错ImportError: DLL load failed while importing cv2记录

错误原因:在CMake源码安装了C++版本的Opencv,但没有安装python版本的Opencv
解决办法:

  1. >>> cd PATH\TO\python_loader
  2. >>> python setup.py install # 安装python版本的Opencv

(8)recursion is detected during loading of cv2 binary extensions

(9)在vs2015中配置Opencv,无法找到源文件"opencv2/opencv.hpp" 

参考资料:在vs2015中配置Opencv,无法找到源文件"opencv2/opencv.hpp"
解决办法:VS2019中x86改为x64

五、其他

(1)opencv 和opencv_contrib配置
参考博客 【Windows版】opencv 和opencv_contrib配置

(2)修改python版本

在cmake-gui中修改

(3)ubuntu编译OpenCV

从源码安装OpenCV,使用python

(4)用Visual studio编译OpenCV

Windows下 Cmake + VS 编译 OpenCV (+ opencv_contribute)源码

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/119849
推荐阅读
相关标签
  

闽ICP备14008679号