2

I am new to java so maybe this is a little stupid. I have written a C++ code that uses OpenCV, now I want to convert it to Java. I used to compile C++ code in the terminal using

g++ main.cpp -o main `pkg-config opencv --libs` 

but I am unable to find a simple equivalent for java. I have tried using

javac -cp .:/usr/share/java/opencv.jar OpenCVDemo.java

but this gives a compilation error which looks like as if it was unable to link to the library. What I am looking for is a way to compile the opencv Java code in a way similar to the C++ method.

It would be helpful if someone could demonstrate how to compile this code

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class Hello
{
   public static void main( String[] args )
   {
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
      System.out.println( "mat = " + mat.dump() );
   }
}

I have only been able to find ways to configure an IDE to compile the program or using ant or sbt. What I want is a way to compile the program from the command line using only javac.

2

1 Answer 1

1

Finally figured it out myself

Compiling:

javac -cp .:/usr/share/OpenCV/java/opencv-248.jar Hello.java

Executing

java -cp .:/usr/share/OpenCV/java/opencv-248.jar Hello

I think I was using the incorrect jar file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.