Java之Opencv人脸识别-yellowcong
2018-01-06 12:59
399 查看
通过opencv来识别浙大的美女,是不是爽歪歪啊,其中我们只要有越丰富的人脸模型,我们的识别就可以更加的精确,这个模型不是很精确,有的人脸没有识别上
项目地址
#码云地址 https://gitee.com/yellowcong/opencv #github https://github.com/yellowcong/opencv[/code]案例
识别后的美女目录结构
pics这个目录用来放需要识别的图片
cascade_storage.xml 这个是人脸识别的模型
这个jar包在中央仓库配有所以 自己直接放到项目了代码
package com.yellowcong.face; import java.io.File; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.highgui.Highgui; import org.opencv.objdetect.CascadeClassifier; /** * 创建日期:2018年1月6日<br/> * 创建时间:上午11:59:19<br/> * 创建者 :yellowcong<br/> * 机能概要: */ public class FaceDemo { public static void main(String[] args) { //图片地址 String inputImagePath = FaceDemo.class.getClassLoader().getResource("pics/demo.jpg").getFile(); // 指定读出的图片路径和输出的文件 String outputImageFile = "D:/demo_identificate.png"; //加载lib,这个lib的名称 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //读取图像的 mat信息 Mat image = Highgui.imread(new File(inputImagePath).getAbsolutePath()); //初始化人脸识别类 MatOfRect faceDetections = new MatOfRect(); //添加识别模型 String xmlPath = FaceDemo.class.getClassLoader().getResource("cascade_storage.xml").getPath().substring(1); CascadeClassifier faceDetector = new CascadeClassifier(xmlPath); //识别脸 faceDetector.detectMultiScale(image, faceDetections); // 画出脸的位置 for (Rect rect : faceDetections.toArray()) { Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255), 2); } // 写入到文件 Highgui.imwrite(outputImageFile, image); System.out.print("图片已经识别"); } }环境搭建
添加lib到maven的路径中
注意,直接添加到jar包的路径上,是没有用的,只能添加到maven这个上面jar 添加pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>yellowcong</groupId> <artifactId>day01_06</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>day01_06</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>opencv</groupId> <artifactId>opencv-2413</artifactId> <version>opencv-2413</version> <scope>system</scope> <optional>true</optional> <systemPath>${project.basedir}/src/main/lib/opencv/opencv-2413.jar</systemPath> </dependency> </dependencies> </project>
相关文章推荐
- android jni中将大数据回调到java层的时候用法,比如视频流,音频流等,图片流等 比如我用ffmpeg解码好视频流,想送到java层使用opengGL进行显示,opencv进行人脸识别等等
- Eclipse+Java+OpenCV246人脸识别
- Java使用OpenCV实现人脸识别/人眼检测/图片截取/合成/添加水印
- opencv 人脸识别 环境搭建---java版-----1
- 【opencv】Java实现opencv 调用本地摄像头,实现人脸识别、人形识别、人眼识别
- opencv 人脸识别 java版------2
- java+opencv+intellij idea实现人脸识别
- Java使用OpenCV进行人脸识别
- OpenCV学习笔记[3]Java Demo人脸识别
- Java使用OpenCV进行人脸识别
- 利用Java调用OpenCV进行人脸识别
- [译] 第十二天: OpenCV - Java开发者的人脸识别
- opencv使用,人脸识别,java使用opencv
- Java之opencv人脸识别
- Eclipse+Java+OpenCV246人脸识别
- 利用Java调用OpenCV进行人脸识别
- Java调用OpenCV人脸识别
- OPENCV+JAVA 人脸识别
- openCV java(JFrame) 实现人脸识别,人脸自动检测,自动保存裁剪后人脸
- 【OpenCV入门指南】第十三篇 人脸识别