Face Detection in Java - It's Easy!

    I hasten to share my joy with you :) I recently encountered a problem here - it was necessary to determine the locations of the persons in the picture.

    Why this is needed is another question: I, personally, needed to create a model for distributing attention in the picture, and maybe someone needed to automatically select people on a group photo in a facebook.

    Algorithms, in principle, are well known. One of the best is the Viola & Jones algorithm, but the search for ready-made implementations did not bring any results. It was upset, but drew attention to a wonderful native library - OpenCV . The library is valuable not only for the implementation of the basic algorithms of computer vision, but for the fact that it is found decisively on all platforms.

    And what do you think? One of the first in Google to drop such a wonderful project JNI interface to OpenCV!

    A few minutes of downloading, a dozen minutes of reading documentation with the installation of the program, and another ten - writing a test. And then, with these four lines, we just take and recognize the faces in the picture!

    OpenCV cv = new OpenCV();
    cv.loadImage("test.jpg", 300, 400);
    cv.cascade("haarcascade_frontalface_default.xml");
    Rectangle bounds[] = cv.detect();




    As I understand it, the JNI interface was written by Bryan Chung for the Processing language (by the way, a video was posted on his website to illustrate the program), and the code was later developed and uploaded to Atelier hyperm├ędia under a BSD license.

    Also popular now: