0

I am trying to load opencv using the above method in a spring mvc project that has the following maven dependency:-

<dependency>
    <groupId>org.openpnp</groupId>
    <artifactId>opencv</artifactId>
    <version>3.2.0-0</version>
</dependency>

My code is:

static {
    nu.pattern.OpenCV.loadShared();
    System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}

Any help in solving this error will be appreciated. Thanks in advance

2
  • Just some more problem that i am facing. this process works fine in a simple java application project. Commented Jan 30, 2018 at 9:16
  • Check out this answer - stackoverflow.com/a/64799844/9640177 if getting runtime error Commented Nov 12, 2020 at 7:53

1 Answer 1

0

Solved this one..

Based on a stack post I included the following lines of code to load the library..

static{
        String osName = System.getProperty("os.name");
        String opencvpath = System.getProperty("user.dir");
        if(osName.startsWith("Windows")) {
            int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
            if(bitness == 32) {
                opencvpath=opencvpath+"\\opencv\\x86\\";
            }
            else if (bitness == 64) { 
                opencvpath=opencvpath+"\\opencv\\x64\\";
            } else { 
                opencvpath=opencvpath+"\\opencv\\x86\\"; 
            }           
        } 
        else if(osName.equals("Mac OS X")){
            opencvpath = opencvpath+"Your path to .dylib";
        }
        System.out.println(opencvpath);
        System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
        //nu.pattern.OpenCV.loadShared();
        //System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
    }

On checking the various parameters it was found that os.name returned WINDOWS. user.dir returned the eclipse root directory and the sun.arch.data.model returned 64. Based on this code I then created the necessary folders in eclipse root directory and pasted the latest opencv dll over there. But now the other problem was that the code was searching for an older version of the dll and wasnt accepting this newer version.
The problem was due to the fact that an inbuilt library was using an older version of opencv and i was trying to use the latest version. So I had to exclude that previous version of opencv from the maven dependency of that library and tada the problem was solved.

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.