I want to recognize faces in real time through a webcam.I have worked till detecting a face through webcam,but I am having trouble in implementing eigen face algorithm in Java (Netbeans).
I have achieved face detection using following code :-
private DaemonThread myThread = null;
int count = 0;
VideoCapture webSource = null;
Mat frame = new Mat();
MatOfByte mem = new MatOfByte();
CascadeClassifier faceDetector = new CascadeClassifier(ScannerGUI.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
MatOfRect faceDetections = new MatOfRect();
class DaemonThread implements Runnable
{
protected volatile boolean runnable = false;
@Override
public void run()
{
synchronized(this)
{
while(runnable)
{
if(webSource.grab())
{
try
{
webSource.retrieve(frame);
//Highgui.imencode(".bmp", frame, mem);
Graphics g=jPanel1.getGraphics();
faceDetector.detectMultiScale(frame, faceDetections);
for (Rect rect : faceDetections.toArray())
{ Imgproc.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),new Scalar(0, 255, 0),2);
}
Imgcodecs.imencode(".bmp", frame, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
BufferedImage buff = (BufferedImage) im;
if (g.drawImage(buff, 0, 0, getWidth(), getHeight() -150 , 0, 0, buff.getWidth(), buff.getHeight(), null))
if(runnable == false)
{
System.out.println("Going to wait()");
this.wait();
}
}
catch(Exception ex)
{
System.out.println("Error");
}
}
}
}
}
}
Now I want to first first save the detected face in eigen faces and then recognize this face.
Can someone please help me through this I have thoroughly searched online for the Eigen face implementation in Java but couldn't able to find anything useful.
Please help me through this as I am new in OpenCV and this My project for College.
To build the OpenCV from source with contrib modules (which contain the org.opencv.face package for Java), see this question and answer .
After building the JAR with contrib modules, you can instantiate an EigenFaceRecognizer like this:
FaceRecognizer model = org.opencv.face.Face.createEigenFaceRecognizer();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.