Hack Forums
[Java] Java + OpenCV? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Java + OpenCV? (/showthread.php?tid=5781325)



Java + OpenCV? - Ram - Jan 7, 2018

Anyone here experienced with Java + OpenCV to help me out with Facial Recognition. I basically wish to make a simple program of running a webcam to scan face, I managed to do the face detecation, but I need to help with comparing faces or rather known as facial recognition..

If anyone can help me out that would be great! Thanks!


RE: Java + OpenCV? - OneHalf - Jan 7, 2018

I'm assuming you already have loaded the classifiers and have some kind of detection method separate.

First you need to convert the frame in grayscale and equalize histogram.
Code
Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(grayFrame, grayFrame);

then you'll want to set the min. size for the face to be detected This will set the min. size at 20%
Code
if (this.absoluteFaceSize == 0)
{
    int height = grayFrame.rows();
    if (Math.round(height * 0.2f) > 0)
    {
            this.absoluteFaceSize = Math.round(height * 0.2f);
    }
}

Now initiate the detection
Code
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());

Put results in an aray of rects and draw them out
Code
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
    Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0, 255), 3);

Should now recognize different faces.


RE: Java + OpenCV? - ocd_eddie - Jan 11, 2018

Look at somthing more sophisticated than OpenCV like deep learning facial recognition. This deep neural network stuff is getting very good and very accurate now.