mingw下编译opencv4.5.2

2023-12-22 10:45:30

初衷:

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

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 configuration
    module 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 code
    module 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 optimization
    module 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.i
    module 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.dat
    module 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 install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:1010 (include)



General configuration for OpenCV 4.5.2 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            G:/workspace/opencv-4.5.2/opencv_contrib-4.x/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2023-12-21T03:10:16Z
    Host:                        Windows 10.0.18363 AMD64
    CMake:                       3.24.2
    CMake generator:             MinGW Makefiles
    CMake build tool:            G:/QT/qt/Tools/MinGW_4.9.2/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2
      requested:                 SSE2
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX
      requested:                 SSE4_1 SSE4_2 AVX FP16
      SSE4_1 (15 files):         + SSE3 SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ 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  -DNDEBUG
    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 -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_DEBUG
    C Compiler:                  G:/QT/qt/Tools/MinGW_4.9.2/MinGW/bin/gcc.exe
    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 -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  -DNDEBUG
    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 -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_DEBUG
    Linker flags (Release):      -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra 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 xphoto
    Disabled:                    -
    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 viz
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    VTK support:                 NO

  Media 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:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      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:                   NO
    DirectShow:                  NO

  Parallel framework:            none

  Trace:                         YES (built-in)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    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.6

  Python (for build):            F:/windows_wd/AI/python/py/python.exe

  Java:                          
    ant:                         NO
    JNI:                         G:/QT/jdk/include G:/QT/jdk/include/win32 G:/QT/jdk/include
    Java wrappers:               NO
    Java tests:                  NO

  Install 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 scope
     return _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 scope
     return _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 declared
   return ::_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
         v_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 scope
     return 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 scope
     return 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 scope
     v_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 scope
     v_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 scope
                     v_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 scope
                     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:142:84: error: 'v_add' was not declared in this scope
                     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: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 scope
                     v_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 scope
                     v_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 scope
                     v_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 scope
                     s00 = 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

文章来源:https://blog.csdn.net/wd1603926823/article/details/135125976
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。