mingw下编译opencv4.5.2

初衷:

加载之前的模型没问题,但最近加载另一个模型时出现报错:

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.1.0) Error: Assertion failed (nodesMapIt != nodesMap.end()) in sortByExecutionOrder, file G:/MXCwork/2019/opencv4.1.0/opencv-4.1.0/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp, line 860

在ubuntu上试过4.5.2加载模型没问题,于是重新编译mingw32的opencv4.5.2,配置如下:

mingw:4.9.2_32bit,同时设置好环境变量G:\QT\qt\Tools\MinGW_4.9.2\MinGW\bin

系统:windows10

opencv:4.5.2

一、github下载opencv源码

在源码中新建将build的文件夹如下:

注意contrib也要下对应版本https://github.com/opencv/opencv_contrib

二、打开cmake-gui

然后选择generator是MingW Makefiles,然后specify native compilers的C和C++处分别填写G:\QT\qt\Tools\MinGW_4.9.2\MinGW\bin\gcc.exe 以及G:\QT\qt\Tools\MinGW_4.9.2\MinGW\bin\g++.exe然后点击configure

三、手动下载必须的包

在第一次configure过程中可能有红色报错,不用在意。第一遍configure结束后按自己的需求取消或增加勾选项,比如我不用OpenCL我就将相关的全部取消,我还取消了OPENCV_GENERATE_SETUPVARS,并填写:

 然后开始第二次configure,在这个过程中要关注输出,当出现红色报错,如下应立刻将https://download.csdn.net/download/wd1603926823/88651377 的包拷贝或替换到opencv4.5.2下的.cache文件夹下的对应文件夹下,此时你替换时应该也看到系统正在下载同名的文件,但因网络问题很可能下载不全,所以建议直接全部替换:

接着开始第三次configure,此时我的只报了下图一个错,但我忽略了:

最后generate 

