我先用main方法测试了opencv发现是可以的,可是项目需求是放到tomcat上,可是不报错,就是出问题了,跑不下去,也没有异常。
这是我的vm option的配置,不知道有没有问题。
下面是我的代码,在执行到faceDetector = new CascadeClassifier(xmlfilePath);的时候就出错了,就执行不下去了,可是直接跑完又不报异常
public void run(String srcFileName) {
Mat image = null;
CascadeClassifier faceDetector = null;
String xmlfilePath = DetectFaceDemo.class.getClassLoader().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
try {
faceDetector = new CascadeClassifier(xmlfilePath);
image = Highgui.imread(srcFileName);
}catch (Exception e){
e.printStackTrace();
}
// 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.
// System.out.println(String.format("Writing %s", newPath));
// Highgui.imwrite(newPath, image);
}