import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.opencv.core.Core;
import org.opencv.core.CvType;
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;
import com.sun.javafx.css.FontFace;
import sun.font.FontScaler;
public class FaceRecognit {
private Mat image;
private CascadeClassifier classifier;
private MatOfRect matOfRect;
public FaceRecognit() {
super();
// TODO Auto-generated constructor stub
classifier = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1));
}
public void writeImage(Mat frame){
image=frame.clone();
matOfRect = new MatOfRect();
classifier.detectMultiScale(image, matOfRect);
for (Rect rect : matOfRect.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));
Core.circle(image, new Point(rect.x+rect.width/2, rect.y+rect.height/2), rect.width/2, new Scalar(0, 255, 0));
}
Core.putText(image, "Author:MarksLin@HFUT_XC", new Point(10, 25),2,1, new Scalar(0, 255, 0));
Core.putText(image, "Student ID:2012217166", new Point(10, 60),2,1, new Scalar(0, 255, 0));
String filename = "face.png";
Highgui.imwrite(filename, image);
}
@SuppressWarnings("deprecation")
public Image readImage(){
Image img=null;
try {
File file=new File(System.getProperty("user.dir")+"\\face.png");
img=ImageIO.read(file.toURL());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}
}
评论5