opencv-4.8.0编译及使用

1 编译

        opencv的编译总体来说比较简单,但必须记住一点:opencv的版本必须和opencv_contrib的版本保持一致。例如opencv使用4.8.0,opencv_contrib也必须使用4.8.0。

        进入opencv和opencv_contrib的github页面后,默认看到的是git分支,如4.x。

        如果想要下载具体的版本,需要通过tag进行查找。

        注意,一定要下载具体的tag进行编译,不要选择branch,否则编译会报错。如opencv选择4.8.0,opencv_contrib选择4.x,编译会报下面的错误:

/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv_contrib-4.x/modules/xphoto/src/grayworld_white_balance.cpp:290:21: error: no matching function for call to 'v_shr'v_sR2 = v_shr(v_mul_wrap(v_sR2, v_gainR), 8);^~~~~
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1437:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1438:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64)
^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1427:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpuvec v_shr(const _Tpuvec& a) \^
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1439:1: note: candidate function template not viable: requires single argument 'a', but 2 arguments were provided
/Users/Github/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin_sse.hpp:1432:16: note: expanded from macro 'OPENCV_HAL_IMPL_SSE_SHIFT_OP'
inline _Tpsvec v_shr(const _Tpsvec& a) \^
/Users/Github/opencv_contrib-4.x/modules/xphoto/src/grayworld_white_balance.cpp:328:21: error: no matching function for call to 'v_shr'v_sB1 = v_shr(v_mul(v_sB1, v_gainB), 16);

        编译脚本如下(make -j8,使用并发编译,编译速度会快些):

make build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX=/Users/opencv-4.8.0 -DBUILD_SHARED_LIBS=OFF -DOPENCV_EXTRA_MODULES_PATH=/Users/Github/opencv_contrib-4.8.0/modules
make -j8
make install

2 使用

        编写cmake时,强烈建议使用find_package引用头文件和lib库,尤其是lib库,千万不要手动逐个引入lib库。opencv的lib库引用关系表复杂,手动引用会出现各种符号未定义。大量的符号未定义会让人忙到怀疑人生。

        完整的cmake如下所示:

#
#cmake for first_opencv
#
cmake_minimum_required(VERSION 3.28)
set(target "first_opencv")
project(${target})
set(CMAKE_CXX_STANDARD 17)
set(project_path "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB srcs "${project_path}/src/*.cpp" "${project_path}/src/*.c")
file(GLOB incs "${project_path}/src/*.hpp" "${project_path}/src/*.h")
source_group(source ${srcs})
source_group(include ${incs})find_package(Iconv)
set(OpenCV_DIR "/Users/libs/opencv-4.8.0/lib/cmake/opencv4")
find_package(OpenCV REQUIRED)
include_directories(${incs} ${OpenCV_INCLUDE_DIRS})add_executable(${target} ${srcs} ${incs})target_link_libraries(${target} ${OpenCV_LIBS})

         注意:

  • set(OpenCV_DIR "/Users/libs/opencv-4.8.0/lib/cmake/opencv4")中/Users/libs/opencv-4.8.0/lib/cmake/opencv4为OpenCVConfig.cmake所在的目录,如果不设置OpenCV_DIR,会报下面错误:
CMake Error at CMakeLists.txt:16 (find_package):By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project hasasked CMake to find a package configuration file provided by "OpenCV", butCMake did not find one.Could not find a package configuration file provided by "OpenCV" with anyof the following names:OpenCVConfig.cmakeopencv-config.cmakeAdd the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set"OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"provides a separate development package or SDK, be sure it has beeninstalled.
  • find_package(Iconv)必须添加,否则会报下面的错误:
CMake Error at /Users/libs/opencv-4.8.0/lib/cmake/opencv4/OpenCVModules.cmake:371 (set_target_properties):The link interface of target "opencv_wechat_qrcode" contains:Iconv::Iconvbut the target was not found.  Possible reasons include:* There is a typo in the target name.* A find_package call is missing for an IMPORTED target.* An ALIAS target is missing.Call Stack (most recent call first):/Users/libs/opencv-4.8.0/lib/cmake/opencv4/OpenCVConfig.cmake:133 (include)CMakeLists.txt:16 (find_package)

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

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

相关文章

NAS搭建NextCloud集成OnlyOffice

1、安装NextCloud(如果总是中断就换个镜像源) 2、创建容器 如果需要穿透选HOST 端口必须80 读写必须开 3、启动容器并配置,看图。 启动看日志,等启动完成再访问。首次启动大约5-10分钟左右。 成功后,我们正常进行安装…

学习selenium+python使用 XPath 表达式来实现找到目标元素时智能封装等待,执行测试代码启动Chrome浏览器后,地址栏只显示data;

背景 学习使用 XPath 表达式来实现找到目标元素时智能封装等待执行测试代码启动Chrome浏览器后,地址栏只显示data; 代码如下 import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from …

6.2 声音编辑工具GoldWave5简介(5)

6.2.4录制声音 利用Windows自带的“录音机”录制声音时,只能录制最大时长为1分钟的声音,而利用GoldWave5,可以录制时长长达277小时以上的声音,而且,录制完成后,还可以很方便地对声音进行处理、转换等操作。…

由jar包冲突导致的logback日志不输出

最近接手一个厂商移交的项目,发现后管子系统不打印日志。 项目使用的logback 本地断点调试发现logback-classic jar冲突导致 打出的war中没有 相关的jar 解决方法: 去除pom 文件中多余的 logback-classic 应用,只保留最新版本的。 重新打…

记录用python封装的第一个小程序

前言 我要封装的是前段时间复现的一个视频融合拼接的程序,现在我打算将他封装成exe程序,我在这里只记录一下我封装的过程,使用的是pyinstaller,具体的封装知识我就不多说了,可以参考我另一篇博客:将Python…

NLP技术在搜索推荐场景中的应用

NLP技术在搜索推荐中的应用非常广泛,例如在搜索广告的CTR预估模型中,NLP技术可以从语义角度提取一些对CTR预测有效的信息;在搜索场景中,也经常需要使用NLP技术确定展现的物料与搜索query的相关性,过滤掉相关性较差的物…

HashMap 为什么线程不安全?

如果你现在需要准备面试,可以关注我的公众号:”Tom聊架构“,回复暗号:”578“,领取一份我整理的50W字面试宝典,可以帮助你提高80%的面试通过率,价值很高!! JDK1.7 及之前…

函数指针和回调函数 以及指针函数

函数指针(Function Pointer): 定义: 函数指针是指向函数的指针,它存储了函数的地址。函数的二制制代码存放在内存四区中的代码段,函数的地址它在内存中的开始地址。如果把函数的地址作为参数,就…

力扣2182.构造限制重复的字符串

思路:先记录每个字符的出现次数,构建一个新字符串,从尾取字符,每取一个该字符个数-1,若该字符已经取到有repeatLimit个,则递归取次大的字符,并对应字符个数-1,若没有次大字符了&…

Elasticsearch基础篇(七):分片大小修改和路由分配规则

Elasticsearch基础篇(七):分片大小修改和路由分配规则1. 分片1.1 主分片(Primary Shard)1.2 副本分片(Replica Shard)1.3 分片路由(Routing Shard) 2. 分片分配的基本策略3. 分片写入验证3.1 数…

2024年前端最新面试题-vue3(持续更新中)

文章目录 前言正文什么是 MVVC什么是 MVVM什么是 SPA什么是SFC为什么 data 选项是一个函数Vue 组件通讯(传值)有哪些方式Vue 的生命周期方法有哪些如何理解 Vue 的单项数据流如何理解 Vue 的双向数据绑定Vue3的响应式原理是什么介绍一下 Vue 的虚拟 DOM介…

设计模式-- 3.适配器模式

适配器模式 将一个类的接口转换成客户希望的另外一个接口。使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 角色和职责 请求者(client):客户端角色,需要使用适配器的对象,不需要关心适配器内部的实现,…

IEEE论文LaTeX模板解析(十一)| 尾页栏目均衡(Last Page Column Equalization)

本文收录于专栏:IEEE论文LaTeX模板解析,本专栏将会围绕IEEE论文LaTeX模板解析持续更新。欢迎点赞收藏关注! 文章目录 IEEE 在最后一页平衡了各栏的长度。这种平衡是粗略的,因为参考文献或 IEEE 传记条目通常不会断开,…

Origin 或 Referer 的关系和区别

Origin 或 Referer 的关系和区别 Origin 和 Referer 都可以服务端用来做来源验证,来防止 csrf 攻击,都是浏览器自动带在请求头的但是,可以通过 Referrer Policy 来禁止请求携带 referer,【请求头增加字段 Referrer-Policy: no-ref…

TF-IDF(词频-逆文档频率)

文章目录 高频词只能说明词汇在评论中出现的频率高,但并不能说明这个词汇的重要性。利用关键词提取可以弥补这一不足,关键词提取是一种自动化的文本处理技术,它可以从一篇文章中自动抽取出最能代表文章主题和内容的若干个词语或短语。通常情况…

常用的检测数据异常值方式,以及异常数据如何处理!!

清除数据异常值 1.箱线图检测数据异常值方法2.3σ原则检测数据异常值方法3. 异常数据处理方式:总结(小白看看就行) 1.箱线图检测数据异常值方法 箱线图检测:箱线图是一种常用的异常值检测方法,它以数据的分位数为基础…

常见的加密算法

加密算法 AES 高级加密标准(AES,Advanced Encryption Standard)为最常见的对称加密算法(微信小程序加密传输就是用这个加密算法的)。对称加密算法也就是加密和解密用相同的密钥,具体的加密流程如下图: RSA RSA 加密算法是一种典型的非对称加密算法&am…

正则表达式2 常见模式

继上次的正则表达式速攻1/2-CSDN博客 还有一些常见的匹配模式可以直接使用 电子邮箱 xxxxxx.域名 的情况 \b[A-Za-z0-9._%-][A-Za-z0-9.-]\.[A-Z|a-z]{2,}\bhttp或者https网址 的情况 http[s]?://(?:[a-zA-Z]|[0-9]|[$-_.&]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F…

DRL入门

目录 1. DRL的核心概念 2. 算法分类 1、免模型学习和有模型学习(理不理解所处的环境) 2、基于策略(概率)的方法和基于价值的方法 3、回合更新和单步更新: 4、在线学习和离线学习 文献 1. Deep Reinforcement L…

Java后端开发——Mybatis实验

文章目录 Java后端开发——Mybatis实验一、MyBatis入门程序1.创建工程2.引入相关依赖3.数据库准备4.编写数据库连接信息配置文件5.创建POJO实体6.编写核心配置文件和映射文件 二、MyBatis案例:员工管理系统1.在mybatis数据库中创建employee表2.创建持久化类Employee…