当前位置: 首页 > news >正文

mingw编译opencv

我这里是msys2

这个是msys2的教程
https://blog.csdn.net/qq_39942341/article/details/105931335?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167821146216800197067008%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=167821146216800197067008&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_ecpm_v1~rank_v31_ecpm-1-105931335-null-null.blog_rank_default&utm_term=msys2&spm=1018.2226.3001.4450

msys2

这里用msys2直接装
配置一下msys2的环境变量(教程里有)
装qt6,将C:\Qt\6.4.2\mingw_64\bin加入环境变量(不知道msvc的能不能用)
(qt6这个可以极端一点,直接想办法下载dll,但是我懒得尝试)

pacman -S mingw-w64-x86_64-opencv

在这里插入图片描述
接着测试
main.cpp

#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>int main() {cv::Mat img = cv::imread("E:\\opencv_test\\test.jpg");cv::imshow("img", img);cv::waitKey(0);cv::destroyAllWindows();return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_test VERSION 0.1.0)IF(NOT CMAKE_BUILD_TYPE)SET(CMAKE_BUILD_TYPE Release)
ENDIF()add_executable(${PROJECT_NAME} main.cpp)# Where to find CMake modules and OpenCV
#set(OpenCV_DIR "D:\\opencv-4.5.5\\opencv-4.5.5\\build")
find_package(OpenCV REQUIRED)message(STATUS "OpenCV Include: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV Libs: ${OpenCV_LIBRARIES}")INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}  ${OpenCV_LIBS})

打开cmd/powershell

mkdir build
cd build
cmake -G "MinGW Makefiles" ..
mingw32-make
.\OpenCV_test.exe

懒人版

https://gitee.com/kirigaya/opencv_built_by_gcc_on_-windows
https://github.com/huihut/OpenCV-MinGW-Build

下了之后,需要设置环境变量D:\opencv-4.5.5\opencv-4.5.5\build\x64\mingw\bin
(就是\x64\mingw\bin)

接着测试
除了cmake,剩下的和上面一样
CMakeLists.txt
与上一个的区别就是set(OpenCV_DIR)这一行

cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_test VERSION 0.1.0)IF(NOT CMAKE_BUILD_TYPE)SET(CMAKE_BUILD_TYPE Release)
ENDIF()add_executable(${PROJECT_NAME} main.cpp)# Where to find CMake modules and OpenCV
set(OpenCV_DIR "D:\\opencv-4.5.5\\opencv-4.5.5\\build")
find_package(OpenCV REQUIRED)message(STATUS "OpenCV Include: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV Libs: ${OpenCV_LIBRARIES}")INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}  ${OpenCV_LIBS})

源码

暂时没成功

我这里mingw是用msys2装的

