4

JAVA言語を使ってOpenCVを学び始めました。http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.htmlから借用した非常に単純なコードを実行しようとしました

日食(JUNO)を使用しています。次のコードを実行すると

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;

//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
  public void run() {
    System.out.println("\nRunning DetectFaceDemo");

    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
    Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath());

    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);

    System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

    // Draw a bounding box around each face.
    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));
    }

    // Save the visualized detection.
    String filename = "faceDetection.png";
    System.out.println(String.format("Writing %s", filename));
    Highgui.imwrite(filename, image);
  }
}

public class HelloOpenCV {
  public static void main(String[] args) {
    System.out.println("Hello, OpenCV");

    // Load the native library.
    System.loadLibrary("opencv_java245");
    new DetectFaceDemo().run();
  }
}

私は得る

Hello, OpenCV

Running DetectFaceDemo
Exception in thread "main" java.lang.NullPointerException
    at DetectFaceDemo.run(HelloOpenCV.java:20)
    at HelloOpenCV.main(HelloOpenCV.java:48)

どこ **

20     CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
48    new DetectFaceDemo().run();

**

私はこの分野に不慣れで、このエラーに対処する方法がわかりません。あなたの助けが必要です。

4

2 に答える 2

0

フルパスを与える Mat image = Highgui.imread("/Users/test/workspace/OpenCV/bin/lena.png");

于 2013-08-03T00:41:15.037 に答える