nu.pattern.OpenCV$UnsupportedPlatformException: Op

2020-05-06 10:42发布

问题:

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

回答1:

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.