Ask Your Question

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>(
    at org.opencv.core.MatOfFloat4.<init>(
    at obstacleDetector.HorizonDetector.<init>(
    at obstacleDetector.HorizonDetector.getInstance(
    at obstacleDetector.Detector.<clinit>(

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


java.lang.UnsatisfiedLinkError -- are you sure, the 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

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

Question Tools

1 follower


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

Seen: 108 times

Last updated: Nov 17 '16