Detected processor: AMD64
sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode
libjpeg-turbo: VERSION = 2.0.6, BUILD = opencv-4.5.2-libjpeg-turbo
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.2-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find BLAS (missing: BLAS_LIBRARIES) 
Could NOT find LAPACK (missing: LAPACK_LIBRARIES) Reason given by package: LAPACK could not be found because dependency BLAS could not be found.VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: G:/workspace/opencv-4.5.2/mingw4.9.2_32bit_build/python_loader
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
freetype2:   NO
harfbuzz:    NO
Julia not found. Not compiling Julia Bindings. 
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Tesseract:   NO
Processing WORLD modules...module opencv_core...
Consider adding OPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int/int64_t according to your build configurationmodule opencv_flann...module opencv_imgproc...module opencv_intensity_transform...module opencv_ml...module opencv_phase_unwrapping...module opencv_photo...module opencv_plot...module opencv_quality...module opencv_reg...module opencv_surface_matching...module opencv_xphoto...module opencv_dnn...
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': G:/workspace/opencv-4.5.2/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
opencv_dnn: filter out ocl4dnn source code
opencv_dnn: filter out cuda4dnn source codemodule opencv_dnn_superres...module opencv_features2d...module opencv_fuzzy...module opencv_hfs...module opencv_imgcodecs...module opencv_line_descriptor...module opencv_saliency...module opencv_text...module opencv_videoio...module opencv_calib3d...module opencv_datasets...module opencv_highgui...module opencv_mcc...module opencv_objdetect...module opencv_rapid...module opencv_rgbd...
rgbd: Eigen support is disabled. Eigen is Required for Posegraph optimizationmodule opencv_shape...module opencv_structured_light...module opencv_video...module opencv_videostab...module opencv_wechat_qrcode...module opencv_xfeatures2d...
xfeatures2d/boostdesc: Download: boostdesc_bgm.i
xfeatures2d/boostdesc: Download: boostdesc_bgm_bi.i
xfeatures2d/vgg: Download: vgg_generated_48.imodule opencv_ximgproc...module opencv_xobjdetect...module opencv_aruco...module opencv_bgsegm...module opencv_bioinspired...module opencv_ccalib...module opencv_dnn_objdetect...module opencv_dpm...module opencv_face...
data: Download: face_landmark_model.datmodule opencv_gapi...module opencv_optflow...module opencv_stitching...module opencv_superres...module opencv_tracking...module opencv_stereo...
Processing WORLD modules... DONE
Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.avx2.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.avx512_skx.cpp
Excluding from source files list: modules/features2d/src/fast.avx2.cpp
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):CONFIGURATION IS NOT SUPPORTED: validate setupvars script in installdirectory
Call Stack (most recent call first):CMakeLists.txt:1010 (include)General configuration for OpenCV 4.5.2 =====================================Version control:               unknownExtra modules:Location (extra):            G:/workspace/opencv-4.5.2/opencv_contrib-4.x/modulesVersion control (extra):     unknownPlatform:Timestamp:                   2023-12-21T03:10:16ZHost:                        Windows 10.0.18363 AMD64CMake:                       3.24.2CMake generator:             MinGW MakefilesCMake build tool:            G:/QT/qt/Tools/MinGW_4.9.2/MinGW/bin/mingw32-make.exeConfiguration:               ReleaseCPU/HW features:Baseline:                    SSE SSE2requested:                 SSE2Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVXrequested:                 SSE4_1 SSE4_2 AVX FP16SSE4_1 (15 files):         + SSE3 SSSE3 SSE4_1SSE4_2 (1 files):          + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2FP16 (0 files):            + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVXAVX (4 files):             + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVXC/C++:Built as dynamic libs?:      YESC++ standard:                11C++ Compiler:                G:/QT/qt/Tools/MinGW_4.9.2/MinGW/bin/g++.exe  (ver 4.9.2)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 -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -mfpmath=sse -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUGC++ 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 -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -mfpmath=sse -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUGC Compiler:                  G:/QT/qt/Tools/MinGW_4.9.2/MinGW/bin/gcc.exeC 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 -Wuninitialized -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -mfpmath=sse -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUGC 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 -Wuninitialized -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -mfpmath=sse -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUGLinker flags (Release):      -Wl,--gc-sections  Linker flags (Debug):        -Wl,--gc-sections  ccache:                      NOPrecompiled headers:         NOExtra dependencies:3rdparty dependencies:OpenCV modules:To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi 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 world xfeatures2d ximgproc xobjdetect xphotoDisabled:                    -Disabled by dependency:      -Unavailable:                 alphamat cannops cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python2 sfm vizApplications:                appsDocumentation:               NONon-free algorithms:         NOWindows RT support:            NOGUI: Win32 UI:                    YESVTK support:                 NOMedia I/O: ZLib:                        build (ver 1.2.11)JPEG:                        build-libjpeg-turbo (ver 2.0.6-62)WEBP:                        build (ver encoder: 0x020f)PNG:                         build (ver 1.6.37)TIFF:                        build (ver 42 - 4.2.0)JPEG 2000:                   build (ver 2.4.0)OpenEXR:                     build (ver 2.3.0)HDR:                         YESSUNRASTER:                   YESPXM:                         YESPFM:                         YESVideo I/O:DC1394:                      NOFFMPEG:                      YES (prebuilt binaries)avcodec:                   YES (58.91.100)avformat:                  YES (58.45.100)avutil:                    YES (56.51.100)swscale:                   YES (5.7.100)avresample:                YES (4.0.0)GStreamer:                   NODirectShow:                  NOParallel framework:            noneTrace:                         YES (built-in)Other third-party libraries:Lapack:                      NOEigen:                       NOCustom HAL:                  NOProtobuf:                    build (3.5.1)Python 3:Interpreter:                 F:/windows_wd/AI/python/py/python.exe (ver 3.6.7)Libraries:                   F:/windows_wd/AI/python/py/libs/libpython36.a (ver 3.6.7)numpy:                       F:/windows_wd/AI/python/py/lib/site-packages/numpy/core/include (ver 1.19.5)install path:                F:/windows_wd/AI/python/py/Lib/site-packages/cv2/python-3.6Python (for build):            F:/windows_wd/AI/python/py/python.exeJava:                          ant:                         NOJNI:                         G:/QT/jdk/include G:/QT/jdk/include/win32 G:/QT/jdk/includeJava wrappers:               NOJava tests:                  NOInstall to:                    G:/workspace/opencv-4.5.2/mingw4.9.2_32bit_build/install
-----------------------------------------------------------------Configuring done
Generating done

 然后关闭cmake-gui!

