Java 无法将FaceDetector解析为类型

Java 无法将FaceDetector解析为类型,java,opencv,exception,face,Java,Opencv,Exception,Face,我正在尝试构建一个用于图像中人脸检测的检测器。我使用OpenCV库,版本2.4.11 现在,我的源代码如下所示: import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.o

我正在尝试构建一个用于图像中人脸检测的检测器。我使用OpenCV库,版本2.4.11

现在,我的源代码如下所示:

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

public class DetectFaces {

    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("pic.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);
    }
}
现在每次调用
FaceDetector.class
时,我都会得到一个
FaceDetector无法解析为类型
异常

在进行此实现时,我遵循

欢迎提出任何建议。
谢谢

您忘记导入该类了吗?
还是在同一个文件夹中?

您忘记导入该类了吗?
还是在同一个文件夹中?

是否与
DetectFaces
类在同一个包中?您没有正确阅读并复制粘贴教程。您正在编写的类名为
FaceDetector
,而不是
DetectFaces
@图纳基。你说得对,谢谢。但这与你链接的主题有什么关系呢?因为它解释了所有可能导致你所犯错误的因素。其中一个原因是您键入的名称不正确。现在,在遵循您的建议并更改名称后,我在以下行中得到一个空指针异常:DetectFaces.class.getResource(“haarcascade_frontalface_alt.xml”)。getPath()是否与
DetectFaces
class在同一个包中?您没有阅读并复制粘贴,正确地阅读教程。您正在编写的类名为
FaceDetector
,而不是
DetectFaces
@图纳基。你说得对,谢谢。但这与你链接的主题有什么关系呢?因为它解释了所有可能导致你所犯错误的因素。其中一个原因是您键入的名称不正确。现在,在遵循您的建议并更改名称后,我在以下行中得到一个空指针异常:DetectFaces.class.getResource(“haarcascade_frontalface_alt.xml”)。getPath()