配置一下msys2的环境变量(教程里有)
装qt6,将C:\Qt\6.4.2\mingw_64\bin加入环境变量(不知道msvc的能不能用)
cmake加入环境变量(要比msys高

去官网下sources
https://opencv.org/releases/
选择sources
我这里选的4.5.5
在这里插入图片描述

在这里插入图片描述

在这个目录打开cmd/powershell

mkdir build
mkdir mingw_build
cd mingw_build
cmake -G "MinGW Makefiles" .. -DCMAKE_INSTALL_PREFIX="../build" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_python_tests=OFF -DOPENCV_DOWNLOAD_MIRROR_ID=gitcode -DBUILD_TIFF=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DWITH_CUDA=OFF -DWITH_VTK=OFF -DWITH_MATLAB=OFF -DCMAKE_CXX_COMPILER=g++ -DWITH_QT=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_MSMF=OFF -DWITH_IPP=OFF -DWITH_OPENGL=ON -DBUILD_JAVA=OFF -DOPENCV_ENABLE_ALLOCATOR_STATS=OFF -DWITH_MSMF=OFF -DWITH_ZLIB=ON -DBUILD_ZLIB=ON

接着

cmake-gui

不要tests
在这里插入图片描述
不要java
在这里插入图片描述
要opengl
在这里插入图片描述
不要ENABLE_PRECOMPILED_HEADERS
在这里插入图片描述
不要WITH_MSMF
在这里插入图片描述
不要WITH_IPP
在这里插入图片描述
不要OPENCV_ENABLE_ALLOCATOR_STATS
在这里插入图片描述
不要java
在这里插入图片描述

要qt
在这里插入图片描述
点configure直到没有红的
然后点generate

General configuration for OpenCV 4.5.5 =====================================Version control:               unknownPlatform:Timestamp:                   2023-03-08T03:26:07ZHost:                        Windows 10.0.19045 AMD64CMake:                       3.26.0-rc1CMake generator:             MinGW MakefilesCMake build tool:            C:/msys64/mingw64/bin/mingw32-make.exeConfiguration:               ReleaseCPU/HW features:Baseline:                    SSE SSE2 SSE3requested:                 SSE3Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKXrequested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKXSSE4_1 (16 files):         + SSSE3 SSE4_1SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVXAVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVXAVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKXC/C++:Built as dynamic libs?:      YESC++ standard:                11C++ Compiler:                C:/msys64/mingw64/bin/g++.exe  (ver 12.2.0)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  -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 -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_DEBUGC Compiler:                  C:/msys64/mingw64/bin/cc.exeC flags (Release):           -fsigned-char -W -Wall -Werror=return-type -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  -DNDEBUGC flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -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_DEBUGLinker flags (Release):      -Wl,--gc-sections  Linker flags (Debug):        -Wl,--gc-sections  ccache:                      NOPrecompiled headers:         NOExtra dependencies:3rdparty dependencies:OpenCV modules:To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoioDisabled:                    java_bindings_generator python_bindings_generator python_tests worldDisabled by dependency:      -Unavailable:                 java python2 python3 tsApplications:                appsDocumentation:               NONon-free algorithms:         NOWindows RT support:            NOGUI:                           QT6QT:                          YES (ver 6.4.2 )QT OpenGL support:         YES (Qt6::OpenGL )Win32 UI:                    YESOpenGL support:              YES (opengl32 glu32)Media I/O: ZLib:                        zlib (ver 1.2.11)JPEG:                        build-libjpeg-turbo (ver 2.1.2-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:                     OpenEXR::OpenEXR (ver 3.1.5)HDR:                         YESSUNRASTER:                   YESPXM:                         YESPFM:                         YESVideo I/O:DC1394:                      NOFFMPEG:                      YES (prebuilt binaries)avcodec:                   YES (58.134.100)avformat:                  YES (58.76.100)avutil:                    YES (56.70.100)swscale:                   YES (5.9.100)avresample:                YES (4.0.0)GStreamer:                   YES (1.22.1)DirectShow:                  YESParallel framework:            noneTrace:                         YES (built-in)Other third-party libraries:Lapack:                      NOEigen:                       YES (ver 3.4.0)Custom HAL:                  NOProtobuf:                    build (3.19.1)OpenCL:                        YES (no extra features)Include path:                D:/opencv-4.5.5/opencv-4.5.5/3rdparty/include/opencl/1.2Link libraries:              Dynamic loadPython (for build):            NOInstall to:                    D:/opencv-4.5.5/opencv-4.5.5/build
-----------------------------------------------------------------
mingw32-make clean
mingw32-make -j 12

然后我就死在这了

mingw32-make[2]: *** No rule to make target 'zlib', needed by 'bin/libopencv_imgcodecs455.dll'.  Stop.
mingw32-make[1]: *** [CMakeFiles\Makefile2:1823: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2

https://zhuanlan.zhihu.com/p/606873516
https://zhuanlan.zhihu.com/p/488401407

http://www.lryc.cn/news/34534.html

相关文章:

  • 数据结构(八)排序
  • 函数习题:用函数实现判断一个整数是否能被n整除
  • SAP 创建会计冲销凭证
  • Jetson(Ubuntu18.04)设备无法ping通百度能ping通局域网错误集合,(神奇的是这样的情况下Todesk等远程确没有问题)
  • Spring的@Conditional注解
  • 剑指 Offer 67 把字符串转换成整数
  • 【教学典型案例】18.开门小例子理解面向对象
  • Linux环境ENV的概念
  • AcWing数据结构 - 数据结构在算法比赛中的应用(下)
  • 基于嵌入式libxml2的ARM64平台的移植(aarch64)
  • 8. 字符串转换整数 (atoi)
  • [Tomcat]解决IDEA中的Tomcat中文乱码问题
  • python之dataclasses
  • 【MapGIS精品教程】007:MapGIS投影变换案例教程
  • list数据根据属性字段去重
  • java教程(2023-3-8)
  • node 配置 vue npm配置
  • 特斯拉、小鹏开路,城市NOA距好用还有几年?
  • Vue 3第九章:WatchEffect高级侦听器
  • c++基础——函数
  • DPDK系列之七DPDK中的虚拟化支持
  • 设计模式~桥接模式(bridge)-14
  • Java项目3 电子邮件
  • 设计模式~访问者模式(Visitor)-15
  • 实战小项目之视频监控(1-1)
  • DEJA_VU3D - Cesium功能集 之 103-直角箭头(标绘+编辑)
  • Vue 对象扩展运算符(…)
  • 又是活动 没啥好说的 送代码
  • ARP报文内容详细分析
  • js一键保存当前页面所有图片