gpt4 book ai didi

java - FaceDetector 无法解析为类型

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:27 26 4
gpt4 key购买 nike

<分区>

我正在尝试构建用于图像中人脸检测的检测器。我使用 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 cannot be resolved to a type 异常。

在处理此实现时,我正在关注 tutorial

欢迎提出任何建议。谢谢你

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com