Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

running java class issue

I cant seem to run this class anyway

> [root@hadoop1 scala-2.11]# ls classes 
> detectfacedemo_2.11-0.1-SNAPSHOT.jar 
> opencv-249.jar [root@hadoop1
> scala-2.11]# java -cp
> detectfacedemo_2.11-0.1-SNAPSHOT.jar:opencv-249.jar
> HelloOpenCV Hello, OpenCV Exception in
> thread "main"
> java.lang.UnsatisfiedLinkError: no
> opencv_java249 in java.library.path
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
>         at java.lang.System.loadLibrary(System.java:1088)
>         at HelloOpenCV.main(HelloOpenCV.java:47)
> [root@hadoop1 scala-2.11]# ls

running java class issue

I cant seem to run this class anyway

> [root@hadoop1 scala-2.11]#  # ls classes 
>  detectfacedemo_2.11-0.1-SNAPSHOT.jar 
>  opencv-249.jar [root@hadoop1
> scala-2.11]# 
# java -cp
> -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar:opencv-249.jar
>  HelloOpenCV Hello, OpenCV Exception in
>  thread "main"
>  java.lang.UnsatisfiedLinkError: no
>  opencv_java249 in java.library.path
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
>         at java.lang.System.loadLibrary(System.java:1088)
>         at HelloOpenCV.main(HelloOpenCV.java:47)
> [root@hadoop1 scala-2.11]# ls

my environment is as follows :

[root@hadoop1 ~]# java -version java version "1.7.0_111" OpenJDK Runtime Environment (rhel-2.6.7.2.el6_8-x86_64 u111-b01) OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)

echo $JAVA_HOME

/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64

which java /usr/bin/java

ls -al /usr/bin/java

lrwxrwxrwx 1 root root 22 Nov 9 15:24 /usr/bin/java -> /etc/alternatives/java

ls -al /etc/alternatives/javac

lrwxrwxrwx 1 root root 48 Nov 9 15:24 /etc/alternatives/javac -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac

echo $PATH

/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin/bin:/usr/hdp/2.5.0.0-1245/flume/bin: /usr/hdp/current/kafkabroker/bin/:/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin//bin: /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: /usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:/root/bin:/usr/hdp/current/kafka-broker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin: /usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin`

the source code is as follows :