四、开始编译

cmd或git-bash下进入G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build里,输入mingw32-make

1、ade出现下面的报错:

[  2%] Built target libopenjp2
[  2%] Built target opencv_videoio_plugins
[  2%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.obj
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp: In function 'void* ade::aligned_alloc(std::size_t, std::size_t)':
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp:26:43: error: '_aligned_malloc' was not declared in this scopereturn _aligned_malloc(size, alignment);^
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp: In function 'void ade::aligned_free(void*)':
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp:40:29: error: '_aligned_free' was not declared in this scopereturn _aligned_free(ptr);^
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp:40:29: error: return-statement with a value, in function returning 'void' [-fpermissive]
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp: In function 'void* ade::aligned_alloc(std::size_t, std::size_t)':
G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build\3rdparty\ade\ade-0.1.1f\sources\ade\source\alloc.cpp:35:1: error: control reaches end of non-void function [-Werror=return-type]}^
cc1plus.exe: some warnings being treated as errors
modules\CMakeFiles\ade.dir\build.make:75: recipe for target 'modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.obj' failed
mingw32-make[2]: *** [modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.obj] Error 1
CMakeFiles\Makefile2:2472: recipe for target 'modules/CMakeFiles/ade.dir/all' failed
mingw32-make[1]: *** [modules/CMakeFiles/ade.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

解决办法:打开cmake-gui,这时默认就是我们之前勾选的界面,取消掉与ade有关的东西,最好不用的东西都取消掉。然后configure再generate,然后关闭cmake-gui。最后进入G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build 依旧输入mingw32-make

2,io_win32出现如下报错:

[  2%] Built target libopenjp2
[  2%] Built target opencv_videoio_plugins
[  3%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj
G:\workspace\opencv-4.5.2\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function 'FILE* google::protobuf::internal::win32::fopen(const char*, const char*)':
G:\workspace\opencv-4.5.2\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:330:10: error: '::_wfopen' has not been declaredreturn ::_wfopen(wpath.c_str(), wmode.c_str());^
G:\workspace\opencv-4.5.2\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:334:1: error: control reaches end of non-void function [-Werror=return-type]}^
cc1plus.exe: some warnings being treated as errors
3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:285: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj' failed
mingw32-make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj] Error 1
CMakeFiles\Makefile2:2375: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all' failed
mingw32-make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

 参考c++ - OpenCV : io_win32.cc : _wfopen has not been declared MinGW - Stack Overflow,我是修改G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build中的CMakeCache.txt,查找CMAKE_CXX_FLAGS,然後把CMAKE_CXX_FLAGS:STRING的值修改爲-U__STRICT_ANSI__
如下图:

 然后直接重新mingw32-make

3,webp出现报错如下:

