OpenCV+OpenCV-Contrib源码编译

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

文章目录

  • 前言
  • 一、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 4minGW32-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 modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe 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 modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe 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.txtCall 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 installdirectory
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.mzph.cn/news/765776.shtml

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

相关文章

python(django)之流程接口管理后台开发

1、在models.py中加入流程接口表和单一接口表 代码如下&#xff1a; from django.db import models from product.models import Product# Create your models here.class Apitest(models.Model):apitestname models.CharField(流程接口名称, max_length64)apitester model…

Python学习笔记07

第十三章&#xff0c;面向对象 初识对象 生活中数据的组织 学校开学&#xff0c;要求学生填写自己的基础信息&#xff0c;一人发一张白纸&#xff0c;让学生自己填 我叫林军杰&#xff0c;今年31岁.来自山东省&#xff0c;我是男的&#xff0c;中国人 内容混乱 改为登记表…

详细分析Python中的enumerate()函数(附多个Demo)

目录 前言1. 基本知识2. Demo 前言 对于Python的基本函数&#xff0c;从实战中获取确切知识 1. 基本知识 enumerate() 接受一个可迭代对象作为输入&#xff0c;并返回一个枚举对象这个枚举对象包含了原始可迭代对象中的每个元素以及对应的索引它允许在循环中同时获取索引和值…

uboot - pinctrl - FPGA回片前测试阶段 - 设置GPIO引脚复用失败

问题描述 pinctrl设置引脚复用失败&#xff0c;没有调用到controller中的set_groups_function函数。 问题定位 pinctrl如何注册dm节点如何进行设备树中各个设备节点下的复用配置为什么没调用到控制器实现的set_groups_function函数 &gpio0 {status "okay";p…

Flutter插件开发与发布指南

在Flutter应用程序开发中&#xff0c;有时候我们会遇到需要使用原生功能的情况&#xff0c;这时候就需要编写Flutter插件来实现与原生平台的交互。本篇博客将介绍如何编写、发布和使用Flutter插件。 1. 准备工作 在开始之前&#xff0c;确保你已经安装好Flutter开发环境&…

JavaScript中改进的数组功能

ES6标准为数组添加了很多新功能&#xff0c;例如&#xff0c;创建数组的新方法&#xff0c;创建定型数组&#xff08;Typed Array)的能力等。 1、创建数组 在ES6以前&#xff0c;创建数组的方式主要有两种&#xff0c;一种是调用Array构造函数&#xff0c;另一种是用数组字面…

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

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

Vue动态设置控制表格列表展现列

最近遇到一个需求,表格列表默认不展示某一列,当我设置后可以展示该列,也可以展示和隐藏别的列,起到可以对整个表格列展示隐藏控制的效果,如下示例,默认不展示“单位名称”这一列,在我点击设置齿轮后可以看到,有“单位名称”这一列,但未打钩: 当我勾中“单位名称”,…

第2讲-Memory(5)外存

磁盘存储器 组成 记录原理 性能指标 (磁盘存取时间的计算) 磁盘地址 工作过程 优点 ①存储容量大,位价格低; ②记录介质可重复使用; ③记录信息可长期保存而不丢失,甚至可脱机存档; ④非破坏性读出,读出时不需要再生。 缺点 存取速度慢,机械结构复杂,对工作环境…

在wps的word中如何引用正确引用参考文献

目录 插入参考文献编号把插入的编号置于右上角最终效果 插入参考文献编号 把插入的编号置于右上角 最终效果

面试算法-88-反转链表

题目 给你单链表的头节点 head &#xff0c;请你反转链表&#xff0c;并返回反转后的链表。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4,5] 输出&#xff1a;[5,4,3,2,1] 解 class Solution {public ListNode reverseList(ListNode head) {if(head null || hea…

大数据技术在工厂生产数字转型中的应用与价值

hello宝子们...我们是艾斯视觉擅长ui设计和前端开发10年经验&#xff01;希望我的分享能帮助到您&#xff01;如需帮助可以评论关注私信我们一起探讨&#xff01;致敬感谢感恩&#xff01; 随着大数据技术的快速发展&#xff0c;越来越多的企业开始关注并应用大数据技术&#x…

HCIP-Datacom(H12-821)新题

最新 HCIP-Datacom&#xff08;H12-821&#xff09;完整题库请扫描上方二维码访问&#xff0c;持续更新中。 以下关于OSPF的描述&#xff0c;哪些项是正确的&#xff1f; A. 第二类外部路由的开销值只是AS外部开销值&#xff0c;忽略AS内部开销值 B. AS-External-LSA描述的是…

prettier + eslint 配置

vue-cli 新建项目选择 ESLint Prettier 会自动下载相关包 settings.json {"editor.formatOnSave": true, // 开启保存文件自动格式化代码"editor.defaultFormatter": "esbenp.prettier-vscode", // 默认的代码格式化工具// "prettier.r…

应用日志集成到ElasticSearch

1、阿里云sls平台集成日志 阿里sls集成日志步骤 2、filebeat 收集到指定es 安装docker容器 Docker安装 拉取镜像&#xff1a; docker pull elastic/filebeat:7.5.1启动&#xff1a; docker run -d --namefilebeat elastic/filebeat:7.5.1拷贝容器中的数据文件到宿主机&a…

【C++航海王:追寻罗杰的编程之路】stack

目录 1 -> stack的介绍和使用 1.1 -> stack的介绍 1.2 -> stack的使用 1.3 -> stack的模拟实现 1 -> stack的介绍和使用 1.1 -> stack的介绍 stack的文档介绍 1. stack是一种容器适配器&#xff0c;专门用在具有后进先出操作的上下文环境中&#xff0c…

零基础机器学习(5)之线性回归模型的性能评估

文章目录 线性回归模型的性能评估1.举例1-单一特征2.举例2-多特征 线性回归模型的性能评估 评估线性回归模型时&#xff0c;首先要建立评估的测试数据集&#xff08;测试集不能与训练集相同&#xff09;&#xff0c;然后选择合适的评估方法&#xff0c;实现对线性回归模型的评…

设计模式——模板方法模式封装.net Core读取不同类型的文件

1、模板方法模式 模板方法模式&#xff1a;定义一个操作中的算法骨架&#xff0c;而将一些步骤延迟到子类中&#xff0c;模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。 特点&#xff1a;通过把不变的行为搬移到超类&#xff0c;去除子类中重复的代…

css的transition详解

CSS的transition属性是一个简写属性&#xff0c;用于设置四个过渡效果属性&#xff0c;以在元素的状态改变时创建平滑的动画效果。这四个属性分别是&#xff1a; transition-property&#xff1a; 定义应用过渡效果的CSS属性名称。当指定的CSS属性改变时&#xff0c;过渡效果将…

【保姆级讲解Linux常见命令】

&#x1f308;&#x1f308;&#x1f308;&#x1f308;欢迎 &#x1f308;&#x1f308;&#x1f308; &#x1f389;&#x1f44d;点赞⭐评论⭐收藏&#x1f389; &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让…