[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("/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(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

running java class issue

I am following the popular DetectFaceDemo tutorial but I cant seem to run this class anyway the packaged jar .

first I tried Java

 # ls classes 
  detectfacedemo_2.11-0.1-SNAPSHOT.jar 
  opencv-249.jar [root@hadoop1

# java -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar:opencv-249.jar

  HelloOpenCV Hello, OpenCV Exception in
  thread "main"
  java.lang.UnsatisfiedLinkError: no
  opencv_java249 in java.library.path
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
>         at java.lang.System.loadLibrary(System.java:1088)
>         at HelloOpenCV.main(HelloOpenCV.java:47)

on the other hand if I run the jar file using sbt I get different error as follows : if you notice that its looking for a file "opencv_java249" where as the file that gets created as part of opencv installation is "opencv-249.jar" , and even if I make a copy of this jar with the expected name ,it still fails .

[root@hadoop1 java]# pwd
/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]# ls
build.sbt  DetectFaceDemo.java.orig  HelloOpenCV.java  lib  project  target
[root@hadoop1 java]# ls lib
opencv-249.jar
[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
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
[error]         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)

my environment is as follows :

[root@hadoop1 ~]# java -version java version "1.7.0_111" OpenJDK Runtime Environment (rhel-2.6.7.2.el6_8-x86_64 u111-b01)
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode) 

# echo $JAVA_HOME

/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64

$JAVA_HOME /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64 # which java /usr/bin/java

/usr/bin/java # ls -al /usr/bin/java

/usr/bin/java lrwxrwxrwx 1 root root 22 Nov 9 15:24 /usr/bin/java -> /etc/alternatives/java

# ls -al /etc/alternatives/javac

/etc/alternatives/javac lrwxrwxrwx 1 root root 48 Nov 9 15:24 /etc/alternatives/javac -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac

echo $PATH

/usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac #echo $PATH /usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin/bin:/usr/hdp/2.5.0.0-1245/flume/bin: /usr/hdp/current/kafkabroker/bin/:/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin//bin: /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: /usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:/root/bin:/usr/hdp/current/kafka-broker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin: /usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin`

/usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin`

the source code is as follows :

[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("/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(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

running java class issue

I am following the popular DetectFaceDemo tutorial but I cant seem to run the packaged jar .. DetectFaceDemo

first I tried Java

# java -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar:opencv-249.jar

  HelloOpenCV Hello, OpenCV Exception in
  thread "main"
  java.lang.UnsatisfiedLinkError: no
  opencv_java249 in java.library.path
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
>         at java.lang.System.loadLibrary(System.java:1088)
>         at HelloOpenCV.main(HelloOpenCV.java:47)

on the other hand if I run the jar file using sbt I get different error as follows : if you notice that its looking for a file "opencv_java249" where as the file that gets created as part of opencv installation is "opencv-249.jar" , and even if I make a copy of this jar with the expected name ,it still fails .

[root@hadoop1 java]# pwd
/root/openCV/opencv/samples/java/sbt/src/main/java
[root@hadoop1 java]# ls
build.sbt  DetectFaceDemo.java.orig  HelloOpenCV.java  lib  project  target
[root@hadoop1 java]# ls lib
opencv-249.jar
[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
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java249 in java.library.path
[error]         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)

my environment is as follows :

[root@hadoop1 ~]# java -version java version "1.7.0_111" OpenJDK Runtime Environment (rhel-2.6.7.2.el6_8-x86_64 u111-b01) 
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode) 

# echo $JAVA_HOME 
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64

# which java /usr/bin/java 

# ls -al /usr/bin/java 
lrwxrwxrwx 1 root root 22 Nov 9 15:24 /usr/bin/java -> /etc/alternatives/java 

# ls -al /etc/alternatives/javac 
lrwxrwxrwx 1 root root 48 Nov 9 15:24 /etc/alternatives/javac -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac


#echo $PATH 
/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin/bin:/usr/hdp/2.5.0.0-1245/flume/bin:
/usr/hdp/current/kafkabroker/bin/:/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin//bin:
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:
/usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:/root/bin:/usr/hdp/current/kafka-broker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:
/usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin`

the source code is as follows :

[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("/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(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

running java class issue

I am following the popular DetectFaceDemo tutorial but I cant seem to run the packaged jar . DetectFaceDemo

first I tried Java

# java -cp detectfacedemo_2.11-0.1-SNAPSHOT.jar:opencv-249.jar

  HelloOpenCV Hello, OpenCV Exception in
  thread "main"
  java.lang.UnsatisfiedLinkError: no
  opencv_java249 I have placed the following files in java.library.path
>         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
>         at java.lang.Runtime.loadLibrary0(Runtime.java:849)
>         at java.lang.System.loadLibrary(System.java:1088)
>         at HelloOpenCV.main(HelloOpenCV.java:47)

on the other hand if I run the jar file using sbt I get different error their respect directories as follows : if you notice that its looking for a file "opencv_java249" where as the file that gets created as part of opencv installation is "opencv-249.jar" , and even if I make a copy of this jar with the expected name ,it still fails .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.UnsatisfiedLinkError: no opencv_java249 in java.library.path
java.lang.NullPointerException
[error]         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)

my environment is as follows :

[root@hadoop1 ~]# java -version java version "1.7.0_111" OpenJDK Runtime Environment (rhel-2.6.7.2.el6_8-x86_64 u111-b01) 
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode) 

# echo $JAVA_HOME 
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64

# which java /usr/bin/java 

# ls -al /usr/bin/java 
lrwxrwxrwx 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 root root 22 s, completed Nov 9 15:24 /usr/bin/java -> /etc/alternatives/java 

# ls -al /etc/alternatives/javac 
lrwxrwxrwx 1 root root 48 Nov 9 15:24 /etc/alternatives/javac -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac


#echo $PATH 
/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin/bin:/usr/hdp/2.5.0.0-1245/flume/bin:
/usr/hdp/current/kafkabroker/bin/:/usr/hdp/2.5.0.0-1245/flume/bin:/usr/hdp/current/kafkabroker/bin//bin:
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:
/usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:/root/bin:/usr/hdp/current/kafka-broker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin:
/usr/hdp/current/kafkabroker/bin:/root/apachemaven-3.3.9/bin:/usr/hdp/2.5.0.0-1245/hive/bin:/opt/gradle/gradle-2.5/bin`
9, 2016 11:20:34 PM

the source code is as follows :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("/lbpcascade_frontalface.xml").getPath());
CascadeClassifier(getClass().getResource("/root/openCV/opencv/samples/java/sbt/src/main/resources/lbpcascade_frontalface.xml").getPath());
    Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath());
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.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}
[root@hadoop1 java]#