November 26

使用opencv2.4.13进行人脸识别测试

1.使用opencv2.4.13进行人脸图片的静态识别测试。

2.安装opencv开发环境,下载opencv2.4.13,解压之后得到文件夹opencv。

3.在Eclipse下添加jar路径,如图:

eclipse_2016-11-26_14-41-48

4.编辑opencv-2413.jar的Native Library,如图:

eclipse_2016-11-26_14-45-28

5.配置完成。

6.测试代码为:

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
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;

public class FaceDetector {

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        System.out.println(“\nRunning FaceDetector”);
        //System.out.println(FaceDetector.class.getResource(“lbpcascade_frontalface.xml”).getPath());

        String url0 = FaceDetector.class.getResource(“lbpcascade_frontalface.xml”).getPath();
        if (url0.startsWith(“/”, 0))
            url0=url0.replaceFirst(“/”, “”);
        try {
            url0=URLDecoder.decode(url0, “UTF-8”);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //this will replace %20 with spaces
        CascadeClassifier faceDetector = new CascadeClassifier(url0);

        String url1 = FaceDetector.class.getResource(“run.jpg”).getPath();
        if (url1.startsWith(“/”, 0))
           url1=url1.replaceFirst(“/”, “”);
        try {
            url1=URLDecoder.decode(url1, “UTF-8”);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //this will replace %20 with spaces
        Mat image = Highgui.imread(url1);

//        Mat image = Highgui
//                .imread(FaceDetector.class.getResource(“test.jpg”).getPath());

        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

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

        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, 255, 0));
        }

        String filename = “dingxiao.png”;
        System.out.println(String.format(“Writing %s”, filename));
        Highgui.imwrite(filename, image);
    }
}

7.测试结果,图中绿色框为人脸识别结果,识别的准确率不是很高。

result

Category: JavaFX | LEAVE A COMMENT
October 19

扬州-吴侬细语

扬州,只在诗句中念到过,今来到此地,和想象中的江南小城确实是曾相识,出差的落脚地是运河边有一定历史的盐商古宅-名为湖南会馆,从房间的阳台望出去,凌乱的小院点缀在郁郁葱葱的树木中,一种儿时才有的墙门生活又再次呈现在眼帘中,很有味道,很怀念~~~

September 3

童年

​每每看到女儿开心玩耍时,会不经的联想到自己的童年,那时过暑假是最开心的,有一群小伙伴在一起玩,打水仗,打弹珠,躲猫猫,每天都有过的很快乐,很怀念。