opencv使用中常见的问题
发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,本篇内容主要讲解"opencv使用中常见的问题",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"opencv使用中常见的问题"吧!最近项目遇到一个问题,spr
千家信息网最后更新 2025年02月03日opencv使用中常见的问题
本篇内容主要讲解"opencv使用中常见的问题",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"opencv使用中常见的问题"吧!
最近项目遇到一个问题,springboot2在打包过程中出现的问题;
1、引用本地的jar包,怎么打包到项目;
pom.xml 配置 dependencies标签配置其中,version为必填,尝试过省略,报错; plugins标签配置 org.opencv opencv 0.0.1 system ${project.basedir}/src/main/resources/lib/opencv-440.jar org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 UTF-8 ${project.basedir}/src/main/resources/lib resources标签 配置 org.springframework.boot spring-boot-maven-plugin true ${project.basedir}/src/main/resources lib/*.jar ${project.basedir}/src/main/resources lib/*.dll ${project.basedir}/src/main/resources *.yml ${project.basedir}/src/main/resources */*.xml ${project.basedir}/src/main/resources */*.json
2、opencv使用人脸识别过程中,需要引入haarcascade_frontalface_alt2.xml文件,如果放在项目的lib文件中,在打包的过程中能够打到包里,但是在动态引用的过程中,由于jar包中文件的引用出现混乱路径的情况,找不到文件。找到一个折中的办法,haarcascade_frontalface_alt2.xml文件放到固定目录下,再引用的时候,只需要读取固定的路径即可。
yml文件配置
path:
resourcePath: C:\haarcascade_frontalface_alt2.xml # 人脸识别的xml配置文件
NativeConfig.java类
package com.hake.smart.configration;import com.hake.smart.ymlconfig.YmlConfigUtil;import lombok.extern.slf4j.Slf4j;import org.opencv.core.*;import org.opencv.imgcodecs.Imgcodecs;import org.opencv.imgproc.Imgproc;import org.opencv.objdetect.CascadeClassifier;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.util.ClassUtils;import javax.annotation.Resource;import java.util.Arrays;/** * @Author: Liu Yue * @Descripition: * @Date; Create in 2020/8/25 15:59 **/@Configuration@Slf4jpublic class NativeConfig { @Resource private YmlConfigUtil ymlConfigUtil; @Value("${path.resourcePath}") private static String resourcePath; @Value(value = "${path.resourcePath}") private void setResourcePath(String resourcePath){ this.resourcePath = resourcePath ; } @Bean public NativeConfig initFrontalface(){ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); log.error("路径:{}",resourcePath); faceDetector = new CascadeClassifier(resourcePath); return new NativeConfig(); } /** * 测试OpenCV是否能运行:需要自行修改图片位置 * @throws Exception 测试是否成功 */ static CascadeClassifier faceDetector;/* static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //String url = "C:/hake/gitremote/hakesmartacceptback/target/classes/lib/haarcascade_frontalface_alt2.xml"; //ClassPathResource("lib/haarcascade_frontalface_alt2.xml"); *//*ClassPathResource resource = new ClassPathResource("lib/haarcascade_frontalface_alt2.xml"); String path = resource.getPath(); path = basepath + path;*//* URL urlClass = ClassLoader.getSystemResource("lib/haarcascade_frontalface_alt2.xml"); String path = urlClass.getPath(); log.error("路径:{}",path); path = path.substring(1,path.length()); faceDetector = new CascadeClassifier(path); }*/ private Mat conv_Mat(String img_1) { Mat image0 = Imgcodecs.imread(img_1); Mat image = new Mat(); //灰度转换 Imgproc.cvtColor(image0, image, Imgproc.COLOR_BGR2GRAY); MatOfRect faceDetections = new MatOfRect(); //探测人脸 faceDetector.detectMultiScale(image, faceDetections); // rect中是人脸图片的范围 for (Rect rect : faceDetections.toArray()) { //切割rect人脸 Mat mat = new Mat(image, rect); return mat; } return null; } //比较图片相似度 public Boolean compare_image(String img_1, String img_2) { Mat mat_1 = conv_Mat(img_1); Mat mat_2 = conv_Mat(img_2); Mat hist_1 = new Mat(); Mat hist_2 = new Mat(); //颜色范围 MatOfFloat ranges = new MatOfFloat(0f, 256f); //直方图大小, 越大匹配越精确 (越慢) MatOfInt histSize = new MatOfInt(1000); Imgproc.calcHist(Arrays.asList(mat_1), new MatOfInt(0), new Mat(), hist_1, histSize, ranges); Imgproc.calcHist(Arrays.asList(mat_2), new MatOfInt(0), new Mat(), hist_2, histSize, ranges); // CORREL 相关系数 double res = Imgproc.compareHist(hist_1, hist_2, Imgproc.CV_COMP_CORREL); log.info("OPENCV人脸相似度:{}",res); int lifePhotostandard = ymlConfigUtil.getLifePhotostandard(); log.info("相识度标准:{}",lifePhotostandard); boolean bl = res * 100 > lifePhotostandard ? true:false; return bl; }}
到此,相信大家对"opencv使用中常见的问题"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
文件
人脸
配置
问题
路径
过程
常见
图片
标签
项目
相似
内容
范围
学习
测试
实用
更深
精确
成功
混乱
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
idea数据库连接放在哪里
幻塔人数多的服务器
ado访问acess数据库
网络安全方面的专利
少年网络安全教育心得体会
网络安全方面工作和工作打算
有关网络安全的背景图
打印服务器支持斑马打印机吗
天宇网络服务器
湖南语音网络技术服务保障
互联网连接人性与科技
软件开发权如何入账
教师网络安全知识内容
mpp数据库一般存哪些数据
数据库表插入数据下一行按什么
福建服务器机房售后服务云主机
硕士软件开发
2016网络安全和信息化委员会
centos 导入数据库
编写软件提供数据库查询功能源码
图书管理系统软件开发基于什么
软件开发国企招聘
服务器切换网卡
数据库设立通俗解释
石家庄节能软件开发费用
江阴创新计算机网络技术服务优势
mqtt协议软件开发
mail的服务器设置
泉州市网络安全会议
战地5自建服务器怎么一直开