3

I compiled OpenCV on Linux (Mint 19 Tara), I used this tutorial: https://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html

Then I tried to use the library like that: https://docs.opencv.org/3.4/d1/d0a/tutorial_java_eclipse.html

But in the imports I get an error: "The import org cannot be resolved."

What can I do wrong? Here is the code I used:

package com.thegergo02.facedetection;

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() );
   }
}

Package Explorer screenshot

The compile was successful, no errors, i had Java, Ant, everything.

Java version: jdk-11.0.1 Ant version: 1.10.3

7
  • As the error itself say the package library org cannot be resolved means it is not installed properly. try using System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Commented Nov 1, 2018 at 20:08
  • But I did everything the tutorial(s) said. What can I do to resolve the issue? Commented Nov 1, 2018 at 20:10
  • Where did I have to put that line? Because it's in the main function already. Commented Nov 1, 2018 at 20:13
  • Did you run 'make install' to get a kind of SDK in the <build>/install folder? Did you tried 'Fix project properties' for the OpenCV library project? Commented Nov 1, 2018 at 20:16
  • Where do I find the 'Fix project properties'? I try recompiling it with that command. Commented Nov 1, 2018 at 20:17

1 Answer 1

5

In the default package, delete the file module-info.java.

The tutorial is based on Java 6 without the Java Platform Module System (JPMS) in mind which can (but does not have to) be used since Java 9.

If using JPMS, the dependency to the OpenCV module must be explicitly defined in the module-info.java file to make it accessible.

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

1 Comment

IT WORKED! Thank you, I can't believe this is the solution to a problem I could not fix in 1 day.

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.