OpenCV+OpenCV-Contrib源码编译

news2024/9/25 13:22:22

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、OpenCV是什么?
  • 二、OpenCV 源码编译
    • 1.前期准备
      • 1.1 源码下载
      • 1.2 cmake安装
      • 1.3 vscode 安装
      • 1.4 git 安装
      • 1.5 mingw安装
    • 2.源码编译
      • 2.1 打开cmake
      • 2.2 去掉不需要的编译模块
      • 2.3 解决完所有的报错,再次点击generate 按钮
      • 2.4 命令生成install 文件
      • 3.2 Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
      • 3.3 Couldn't download files from the Internet.
      • 3.4 CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
      • 3.5 No modules has been found: G:/OpenCV/455/opencv_contrib-4.5.5
      • 3.6 make 编译出现
    • 4. 编译测试
      • 4.1 配置OpenCV 库
      • 4.2 测试代码
      • 4.3 测试效果
  • 总结


前言

提示:这里可以添加本文要记录的大概内容:

OpenCV是一款免费开源的计算机视觉算法库,在实际使用的时候,需要移植到不同的平台。在这记录下源码编译的过程。


提示:以下是本篇文章正文内容,下面案例可供参考

一、OpenCV是什么?

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

二、OpenCV 源码编译

1.前期准备

1.1 源码下载

https://opencv.org/releases/OpenCV源码
下载指定的版本4.5.5

https://github.com/opencv/opencv_contrib/tags opencv_contrib4.5.5地址
在这里插入图片描述

1.2 cmake安装

1.3 vscode 安装

1.4 git 安装

1.5 mingw安装

2.源码编译

2.1 打开cmake

设置OpenCV 的路径和编译之后存放的路径
在这里插入图片描述
点击configure 按钮,选择平台对应的编译器
在这里插入图片描述
设置编译器的路径
在这里插入图片描述

2.2 去掉不需要的编译模块

去掉python部分
在这里插入图片描述
去掉java 部分
在这里插入图片描述
去掉test
在这里插入图片描述
添加opencv_contrib 路径
在这里插入图片描述

2.3 解决完所有的报错,再次点击generate 按钮

在这里插入图片描述

2.4 命令生成install 文件

cd build
minGW32-make -j 4

minGW32-make install

在这里插入图片描述



## 3. 问题汇总
### 3.1 Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules

```c
CMake Warning (dev) at cmake/OpenCVUtils.cmake:144 (find_package):
  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
  cmake/OpenCVDetectPython.cmake:64 (find_host_package)
  cmake/OpenCVDetectPython.cmake:286 (find_python)
  CMakeLists.txt:660 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

解决办法:在CMakeLists.txt 里面添加以下代码

```c
if(POLICY CMP0148)
  cmake_policy(SET CMP0148 OLD)  # CMake 3.13+: option() honors normal variables.
endif()

3.2 Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules

Found PythonInterp: E:/python389/python.exe (found suitable version "3.8.9", minimum required is "3.2") 
CMake Warning (dev) at cmake/OpenCVDetectPython.cmake:140 (find_package):
  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
  cmake/OpenCVDetectPython.cmake:286 (find_python)
  CMakeLists.txt:660 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

解决办法:同上

3.3 Couldn’t download files from the Internet.

FFMPEG: Downloading opencv_videoio_ffmpeg.dll from https://raw.githubusercontent.com/opencv/opencv_3rdparty/fbac408a47977ee4265f39e7659d33f1dfef5216/ffmpeg/opencv_videoio_ffmpeg.dll
Try 1 failed

=======================================================================
  Couldn't download files from the Internet.
  Please check the Internet access on this host.
=======================================================================

