running java class issue [closed]
I am following the popular DetectFaceDemo tutorial but I cant seem to run the packaged jar . DetectFaceDemo
I have placed the following files in their respect directories as shown below :
[root@hadoop1 java]# pwd
/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]#
[root@hadoop1 java]# ls
build.sbt DetectFaceDemo.java.orig HelloOpenCV.java lib project target
[root@hadoop1 java]#
[root@hadoop1 java]# ls lib
libopencv_java249.so opencv-249.jar
[root@hadoop1 java]#
[root@hadoop1 java]# cd ..
[root@hadoop1 main]# pwd
/root/openCV/opencv/samples/java/sbt/src/main
[root@hadoop1 main]# ls
java origscala resources
[root@hadoop1 main]# ls resources
AverageMaleFace.jpg img1.png img2.png lbpcascade_frontalface.xml lena.png
[root@hadoop1 main]#
I am getting error when I run the jar , I have a feeling the code is not picking up the image and the xml file from the src/main/resources folder ? I have though provided the absolute path to the resource folder.
[root@hadoop1 java]# sbt run
[info] Set current project to DetectFaceDemo (in build file:/root/openCV/opencv/samples/java/sbt/src/main/java/)
[info] Running HelloOpenCV
[info] Hello, OpenCV
[info]
[info] Running DetectFaceDemo
[error] Exception in thread "main" java.lang.NullPointerException
[error] at DetectFaceDemo.run(HelloOpenCV.java:20)
[error] at HelloOpenCV.main(HelloOpenCV.java:48)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 1 s, completed Nov 9, 2016 11:20:34 PM
the source code is below:
[root@hadoop1 java]# more HelloOpenCV.java
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("/root/openCV/opencv/samples/java/sbt/src/main/resources/lbpcascade_frontalface.xml").getPath());
Mat image = Highgui.imread(getClass().getResource("/root/openCV/opencv/samples/java/sbt/src/main/resources/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(Core ...
found the solution online : put the following in the code to finD the classpath and copy the "xml" and "png" files to this location .
System.out.println(System.getProperty("java.class.path"));