网站首页 > 文章中心 > 其它

java人脸识别简单代码的简单介绍

作者:小编 更新时间:2023-09-21 10:17:52 浏览量:188人看过

java 人脸识别 问题!

no jniopencv_objdetect in java.library.path

opencv的相应的dll,没有放到环境变量PATH 所指的目录

java怎么实现人脸识别?

应该可以通过java调用别人的人脸识别的接口,主要是利用图像处理的技术,识别关键点

如何开发Java动态人脸识别

java人脸识别简单代码的简单介绍-图1

①环境搭建

整个项目的结构图

[java] view plaincopy

package com.njupt.zhb.test;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.core.MatOfRect;

import org.opencv.core.Point;

java人脸识别简单代码的简单介绍-图2

import org.opencv.core.Rect;

import org.opencv.core.Scalar;

import org.opencv.highgui.Highgui;

import org.opencv.objdetect.CascadeClassifier;

//

// Detects faces in an image, draws boxes around them, and writes the results

// to "faceDetection.png".

public class DetectFaceDemo {

public void run() {

System.out.println("\nRunning DetectFaceDemo");

System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());

// Create a face detector from the cascade file in the resources

// directory.

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());

//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());

//注意:源程序的路径会多打印一个'/',所以呢总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//所以呢,我们将第一个字符去掉

String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);

CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);

Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));

// Detect faces in the image.

// MatOfRect is a special container class for Rect.

MatOfRect faceDetections = new MatOfRect();

faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.

for (Rect rect : faceDetections.toArray()) {

}

// Save the visualized detection.

String filename = "faceDetection.png";

System.out.println(String.format("Writing %s", filename));

Highgui.imwrite(filename, image);

public class TestMain {

java人脸识别简单代码的简单介绍-图3

public static void main(String[] args) {

System.out.println("Hello, OpenCV");

// Load the native library.

new DetectFaceDemo().run();

//运行结果:

//Hello, OpenCV

//Running DetectFaceDemo

//Writing faceDetection.png

以上就是土嘎嘎小编为大家整理的java人脸识别简单代码的简单介绍java人脸识别简单代码的简单介绍相关咨询咨询主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章