[ 14%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/utils/thread_utils.c.obj
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c:29:9: error: unknown type name 'CONDITION_VARIABLE'typedef CONDITION_VARIABLE pthread_cond_t;^
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c: In function 'pthread_mutex_init':
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c:108:3: warning: implicit declaration of function 'InitializeCriticalSectionEx' [-Wimplicit-function-declaration]InitializeCriticalSectionEx(mutex, 0 /*dwSpinCount*/, 0 /*Flags*/);^
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c: In function 'pthread_cond_init':
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c:146:3: warning: implicit declaration of function 'InitializeConditionVariable' [-Wimplicit-function-declaration]InitializeConditionVariable(condition);^
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c: In function 'pthread_cond_signal':
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c:164:3: warning: implicit declaration of function 'WakeConditionVariable' [-Wimplicit-function-declaration]WakeConditionVariable(condition);^
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c: In function 'pthread_cond_wait':
G:\workspace\opencv-4.5.2\3rdparty\libwebp\src\utils\thread_utils.c:182:3: warning: implicit declaration of function 'SleepConditionVariableCS' [-Wimplicit-function-declaration]ok = SleepConditionVariableCS(condition, mutex, INFINITE);^
3rdparty\libwebp\CMakeFiles\libwebp.dir\build.make:1755: recipe for target '3rdparty/libwebp/CMakeFiles/libwebp.dir/src/utils/thread_utils.c.obj' failed
mingw32-make[2]: *** [3rdparty/libwebp/CMakeFiles/libwebp.dir/src/utils/thread_utils.c.obj] Error 1
CMakeFiles\Makefile2:2297: recipe for target '3rdparty/libwebp/CMakeFiles/libwebp.dir/all' failed
mingw32-make[1]: *** [3rdparty/libwebp/CMakeFiles/libwebp.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

 打开cmake-gui,这是上次的默认界面,直接取消webp相关的东西,即取消 BUILD_WEBP WITH_WEBP,(然后configure再generate,然后关闭cmake-gui,最后进入G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build 依旧输入mingw32-make ,这一段话我后面不再赘述,记住反正每次编译报错时,来取消某些选项后,都得这样做)

4,fibersapi出现报错:

[ 26%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/core/src/mathfuncs_core.dispatch.cpp.obj
[ 26%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/core/src/matmul.dispatch.cpp.obj
[ 26%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/core/src/matrix.cpp.obj
In file included from G:/workspace/opencv-4.5.2/modules/core/include/opencv2/core.hpp:53:0,from G:/workspace/opencv-4.5.2/modules/core/include/opencv2/core/utility.hpp:56,from G:\workspace\opencv-4.5.2\modules\core\src\precomp.hpp:53,from G:\workspace\opencv-4.5.2\modules\core\src\matrix.cpp:5:
G:\workspace\opencv-4.5.2\modules\core\src\matrix.cpp: In function 'void cv::setSize(cv::Mat&, int, const int*, const size_t*, bool)':
G:\workspace\opencv-4.5.2\modules\core\src\matrix.cpp:259:126: warning: unknown conversion type character 'z' in format [-Wformat=]CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1));^
G:/workspace/opencv-4.5.2/modules/core/include/opencv2/core/base.hpp:334:61: note: in definition of macro 'CV_Error_'#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )^
G:\workspace\opencv-4.5.2\modules\core\src\matrix.cpp:259:126: warning: unknown conversion type character 'z' in format [-Wformat=]CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1));^
G:/workspace/opencv-4.5.2/modules/core/include/opencv2/core/base.hpp:334:61: note: in definition of macro 'CV_Error_'#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )^
G:\workspace\opencv-4.5.2\modules\core\src\matrix.cpp:259:126: warning: too many arguments for format [-Wformat-extra-args]CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1));^
G:/workspace/opencv-4.5.2/modules/core/include/opencv2/core/base.hpp:334:61: note: in definition of macro 'CV_Error_'#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )G:\workspace\opencv-4.5.2\modules\core\src\system.cpp:153:25: fatal error: fibersapi.h: No such file or directory#include <fibersapi.h>^
compilation terminated.
modules\world\CMakeFiles\opencv_world.dir\build.make:1388: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/__/core/src/system.cpp.obj' failed
mingw32-make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/__/core/src/system.cpp.obj] Error 1
CMakeFiles\Makefile2:2361: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/all' failed
mingw32-make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

 在我的opencv-4.5.2下的cmakelist.txt中第153行即

#if ((_WIN32_WINNT >= 0x0600) && !defined(CV_DISABLE_FLS)) || defined(CV_FORCE_FLS)#include <fibersapi.h>#define CV_USE_FLS

在这三行的上面加上:

//add here
#define CV_DISABLE_FLS

