Ask Your Question
0

Opencv Java MatOfFloat4 object cannot be created via constructor

asked 2016-11-15 04:18:00 -0500

Raki gravatar image

I've a class which has the following variable:

private MatOfFloat4 horizonLine = new MatOfFloat4();

which I later on pass into a function as follows:

Imgproc.fitLine(tmpPoints, horizonLine, Imgproc.CV_DIST_L1, 0, 0.01, 0.01);

However, I get an error saying that:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
    at org.opencv.core.Mat.n_Mat(Native Method)
    at org.opencv.core.Mat.<init>(Mat.java:24)
    at org.opencv.core.MatOfFloat4.<init>(MatOfFloat4.java:12)
    at obstacleDetector.HorizonDetector.<init>(HorizonDetector.java:327)
    at obstacleDetector.HorizonDetector.getInstance(HorizonDetector.java:59)
    at obstacleDetector.Detector.<clinit>(Detector.java:28)

which directs me to the initialization of the variable. Why can't OpenCV intialize this variable? What is wrong?

P.S: If it matters, the class which I place this variable, is a Singleton class:

public static HorizonDetector getInstance() {
        if (_instance == null) {
            _instance = new HorizonDetector();
        } else {
            System.out.println("Same instance of the Horizon Detector-Singleton class already exists.");
        }
        return _instance;
    }

Any thoughts?

edit retag flag offensive close merge delete

Comments

java.lang.UnsatisfiedLinkError -- are you sure, the opencv_java.so is already loaded, when you try to run your code ?

berak gravatar imageberak ( 2016-11-15 05:20:24 -0500 )edit

The code runs when I comment out the initialization part of the MatOfFloat4 object. So the problem is not about the library. Additionally, I have System.loadLibrary(Core.NATIVE_LIBRARY_NAME); as well.

Raki gravatar imageRaki ( 2016-11-15 05:23:41 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-17 05:46:54 -0500

Raki gravatar image

Ok, so you cannot create this object with a constructor like that apparently, so what I did was to use fromList() function and getting the values from an ArrayList that I had. Solved the problem.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-15 04:18:00 -0500

Seen: 82 times

Last updated: Nov 17 '16