您的位置:首页 > 运维架构

openCV人脸识别

2014-05-15 15:43 399 查看
class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");

// Create a face detector from the cascade file in the resources
// directory.
// CascadeClassifier faceDetector = new
// CascadeClassifier(getClass().getResource("./lbpcascade_frontalface.xml").getPath());
CascadeClassifier faceDetector = new CascadeClassifier(
"F:\\opencv\\sources\\data\\lbpcascades\\lbpcascade_frontalface.xml");
// Mat image =
// Highgui.imread(getClass().getResource("/lena.png").getPath());
Mat image = Highgui.imread("F:\\android\\OpenCvTest\\person.jpg");

// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);

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

// Draw a bounding box around each face.
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));
}

// Save the visualized detection.
String filename = "test.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}

}

public class HelloOpenCV {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");

// Load the native library.
// System.loadLibrary("opencv");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new DetectFaceDemo().run();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: