1

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.

lakshayg
  • 2,053
  • 2
  • 20
  • 34
  • This might help you out. http://stackoverflow.com/questions/18873017/where-to-get-the-jar-for-opencv – Anon Jul 13 '15 at 13:23
  • This tutorial shows how use java version of openCV under Netbeans. http://www.codeproject.com/Tips/717283/How-to-Use-OpenCV-with-Java-under-NetBeans-IDE I have configured my env in this way and it works like a charm. – Araneo Jul 13 '15 at 13:35

1 Answers1

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

lakshayg
  • 2,053
  • 2
  • 20
  • 34