JavaCV cvLoad返回null

时间:2016-07-28 02:05:02

标签: java opencv computer-vision javacv face-recognition

我在我的项目中使用javaCV信封,当我尝试使用haarcascade_frontalface_default.xml函数从xml(cvLoad)加载Haar级联时,我从中获取null。 Threre没有错误,仅null而不是Pointer

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.opencv_core.*;
import org.bytedeco.javacpp.opencv_objdetect.CvHaarClassifierCascade;
import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_imgcodecs.*;
import static org.bytedeco.javacpp.opencv_objdetect.*;

URI haarCascadeResource = getClass().getResource(
                "/haarcascades/haarcascade_frontalface_default.xml").toURI();
String haarCascadePath = Paths.get(haarCascadeResource).toAbsolutePath().normalize().toString();    
Pointer pointerToCascade = cvLoad(haarCascadePath);
this.faceHaarCascade = new CvHaarClassifierCascade(pointerToCascade);

pointerToCascadenullthis.faceHaarCascade也为null

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

Pointer pointerToCascade = cvLoad(Put the directory of the haarcascade_frontalface_default.xml);
this.faceHaarCascade = new CvHaarClassifierCascade(pointerToCascade);