Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize face recognition by Java OpenCV

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to achieve face recognition with Java OpenCV". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve face recognition with Java OpenCV".

Prepare:

Download the openCV installation package: https://opencv.org/

The installation package supports multiple locales after installation. Java is used here, java/opencv-320.jar under the openCV directory is introduced into Eclipse, and the openCV library path is configured.

Eclipse configuration openCV

Code implementation:

Package test;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.objdetect.CascadeClassifier;import org.opencv.imgcodecs.Imgcodecs;import org.opencv.imgproc.Imgproc;public class Test {/ / introduce the trained face recognition XML file static String PAHT = "E:/GOF/OpenCV/bin/test/haarcascade_frontalface_alt.xml" Static String IMAGE_PATH = "E:/GOF/OpenCV/src/test/a.jpg"; static String productPath = "E:/GOF/OpenCV"; public static void main (String [] args) {System.loadLibrary (Core.NATIVE_LIBRARY_NAME); String Path = Test.class.getResource ("haarcascade_frontalface_alt.xml"). GetPath (); System.out.println (Path); CascadeClassifier faceDetector = new CascadeClassifier (PAHT); Mat image = Imgcodecs.imread (IMAGE_PATH); MatOfRect faceDetections = new MatOfRect (); faceDetector.detectMultiScale (image, faceDetections) System.out.println (String.format ("Detected% s faces", faceDetections.toArray () .length); for (Rect rect: faceDetections.toArray ()) {Imgproc.rectangle (image, new Point (rect.x, rect.y), new Point (rect.x + rect.width, rect.y + rect.height), new Scalar (0,255,0));} String filename = "ouput.png"; System.out.println (String.format ("Writing% s", filename)); boolean flag = Imgcodecs.imwrite (filename, image) }}

Achieve results:

Write a border to the face area

At this point, I believe you have a deeper understanding of "Java OpenCV how to achieve face recognition", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report