public class FaceDetector {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning FaceDetector");
CascadeClassifier faceDetector = new CascadeClassifier(FaceDetector.class.getResource("\\haarcascade_frontalface_alt.xml").getPath());
Mat image = Highgui.imread(FaceDetector.class.getResource("abc.jpg").getPath());
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
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));
}
String filename = "ouput.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
이것은 내 오류 이미지입니다.
null 포인트 예외 오류가 발생했습니다. 해결 방법 나는 또한 동일한 문제를 전체 경로를 제공하려고 노력합니다. 제발 도와주세요.
에 절대 경로를 전달해야합니다 CascadeClassifier
. 예를 들면 :
CascadeClassifier faceDetector = new CascadeClassifier("D:\\haarcascade_frontalface_alt.xml");
그리고 이미지를 읽고 쓸 때도 똑같이하십시오. 이것은 유선이지만이 경우 파일을 읽을 수 없다는 것은 사실입니다. 저도 마찬가지 였고 제가 해결했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다