Visual Studio 2022配置OpenCV455+CMake(Win11)
- 1下载
-
- 1.1OpenCV下载
- 1.2CMake下载
- 2CMake编译
- 3遇到的警告及解决方案
-
- 3.1ippicv无法下载
- 3.2ffmpeg无法下载
- 3.3wechat_qrcode无法下载
- 4Visual Studio编译
- 5环境配置
- 6测试
- 7其他
记录下CMake配置过程。
1下载 1.1OpenCV下载 (1)Github源码:https://github.com/opencv/opencv选择4.5.5版本。
文章图片
文章图片
(2)Github扩展源码:https://github.com/opencv/opencv_contrib选择4.5.5版本。
文章图片
文章图片
(3)下载后得到的是两个压缩包,解压。
文章图片
1.2CMake下载 官网下载:https://cmake.org/download/选择Windows x64 Installer版。
文章图片
2CMake编译 (1)第一次配置
选择源码、生成路径,VS2022版本x64,等待完成。
文章图片
文章图片
(2)调整配置
1.勾选 OPENCV_EXTRA_NONFREE 项
2.勾选BUILD_opencv_world 项
3.添加OPENCV_EXTRA_MODULES_PATH:E:/Tools/OpenCV/opencv_contrib-4.5.5/modules(即 opencv_contrib/modules 路径)
4.Configure,等待完成
文章图片
文章图片
3遇到的警告及解决方案 3.1ippicv无法下载
CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
IPPICV: Download failed: 6;
"Couldn't resolve host name"For details please refer to the download log file:E:/Tools/OpenCV/OpenCV-4.5.5-Build/CMakeDownloadLog.txtCall Stack (most recent call first):
3rdparty/ippicv/ippicv.cmake:37 (ocv_download)
cmake/OpenCVFindIPP.cmake:259 (download_ippicv)
cmake/OpenCVFindLibsPerf.cmake:12 (include)
CMakeLists.txt:732 (include)
【OpenCV|Visual Studio 2022配置OpenCV455+CMake(Win11)】解决方案:参考
- 打开E:\Tools\OpenCV\OpenCV-4.5.5-Build文件夹下的CMakeDownloadLog.txt找到
#do_unpack "ippicv_2020_win_intel64_20191018_general.zip" "879741a7946b814455eee6c6ffde2984" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_intel64_20191018_general.zip" "E:/Tools/OpenCV/OpenCV-4.5.5-Build/3rdparty/ippicv"
#check_md5 "E:/Tools/OpenCV/opencv-4.5.5/.cache/ippicv/879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip"
https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_intel64_20191018_general.zip
为下载地址,在https://ghproxy.com/的搜索框输入即可下载- 重命名为
879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip
- 将重命名后的文件放入E:\Tools\OpenCV\opencv-4.5.5.cache\ippicv中
CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
FFMPEG: Download failed: 6;
"Couldn't resolve host name"For details please refer to the download log file:E:/Tools/OpenCV/OpenCV-4.5.5-Build/CMakeDownloadLog.txtCall Stack (most recent call first):
3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
modules/videoio/cmake/detect_ffmpeg.cmake:14 (download_win_ffmpeg)
modules/videoio/cmake/init.cmake:7 (include)
modules/videoio/cmake/init.cmake:11 (add_backend)
cmake/OpenCVModule.cmake:298 (include)
cmake/OpenCVModule.cmake:361 (_add_modules_1)
cmake/OpenCVModule.cmake:385 (ocv_glob_modules)
CMakeLists.txt:927 (ocv_register_modules)
解决方案:
- opencv_videoio_ffmpeg.dll:
https://raw.githubusercontent.com/opencv/opencv_3rdparty/4d348507d156ec797a88a887cfa7f9129a35afac/ffmpeg/opencv_videoio_ffmpeg.dll
重命名为eece4ec8304188117ffc7d5dfd0fc0ae-opencv_videoio_ffmpeg.dll
- opencv_videoio_ffmpeg_64.dll:
https://raw.githubusercontent.com/opencv/opencv_3rdparty/4d348507d156ec797a88a887cfa7f9129a35afac/ffmpeg/opencv_videoio_ffmpeg_64.dll
重命名为20deefbfe023c8b8d11a52e5a6527c6a-opencv_videoio_ffmpeg_64.dll
- ffmpeg_version.cmake:
https://raw.githubusercontent.com/opencv/opencv_3rdparty/4d348507d156ec797a88a887cfa7f9129a35afac/ffmpeg/ffmpeg_version.cmake
右键另存为8862c87496e2e8c375965e1277dee1c7-ffmpeg_version.cmake
- 将这三个文件放入E:\Tools\OpenCV\opencv-4.5.5.cache\ffmpeg中
全部完成后点Generate,等待完成。
4Visual Studio编译 (1)生成后点Open Project,选择Debug x64或Release x64。
(2)找到ALL_BUILD,右键生成,等待完成。
文章图片
(3)找到INSTALL,右键,仅当前项目,只生成 INSTALL,等待完成。
文章图片
(4)E:\Tools\OpenCV\OpenCV-4.5.5-Build\install 该路径为环境配置所需。
5环境配置 1.添加系统环境变量E:\Tools\OpenCV\OpenCV-4.5.5-Build\install\x64\vc17\bin
2.新建项目属性表(这里配置的是Release版)
文章图片
3.VC++目录–包含目录添加路径:
E:\Tools\OpenCV\OpenCV-4.5.5-Build\install\include
E:\Tools\OpenCV\OpenCV-4.5.5-Build\install\include\opencv2
文章图片
4.VC++目录–库目录添加路径:
E:\Tools\OpenCV\OpenCV-4.5.5-Build\install\x64\vc17\lib
文章图片
5.链接器–输入–附加依赖项添加:
opencv_world455.lib(Release版)
opencv_world455d.lib(Debug版)
文章图片
6测试
#include
#include //日志头文件
#include using namespace cv;
using namespace std;
int main()
{
//utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);
//不输出日志
//utils::logging::setLogLevel(utils::logging::LOG_LEVEL_ERROR);
//只输出错误日志
Mat src = https://www.it610.com/article/imread("C:/Users/12421/Desktop/Lena.jpg");
if (src.empty())
{
cout << "please cheak image path" << endl;
return -1;
} Mat src_x, src_y, src_xy;
flip(src, src_x, 0);
//沿x轴对称
flip(src, src_y, 1);
//沿y轴对称
flip(src, src_xy, -1);
//沿x轴对称,沿y轴对称 imshow("src", src);
imshow("src_x", src_x);
imshow("src_y", src_y);
imshow("src_xy", src_xy);
waitKey(0);
return 0;
}
原图:
文章图片
结果:
7其他 1.帮助文档下载:https://docs.opencv.org/
2.OpenCV455Debug版本运行时CMD框会显示很多日志,关闭的方法:参考
添加头文件
#include
main()函数里添加语句
cv::utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);
文章图片
文章图片
3.Visual Studio编译中第二步出现opencv_test_objdetect test_qrcode_encode.cpp错误,打开并删除日文注释即可。参考
推荐阅读
- OpenCV|OpenCV学习笔记(一)Opencv4.5.5 VS2019永久开发环境配置
- 机器学习算法|基于Open-cv 的停车场停车位识别个人笔记附所有代码(下)
- 学习笔记|OpenCV(五)停车场的车位识别
- c语言|如何用C语言实现小游戏——扫雷
- c++作业|c++课设作业之课程信息管理系统
- c++学习|19.1 STL总述、发展史、组成与数据结构谈
- C++|C++ 基础与深度分析 Chapter11 类与面向对象编程(构造函数(缺省、单一、拷贝、移动、赋值))
- C++|很值得学习的Linux C++线程池框架
- C++|初识C++模板(函数、类模板)