2013-06-16 3 views
2

나는이 samle을하려고 애썼다 : http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html 그러나 "Detected 0 faces"를 얻을 때마다. Windows 7 x64를 가지고 있고 모든 라이브러리 (opencv_java245.dll)가 연결되어 있습니다. 2.4.4 및 2.4.5 버전을 시도했지만 다른 이미지 형식 (png, jpg, bmp) 및 다른 이미지를 시도했지만 결과는 항상 "감지 된 0면"과 같습니다. 왜 이것이 작동하지 않을 수 있습니까?열린 CV 감지 자바 얼굴

답변

2

이 문제는이 같은 문제를 가지고

+0

.xml 및 .png 파일을 다른 위치로 이동해도 문제가 해결되지 않습니다. 그것은 여전히 ​​"Detected 0 faces"라는 오류 메시지를 표시합니다. 다른 대안이 있습니까? – San

2

컴퓨터의 다른 위치로 내 프로젝트에서 XML 파일을 전송함으로써 해결되었다, 나는 코드

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath()); 
//Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath()); 

CascadeClassifier faceDetector = new CascadeClassifier("E:/lbpcascade_frontalface.xml"); // With absolute location. 
Mat image = Highgui.imread("E:/lena.png"); // With absolute location. 

에에게 변경

다음 작동합니다.

원본 파일의 파일 위치에 문제가 있습니다.

String lbpcascadesFilePath = getClass().getResource("/lbpcascade_frontalface.xml").getPath(); 
// The fiel path you got is like /E:/Programmer/EclipseWorkspace/JavaProject/TestOpenCV/bin/lbpcascade_frontalface.xml 
System.out.println(lbpcascadesFilePath); 
// trim first '/', or the file cannot be read in Windows. 
lbpcascadesFilePath = lbpcascadesFilePath.substring(1); 
// Then it is OK to load the file. 
CascadeClassifier faceDetector = new CascadeClassifier(lbpcascadesFilePath); 

그런 다음 이미지 파일과 동일하게 작업하십시오.

String imgFilePath = getClass().getResource("/lena.png").getPath(); 
System.out.println(imgFilePath); // like /E:/Programmer/EclipseWorkspace/JavaProject/TestOpenCV/bin/lena.png 
imgFilePath = imgFilePath.substring(1); // trim first "/", or the file cannot be read in Windows. 
Mat image = Highgui.imread(imgFilePath);