CMake Warning at cmake/OpenCVDownload.cmake:248 (message):
  FFMPEG: Download failed: 6;"Couldn't resolve host name"

  For details please refer to the download log file:

  G:/OpenCV/490_0/opencv/build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
  modules/videoio/cmake/detect_ffmpeg.cmake:17 (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:408 (ocv_glob_modules)
  CMakeLists.txt:1032 (ocv_register_modules)

科学上网,将需要的文件下载下来;类似其他报错误,也是对应将文件下载下来即可。

3.4 CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install

Processing WORLD modules... DONE
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.rvv.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:1039 (include)

解决办法:OPENCV_GENERATE_SETUPVARS,去除勾选

3.5 No modules has been found: G:/OpenCV/455/opencv_contrib-4.5.5

VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
CMake Error at cmake/OpenCVModule.cmake:274 (message):
  No modules has been found: G:/OpenCV/455/opencv_contrib-4.5.5
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:356 (_glob_locations)
  cmake/OpenCVModule.cmake:385 (ocv_glob_modules)
  CMakeLists.txt:931 (ocv_register_modules)

解决办法:路径一定要选到 opencv_contrib/modules 这里。

3.6 make 编译出现

在这里插入图片描述
说明源码被加密,需要解密。

4. 编译测试

4.1 配置OpenCV 库

打开vscode ,打开测试文件夹。

创建 .vscode文件夹,创建c_cpp_properties.json 、launch.json、task.json文件

在这里插入图片描述
c_cpp_properties.json

{
    "configurations": [
        {
            "name": "win",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/software/opencv3/opencv/build/x64/mingw/include",
                "C:/software/opencv3/opencv/build/x64/mingw/install/include/opencv2",
                "C:/software/opencv3/opencv/build/x64/mingw/install/include"
            ],
            "defines": [],
            "compilerPath": "C:/software/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

launch.json

{

    "version": "0.2.0",
    "configurations": [
        {
            "name": "opencv debuge",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}//Debugger//${fileBasenameNoExtension}.exe",
            //上面这个Debugger是我自己定义的,为了方便放置生成的exe文件
            "args": [],
            "stopAtEntry": false, //这里如果为 false,则说明调试直接运行。(反之则停止)
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//是否调用外部cmd
            "MIMode": "gdb",
            "miDebuggerPath": "C:/software/mingw64/bin/gdb.exe",//自己进行设置
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "opencv3.5.2"
        }
    ]
}

task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "opencv3.5.2",
            "command": "C:/software/mingw64/bin/g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}//Debugger//${fileBasenameNoExtension}.exe",
                //上面这个Debugger是我自己定义的,为了方便放置生成的exe文件
                "C:/software/opencv3/opencv/build/x64/mingw/bin/libopencv_world3416.dll",
                "-I",
                "C:/software/opencv3/opencv/build/x64/mingw/install/include",
                "-I",
                "C:/software/opencv3/opencv/build/x64/mingw/install/include/opencv2",
            ],
            "options": {
                "cwd": "C:/software/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

4.2 测试代码

#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
uisng namespace std;
int main()
{
    string imgpath ="/path/to/img.jpg"
    Mat img=imread(imgpath);
    imshow("image",img);
    waitKey();
    return 0;
}

在这里插入图片描述

4.3 测试效果

网络图片,侵删


总结

记录下window10 下编译OpenCV+opencv_contrib 的过程,也给有需要的朋友一些经验。

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[ESP32]:基于HTTP实现百度AI识图

[ESP32]&#xff1a;基于HTTP实现百度AI识图 测试环境&#xff1a; esp32-s3esp idf 5.1 首先&#xff0c;先配置sdk&#xff0c;可以写入到sdkconfig.defaults CONFIG_IDF_TARGET"esp32s3" CONFIG_IDF_TARGET_ESP32S3yCONFIG_PARTITION_TABLE_CUSTOMy CONFIG_PA…

vue.config.js配置项

vue.config.js配置项 vue-cli3 脚手架搭建完成后&#xff0c;项目目录中没有 vue.config.js 文件&#xff0c;需要手动创建 创建vue.config.js vue.config.js(相当于之前的webpack.config.js) 是一个可选的配置文件&#xff0c;如果项目的 (和 package.json 同级的) 根目录中存…

数组不初始化带来的问题及解决、动态分配

C中数组不初始化会输出什么结果 在C中&#xff0c;如果你声明了一个数组但没有对其进行初始化&#xff0c;数组的元素将具有未定义的值。这意味着数组元素的值是不确定的&#xff0c;可能是垃圾值。 当你访问未初始化的数组元素时&#xff0c;可能会得到以下结果&#xff1a;…

力扣---全排列---回溯

思路&#xff1a; 递归做法&#xff0c;一般会有visit数组来判断第 i 位是否被考虑了。我们先考虑第0位&#xff0c;再考虑第1位&#xff0c;再考虑第2位...dfs函数中还是老套路&#xff0c;先判定特殊条件&#xff0c;再从当下的角度&#xff08;决定第 j 位是哪个元素&#x…

Docker 【通过Dockerfile构建镜像】【docker容器与镜像的关系】

文章目录 前言一、前期的准备工作二、上手构建一个简单的镜像三、DcokerFile1 指令总览2 指令详情 四、Dockerfile文件规范五、docker运行build时发生了什么?六、调试手段1. 修改镜像打包后&#xff0c;如何验证新内容已更新至镜像 七、Dockerfile优化方案 前言 docker构建镜…

优化选址问题 | 基于鹈鹕算法求解基站选址问题含Matlab源码

目录 问题代码问题 鹈鹕算法(Pelican Optimization Algorithm, POA)是一种相对较新的启发式优化算法,模拟了鹈鹕鸟觅食的行为。这种算法通常用于解决复杂的优化问题,如函数优化、路径规划、调度问题等。基站选址问题通常是一个复杂的优化问题,需要考虑覆盖范围、干扰、成…

AI修复老照片的一些参数设置

很久没更新CSDN文章了&#xff0c;这次给粉丝带来老照片修复流程 1>用ps修图 图章工具 笔刷 画笔修复 2>高清放大 3>lineattile 重绘 4>上色 具体可参考我的B站视频。 下面是一些笔记。 best quality,masterpiece,photorealistic,8k,ultra high res,solo,ext…

Fabric Measurement

Fabric Measurement 布料测量

通信网络设计[PTA]

文章目录 题目描述思路AC代码 题目描述 输入样例1 6 10 1 2 6 1 5 10 1 6 12 2 4 5 2 6 8 2 3 3 3 4 7 4 5 9 4 6 11 5 6 16 输出样例1 YES! Total cost:31输入样例2 5 4 1 2 3 1 3 11 2 3 8 4 5 9 输出样例2 NO! 1 part:1 2 3 2 part:4 5思路 最小生成树–kruskal算法 具体做法…

RbbitMQ使用教程

RabbitMQ 是一个可靠且成熟的消息传递和流代理&#xff0c;易于部署在云环境、本地和本地计算机上。它目前被全球数百万人使用。通过确认消息传递和跨集群复制消息的功能&#xff0c;您可以使用 RabbitMQ 确保您的消息是安全的。 RabbitMQ安装 推荐使用docker安装部署&#xf…

VMware Workstation Pro 17虚拟机超级详细搭建(含redis,nacos,docker)(一)

今天从零搭建一下虚拟机的环境&#xff0c;把nacos&#xff0c;redis等微服务组件还有数据库搭建到里面&#xff0c;首先看到的是我们最开始下载VMware Workstation Pro 17 之后的样子&#xff0c;总共一起应该有三部分因为篇幅太长了 下载地址 : VMware - Delivering a Digit…

pytest全局配置+前后只固件配置

pytest全局配置前后只固件配置 通过读取pytest.ini配置文件运行通过读取pytest.ini配置文件运行无条件跳过pytest.initest_mashang.pyrun.py 有条件跳过test_mashang.py pytest框架实现的一些前后置&#xff08;固件、夹具&#xff09;处理方法一&#xff08;封装&#xff09;方…

VUE3.0(一):vue3.0简介

Vue 3 入门指南 什么是vue Vue (发音为 /vjuː/&#xff0c;类似 view) 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和JavaScript 构建&#xff0c;并提供了一套声明式的、组件化的编程模型&#xff0c;帮助你高效地开发用户界面。无论是简单还是复杂的界…

[ C++ ] STL---仿函数与priority_queue

目录 仿函数 示例一&#xff1a; 示例二 : 常见的仿函数 priority_queue简介 priority_queue的常用接口 priority_queue的模拟实现 基础接口 push() 堆的向上调整算法 堆的插入 pop() 堆的向下调整算法 堆的删除 priority_queue最终实现 仿函数 仿函数&#xff…

数据结构 - 二叉树非递归遍历

文章目录 前言一、前序二、中序三、后序 前言 本文实现二叉树的前中后的非递归遍历&#xff0c;使用栈来模拟递归。 文字有点简略&#xff0c;需要看图和代码理解 树节点&#xff1a; typedef char DATA; //树节点 typedef struct Node {DATA data; //数据struct Node* left…

MySQL进阶-----Linux系统安装MySQL

目录 前言 一、准备工作 1. 准备一台Linux服务器 2. 下载Linux版MySQL安装包 3. 上传MySQL安装包 二、安装操作指令 1. 创建目录,并解压 2.安装mysql的安装包 三、开启mysql与密码修改 1.启动MySQL服务 2. 查询自动生成的root用户密码 3.修改root用户密码 四、创…

【LeetCode】升级打怪之路 Day 26:回溯算法 — 集合划分问题

今日题目&#xff1a; 698. 划分为k个相等的子集 | LeetCode473. 火柴拼正方形 | LeetCode 参考文章&#xff1a; 经典回溯算法&#xff1a;集合划分问题 目录 LC 698. 划分为k个相等的子集 【classic&#xff0c;有难度】数据预处理&#xff1a;计算 target基本回溯优化 1&…

限时免费!Unity 资源商店威尔房间精品资源等你来领!

Unity 资源商店威尔房间精品资源分享 资源介绍资源特色免费领取 Unity 商店资源&#xff1a;Will’s Room Environment, Dormitory Room Environment 免费获取。 资源介绍 好消息来啦&#xff01;Unity 资源商店的威尔房间精品资源正在限时免费中&#xff01;这是一个非常受欢迎…

一维前缀和一维差分(下篇讲解二维前缀和二维差分)(超详细,python版,其他语言也很轻松能看懂)

本篇博客讲解一维前缀和&#xff0c;一维差分&#xff0c;还会给出一维差分的模板题&#xff0c;下篇博客讲解 二维前缀和&二维差分。 一维前缀和&#xff1a; 接触过算法的小伙伴应该都了解前缀和&#xff0c;前缀和在算法中应用很广&#xff0c;不了解也没有关系&#…

【算法】小强爱数学(迭代公式+数论取模)

文章目录 1. 问题2. 输入3. 输出4. 示例5. 分析6. 思路7. 数论&#xff0c;取模相关公式8. 数论&#xff0c;同余定理9. 代码 1. 问题 小强发现当已知 x y B xyB xyB以及 x y A xyA xyA时,能很轻易的算出 x n x_ {n} xn​ y n y_ {n} yn​ 的值.但小强想请你在已知A和B的…