即不让它进去,就不会报错了。然后重新打开cmake-gui进行configure和generate ,再关闭cmake-gui,接着继续mingw32-make

5,xphoto报错如下:

[ 32%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/xphoto/src/bm3d_image_denoising.cpp.obj
[ 32%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/xphoto/src/dct_image_denoising.cpp.obj
[ 32%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/xphoto/src/grayworld_white_balance.cpp.obj
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp: In function 'void cv::xphoto::calculateChannelSums(uint&, uint&, uint&, uchar*, int, float)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:133:58: error: 'v_sub' was not declared in this scopev_m1 = v_not(v_gt(v_mul_wrap(v_sub(v_max1, v_min1), v_255), v_mul_wrap(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:133:97: error: 'v_gt' was not declared in this scopev_m1 = v_not(v_gt(v_mul_wrap(v_sub(v_max1, v_min1), v_255), v_mul_wrap(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:133:98: error: 'v_not' was not declared in this scopev_m1 = v_not(v_gt(v_mul_wrap(v_sub(v_max1, v_min1), v_255), v_mul_wrap(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:137:40: error: 'v_and' was not declared in this scopev_iB1 = v_add(v_and(v_iB1, v_m1), v_and(v_iB2, v_m2));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:137:61: error: 'v_add' was not declared in this scopev_iB1 = v_add(v_and(v_iB1, v_m1), v_and(v_iB2, v_m2));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp: In function 'void cv::xphoto::calculateChannelSums(uint64&, uint64&, uint64&, ushort*, int, float)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:200:53: error: 'v_sub' was not declared in this scopev_m1 = v_not(v_gt(v_mul(v_sub(v_max1, v_min1), v_65535), v_mul(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:200:63: error: 'v_mul' was not declared in this scopev_m1 = v_not(v_gt(v_mul(v_sub(v_max1, v_min1), v_65535), v_mul(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:200:89: error: 'v_gt' was not declared in this scopev_m1 = v_not(v_gt(v_mul(v_sub(v_max1, v_min1), v_65535), v_mul(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:200:90: error: 'v_not' was not declared in this scopev_m1 = v_not(v_gt(v_mul(v_sub(v_max1, v_min1), v_65535), v_mul(v_thresh, v_max1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:204:40: error: 'v_and' was not declared in this scopev_iB1 = v_add(v_and(v_iB1, v_m1), v_and(v_iB2, v_m2));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:204:61: error: 'v_add' was not declared in this scopev_iB1 = v_add(v_and(v_iB1, v_m1), v_and(v_iB2, v_m2));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp: In function 'void cv::xphoto::applyChannelGains(cv::InputArray, cv::OutputArray, float, float, float)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\xphoto\src\grayworld_white_balance.cpp:285:56: error: no matching function for call to 'v_shr(cv::hal_baseline::v_uint16x8, int)'v_sB1 = v_shr(v_mul_wrap(v_sB1, v_gainB), 8);

取消BUILD_opencv_xphoto 然后重新打开cmake-gui进行configure和generate,接着依旧mingw32-make

6,rgbd报错

[ 65%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/rapid/src/histogram.cpp.obj
[ 65%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/rapid/src/rapid.cpp.obj
[ 65%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/rgbd/src/colored_kinfu.cpp.obj
In file included from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\kinfu_frame.hpp:11:0,from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\fast_icp.hpp:11,from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\colored_kinfu.cpp:8:
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\utils.hpp: In function 'bool cv::kinfu::isNaN(const cv::hal_baseline::v_float32x4&)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\utils.hpp:71:37: error: 'v_ne' was not declared in this scopereturn cv::v_check_any(v_ne(p, p));^
In file included from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\hash_tsdf.hpp:12:0,from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\colored_kinfu.cpp:10:
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\tsdf_functions.hpp: In function 'cv::hal_baseline::v_float32x4 cv::kinfu::tsdfToFloat_INTR(const cv::hal_baseline::v_int32x4&)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\rgbd\src\tsdf_functions.hpp:23:40: error: 'v_mul' was not declared in this scopereturn v_mul(v_cvt_f32(num), num128);^
modules\world\CMakeFiles\opencv_world.dir\build.make:7568: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/rgbd/src/colored_kinfu.cpp.obj' failed
mingw32-make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/rgbd/src/colored_kinfu.cpp.obj] Error 1
CMakeFiles\Makefile2:2361: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/all' failed
mingw32-make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

 取消BUILD_opencv_rgbd,然后执行那句不想赘述的话。

7,ximgproc报错

[ 78%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/xfeatures2d/src/vgg.cpp.obj
[ 78%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/xfeatures2d/src/xfeatures2d_init.cpp.obj
[ 78%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/opencl_kernels_xfeatures2d.cpp.obj
[ 78%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/ximgproc/src/adaptive_manifold_filter_n.cpp.obj
[ 78%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/ximgproc/src/anisodiff.cpp.obj
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp: In function 'cv::hal_baseline::v_uint8x16 cv::ximgproc::v_finalize_pix_ch(const cv::hal_baseline::v_int16x8&, const cv::hal_baseline::v_int16x8&, const cv::hal_baseline::v_float32x4&, const cv::hal_baseline::v_float32x4&, const cv::hal_baseline::v_float32x4&, const cv::hal_baseline::v_float32x4&, const cv::hal_baseline::v_float32x4&)':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:77:56: error: 'v_mul' was not declared in this scopev_int16x8 d0 = v_pack(v_round(v_add(v_mul(s0, alpha), f0)), v_round(v_add(v_mul(s1, alpha), f1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:77:61: error: 'v_add' was not declared in this scopev_int16x8 d0 = v_pack(v_round(v_add(v_mul(s0, alpha), f0)), v_round(v_add(v_mul(s1, alpha), f1)));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp: In member function 'virtual void cv::ximgproc::ADBody::operator()(const cv::Range&) const':
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:138:51: error: 'v_sub' was not declared in this scopev_int16x8 d00 = v_sub(p00, c00), d01 = v_sub(p01, c01);^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:142:71: error: 'v_add' was not declared in this scopev_uint16x8 n0 = v_add(v_add(v_abs(d00), v_abs(d10)), v_abs(d20));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:142:84: error: 'v_add' was not declared in this scopev_uint16x8 n0 = v_add(v_add(v_abs(d00), v_abs(d10)), v_abs(d20));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:142:84: error: redeclaration of '<typeprefixerror>v_add'
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:142:71: note: previous declaration '<typeprefixerror>v_add'v_uint16x8 n0 = v_add(v_add(v_abs(d00), v_abs(d10)), v_abs(d20));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:143:55: error: 'd01' was not declared in this scopev_uint16x8 n1 = v_add(v_add(v_abs(d01), v_abs(d11)), v_abs(d21));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:143:67: error: 'd11' was not declared in this scopev_uint16x8 n1 = v_add(v_add(v_abs(d01), v_abs(d11)), v_abs(d21));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:143:80: error: 'd21' was not declared in this scopev_uint16x8 n1 = v_add(v_add(v_abs(d01), v_abs(d11)), v_abs(d21));^
G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\ximgproc\src\anisodiff.cpp:156:51: error: 'v_mul' was not declared in this scopes00 = v_add(s00, v_mul(fd0, w0)); s01 = v_add(s01, v_mul(fd1, w1)); s02 = v_add(s02, v_mul(fd2, w2)); s03 = v_add(s03, v_mul(fd3, w3));^
modules\world\CMakeFiles\opencv_world.dir\build.make:9509: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/ximgproc/src/anisodiff.cpp.obj' failed
mingw32-make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/ximgproc/src/anisodiff.cpp.obj] Error 1
CMakeFiles\Makefile2:2361: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/all' failed
mingw32-make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

 取消BUILD_opencv_ximgproc,然后依旧执行那句不想赘述的话

8,aruco报错

[ 82%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/__/opencv_contrib-4.x/modules/aruco/src/aruco.cpp.obj
In file included from G:\workspace\opencv-4.5.2\opencv_contrib-4.x\modules\aruco\src\aruco.cpp:6:0:
G:/workspace/opencv-4.5.2/opencv_contrib-4.x/modules/aruco/include/opencv2/aruco.hpp:7:48: fatal error: opencv2/objdetect/aruco_detector.hpp: No such file or directory#include "opencv2/objdetect/aruco_detector.hpp"^
compilation terminated.

取消BUILD_opencv_aruco ,执行那句话

9,python_bindings报错

[ 98%] Built target gen_opencv_python_source
[ 98%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.obj
In file included from G:\workspace\opencv-4.5.2\modules\python\src2\cv2.cpp:41:0:
G:/workspace/opencv-4.5.2/mingw4.9.2_32bit_build/modules/python_bindings_generator/pyopencv_generated_include.h:48:51: fatal error: opencv2/xphoto/bm3d_image_denoising.hpp: No such file or directory#include "opencv2/xphoto/bm3d_image_denoising.hpp"^
compilation terminated.
modules\python3\CMakeFiles\opencv_python3.dir\build.make:75: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.obj' failed
mingw32-make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.obj] Error 1
CMakeFiles\Makefile2:2572: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
mingw32-make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

取消BUILD_python_bindings_generator,依旧执行那句话。

这次终于不再报错,顺利编译完毕,如下图所示:

然后mingw32-make install也很顺利:

 在G:\workspace\opencv-4.5.2\mingw4.9.2_32bit_build下生成了install文件夹,直接拷贝出去就可以使用这个第三方库了。

五、应用问题

我发现install下的库竟然是x64,不应该是x86吗?仪器32bit的库都是x86的命名,然后我抱着将信将疑的态度试了下这个新的库,发现无论我用ming32位或ming64位工程中都会报错!

我又试着用cmd重新mingw32-make以及mingw32-make install,依旧有问题。

然后我又试了windows powershell,还是一样有问题。

经过反思,发现问题出在我的编译器上,如下图我的git-bash打开默认是MING64,所以我cmake时是用的mingw32的gcc,但mingw32-make以及ming32-make install时实际使用的是mingw64!!!不伦不类,所以编译出来的库应用时会报错:

 所以我实际应该在MINGW32的这个命名行下进行编译。于是我重新卸载了我的git,重新Downloading Git for Windows 2.37.3 (32-bit) from FileHorse.com安装git-32bit,默认方式安装即可。然后重新mingw32-make以及mingw32-make install

 然后将新生成的install文件改名为opencv4.5.2_mingw32 将bin和lib添加到环境变量,然后就可以应用了。不再报错:

 

 六、编译完毕的包

至此,历经这些后,应该无论32位还是64位,无论哪个版本的都能自己编译了。遇到问题不可怕,分析问题原因,尝试解决办法。我觉得可怕的是报的错与解决方式完全没有关联,不方便寻根溯源去解决且无论怎么搜索,没有一个网友遇到过,才是最烦人的。

将编译完毕的opencv4.2.0_64bit_mingw4.9.2 、 opencv4.5.2_32bit_mingw4.9.2我也上传在了 https://download.csdn.net/download/wd1603926823/88651377

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/295578.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Vue和jQuery:横向对比

聚沙成塔每天进步一点点 ⭐ 专栏简介 Vue学习之旅的奇妙世界 欢迎大家来到 Vue 技能树参考资料专栏!创建这个专栏的初衷是为了帮助大家更好地应对 Vue.js 技能树的学习。每篇文章都致力于提供清晰、深入的参考资料,让你能够更轻松、更自信地理解和掌握 Vue.js 的核心概念和技…

java并发编程三 共享内存的问题和synchronized解决方案

文章目录 共享带来的问题synchronized 解决方案方法上的 synchronized 共享带来的问题 小故事 老王&#xff08;操作系统&#xff09;有一个功能强大的算盘&#xff08;CPU&#xff09;&#xff0c;现在想把它租出去&#xff0c;赚一点外快 小南、小女&#xff08;线程&…

数字人解决方案——ER-NeRF实时对话数字人模型推理部署带UI交互界面

简介 这个是一个使用ER-NeRF来实现实时对话数字人、口播数字人的整体架构&#xff0c;其中包括了大语言回答模型、语音合成、成生视频流、背景替换等功能&#xff0c;项目对显存的要求很高&#xff0c;想要达到实时推理的效果&#xff0c;建议显存在24G以上。 实时对话数字人 …

CycleGAN-两个领域非匹配图像的相互转换

1. CycleGAN的简介 pix2pix可以很好地处理匹配数据集图像转换&#xff0c;但是在很多情况下匹配数据集是没有的或者是很难收集到的&#xff0c;但是我们可以很容易的得到两个领域大量的非匹配数据。2017年有两篇非常相似的论文CycleGAN和DiscoGAN&#xff0c;提出了一种解决非匹…

初识Docker-什么是docker

Docker是一个快速交付应用、运行应用的技术 目录 一、Docker 二、运用场景 一、什么是Docker&#xff1f;它的作用是什么&#xff1f; Docker如何解决大型项目依赖关系复杂&#xff0c;不同组件依赖的兼容性问题? Docker允许开发中将应用、依赖、函数库、配置一起打包&…

旅游海报图怎么做二维码展示?扫码即可查看图片

现在旅游攻略的海报可以做成二维码印刷在宣传单单页或者分享给用户来了解目的地的实际情况&#xff0c;出行路线、宣传海报等。用户只需要扫描二维码就可以查看内容&#xff0c;更加的方便省劲&#xff0c;那么旅游海报的图片二维码制作的技巧有哪些呢&#xff1f;使用图片二维…

【Flutter】黑白图片

一、将图片处理成黑白图片 //第一种方法CachedNetworkImage(imageUrl: imageUrl,width: 80,height: 80,fit: BoxFit.cover,color: Colors.black,//目标颜色colorBlendMode: BlendMode.color,//颜色混合模式)//第二种方法ShaderMask(shaderCallback: (Rect bounds) {return Lin…

【shell脚本实战学习笔记】#1

shell脚本实战学习笔记#1 脚本编写场景需求&#xff1a; 编写一个比较数据大小的shell脚本&#xff0c;要求判断用户只能输入两位数字&#xff0c;不能是字符或其他特殊字符&#xff1b;并且在shell脚本中需要用到函数来控制执行顺序。 知识点&#xff1a;shell函数&#xff…

ros2humble使用gazebo加载urdf文件的基本流程

1&#xff1a;编写xacro文件 2&#xff1a;把xacro文件转换为urdf文件 3&#xff1a;使用gazebo建立sdf文件fine&#xff0c;也就是ros1里面的world文件&#xff0c;现在后缀是sdf文件了 4&#xff1a;把urdf文件转换为sdf文件good 5&#xff1a;把修改后的good.sdf文件稍微…

swing快速入门(二十五)

注释很详细&#xff0c;直接上代码 新增内容 1.ImageIO.write读取并显示图片 2.ImageIO.writeImageIO.write读取并保存图片 package swing21_30;import javax.imageio.ImageIO; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent…

内存函数的学习

额外知识点 第一个 假设c为int类型&#xff0c;&#xff08;char&#xff09;c之后&#xff0c;之后如果还用变量c的话&#xff0c;c依然为int类型。&#xff08;&#xff09;强制转换操作符并不会永久改变原本的变量类型。 第二个 \0在打印时不会显示出来 第三个 void …

浏览器原理篇—渲染阻塞

渲染阻塞 1.DOM 的解析 html 文档 边加载边解析 的&#xff1b;网络进程和渲染进程之间会建立一个共享数据的管道&#xff0c;网络进程接收到数据实时传递给渲染进程&#xff0c;渲染进程的 HTML 解析器&#xff0c;它会动态接收字节流&#xff0c;并将其解析为 DOM 2.字节流…