OpenCV+OpenCV-Contrib源码编译

这篇具有很好参考价值的文章主要介绍了OpenCV+OpenCV-Contrib源码编译。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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


前言

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

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


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

一、OpenCV是什么?

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

二、OpenCV 源码编译

1.前期准备

1.1 源码下载

https://opencv.org/releases/OpenCV源码
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

https://github.com/opencv/opencv_contrib/tags opencv_contrib4.5.5地址
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

1.2 cmake安装

1.3 vscode 安装

1.4 git 安装

1.5 mingw安装

2.源码编译

2.1 打开cmake

设置OpenCV 的路径和编译之后存放的路径
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
点击configure 按钮,选择平台对应的编译器
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
设置编译器的路径
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

2.2 去掉不需要的编译模块

去掉python部分
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
去掉java 部分
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
去掉test
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
添加opencv_contrib 路径
opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

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

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

2.4 命令生成install 文件

cd build
minGW32-make -j 4

minGW32-make install

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译



## 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 编译出现

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
说明源码被加密,需要解密。

4. 编译测试

4.1 配置OpenCV 库

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

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

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译
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;
}

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译

4.3 测试效果

opencv_contrib编译,opencv,人工智能,计算机视觉,Opencv_contrib,源码编译


总结

记录下window10 下编译OpenCV+opencv_contrib 的过程,也给有需要的朋友一些经验。文章来源地址https://www.toymoban.com/news/detail-858501.html

到了这里,关于OpenCV+OpenCV-Contrib源码编译的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • OpenCV4.6.0及其扩展模块OpenCV_contrib的Cmake编译安装指南

    下载地址 注意: 从github上下载时尽量避免使用zip下载方式,可能丢失文件。可使用git在网络状况良好(梯纸)时进行下载。 下载地址 选择zip压缩包下载并解压即可。 OpenCV源码版本 必须 与扩展模块版本一致!!! 打开 Cmake ,选择OpenCV源码路径 新建一个build文件夹,编译后

    2024年02月13日
    浏览(64)
  • opencv_contrib扩展模块的安装(CMake编译器)及解决文件下载失败的问题(超详细)

    上篇文章介绍了Windows 10 64位系统下 Visual Studio 2015+OpenCV4.1.0下载安装及环境配置, Visual Studio 2015+OpenCV4.1.0 下载安装及环境配置_专注专心的博客-CSDN博客 本篇文章继续介绍,opencv_contrib扩展模块的安装(CMake编译器),并详细说明了“ffmpeg”、 “ippicv”、“data”、“xfeatures2d”等

    2024年02月14日
    浏览(90)
  • Windows 下编译 OpenCV 和 OpenCV-contrib

    在本文中,我们将介绍如何在 Windows 系统下编译 OpenCV 和 OpenCV-contrib。OpenCV 是一个开源的计算机视觉库,它包含了许多图像处理和计算机视觉的功能。而 OpenCV-contrib 则是一个由社区贡献的额外功能模块,可以为 OpenCV 提供更多的功能。 在编译源码前,需要准备以下源码及环境

    2024年02月08日
    浏览(37)
  • 如何安装 OpenCV 和 OpenCV_contrib

    首先,从opencv官网下载opencv3.4.0以及opencv_contrib压缩包: https://opencv.org/releases/ 在页面下找到3.4.0版本并下载Sources压缩包 opencv_contrib下载网址 https://github.com/opencv/opencv_contrib

    2024年02月16日
    浏览(45)
  • RK3588移植opencv(包含opencv_contrib)过程

    后面给大家准备了我自己编译好的(百度云链接),如果有用,麻烦点个赞!!! PC端:Ubuntu 16.04  opencv 版本: 3.4.13 编译器:aarch64-linux-gnu 工具:cmake opencv-3.4.13 http://链接:https://pan.baidu.com/s/1YBohe41YuOhBZ2iCIupmLA 提取码:0012 --来自百度网盘超级会员V4的分享 opencv_contrib-3.4.

    2024年02月16日
    浏览(44)
  • OpenCV_contrib配置教程(详细版)

    个人笔记: 操作系统:Windows 10或Windows 11 软件:Visual Studio 2017、OpenCV4.5.1、OpenCV_contrib4.5.1扩展库、Cmake3.19.3. 个人用到是vs2017,这里vs版本也可以用2015,2019,等,自己尝试即可。 注意:OpenCV基础库和contrib扩展库的版本一定要一致!!! 1:OpenCV4.5.1、OpenCV_contrib4.5.1扩展库下载

    2024年02月09日
    浏览(50)
  • ubuntu18.04系统安装opencv及opencv_contrib

    这篇文章博主是正在学习的过程中总结的,有什么问题请各位提出,便于博主改正。 博主使用的 ubuntu 系统是 18.04 , opencv 和 opencv_contrib 均是 4.6.0 版本的,使用 Qt 编写使用opencv的程序。 安装任意版本都是通用的,如果有问题,欢迎各位提出修改建议。 1.opencv安装包 下载地

    2024年02月04日
    浏览(61)
  • Ubuntu 20.04 安装opencv 和 +opencv_contrib教程

    首先opencv和opencv_contrib下载版本要一致!!!! 我是以opencv3.4.5为例 opencv下载官网:Releases - OpenCV opencv_contirb网址:GitHub - opencv/opencv_contrib: Repository for OpenCV\\\'s extra modules 源地址:GitHub - opencv/opencv_contrib: Repository for OpenCV\\\'s extra modules 以上即是在Ubuntu上下载好opencv和opencv_contrib

    2024年02月11日
    浏览(49)
  • Visual Stdio2022+Opencv4.8.0+Opencv-contrib+Cmake3.27.1

    默认Visual Stdio已经安装完成。之前只安装了opencv,发现有些功能实现不了,还需要依赖opencv-contrib,所以这里对其进行一个记录。 一.安装opencv、opencv-contrib、Cmake opencv安装链接: Releases - OpenCV https://opencv.org/releases/ opencv-contrib安装链接:  Tags · opencv/opencv_contrib · GitHub https:

    2024年02月08日
    浏览(47)
  • Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0 及错误

    Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0 在OpenCV的官方网站下载OpenCV的4.4.0源文件 OpenCV源文件下载地址 并下载4.4.0版本的contrib包 OpenCV_contrib下载地址 将opencv-contrib安装在opencv中 首先,更新一下 然后安装依赖包 其中遇见无法安装libjasper-dev的问题 4.1 安装CMake-gui 进入opencv文件夹,

    2024年02月15日
    浏览(51)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包