Javacv: java cv 1.5.2 openblas

Created on 9 Nov 2019  路  36Comments  路  Source: bytedeco/javacv

Hi

I just update javacv from 1.5.0 to 1.5.2.

Previously i am using ffmpeg and opencv libs only, but now i found opencv is denpend on openblas, so i have to include openblas in my libs also?

bug question

All 36 comments

Yes, that's correct, we need OpenBLAS.

Thanks, do you have any suggestions to reduce the size of library.

Because i am using this great library to develop mobiel apps, so the size is important!

OpenCV can't use OpenBLAS on Android or iOS anyway, so no need to include it.

Hi the problem is if i don't include it, it will will throw exception when i am using :

CV_RGB((double) Color.red(bgColor), (double) Color.green(bgColor), (double) Color.blue(bgColor));

Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bytedeco/openblas/presets/openblas;
2019-11-09 13:46:23.186 29504-30155/com.. I/ps.: at java.lang.annotation.Annotation java.lang.Class.getDeclaredAnnotation(java.lang.Class) (Class.java:-2)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at java.lang.annotation.Annotation java.lang.Class.getAnnotation(java.lang.Class) (Class.java:2488)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at boolean org.bytedeco.javacpp.Loader.checkPlatform(java.lang.Class, java.util.Properties) (Loader.java:964)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at java.lang.String org.bytedeco.javacpp.Loader.load(java.lang.Class, java.util.Properties, boolean) (Loader.java:1080)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at java.lang.String org.bytedeco.javacpp.Loader.load() (Loader.java:1042)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at void org.bytedeco.opencv.global.opencv_core.() (opencv_core.java:15)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at org.bytedeco.opencv.opencv_core.CvScalar org.bytedeco.opencv.global.opencv_core.cvScalar(double, double, double, double) (opencv_core.java:-2)
2019-11-09 13:46:23.186 29504-30155/com. I/ps.: at org.bytedeco.opencv.opencv_core.CvScalar org.bytedeco.opencv.helper.opencv_core.CV_RGB(double, double, double) (opencv_core.java:32)

@saudet can you plz give me an suggestion ? thanks.

Ah, yes, the presets do load OpenBLAS anyway... We should change that.

@saudet so u mean i have to wait for the next version to fix? thanks

Hi @saudet do you mind let me know how to remove openlab reference? e.g which file/files?

But in the opencv code, there are quite a lot of java references.

image

You can ignore the files in src/gen, those get regenerated at build time.

I forgot to mention that we should modify the pom.xml files as well, but that should be it:
https://github.com/bytedeco/javacpp-presets/blob/master/opencv/pom.xml
https://github.com/bytedeco/javacpp-presets/blob/master/opencv/platform/pom.xml

But i did see some error because of this:
image

Ok, try to remove the files from the src/gen subdirectory.

Thanks, I can build openc and ffmpeg now, and it works.

Btw, may i know how to build javacv? Just encounter some java build error.

JavaCV doesn't contain any native code, so a simple mvn clean install works.

Hi @saudet,

I'm using javaCV version 1.5.3, but I also receive the same error:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bytedeco/openblas/presets/openblas;
        at java.lang.Class.getDeclaredAnnotation(Native Method)
        at java.lang.Class.getAnnotation(Class.java:2488)
        at org.bytedeco.javacpp.Loader.checkPlatform(Loader.java:964)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1080)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1058)
        at org.bytedeco.javacv.OpenCVFrameConverter.<clinit>(OpenCVFrameConverter.java:43)

I saw that you suggested removing the src/gen directory, but I'm unable to find that directory.
Can you help me?

@DonyellFonk As per above, you'll need to include the presets for OpenBLAS in the class path.

@saudet

OpenCV can't use OpenBLAS on Android or iOS anyway, so no need to include it.

Sorry, I forgot to mention it, I'm using this library in an Android app. Do I still need to include OpenBLAS?

Yes, unless you rebuild from source as per @xiaos

Hi @saudet , i have one question, after i built the ffmpeg, where can i find the ffmpeg header files?

They should be under ffmpeg/cppbuild//include

got it, thanks!

Hello again!

In question #1527 you wrote me that I should add OpenBLAS dependency. But judging by this thread in the case of development for android, should I remove all dependencies on openblas (as it is said here)?

Do you mean here to add javacv as a separate module (not through dependencies in gradle) and remove all mentions of openblas from there?

Any of those options work fine, but if you're just trying to get JavaCV
running, the platform plugin of Gradle JavaCPP is easiest:
https://github.com/bytedeco/gradle-javacpp#the-platform-plugin

Hello!

I tried your solution (with the platform plugin of Gradle JavaCPP). It works with versions like this:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'org.bytedeco.gradle-javacpp-platform' version "1.5.4"
}

ext {
    javacppPlatform = 'android-arm,android-arm64'
}

android { ... }

dependencies {

...

implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.2'
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.7-1.5.2'
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.7-1.5.2', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.7-1.5.2', classifier: "android-arm64"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.2-1.5.2'
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.2-1.5.2', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.1.2-1.5.2', classifier: "android-arm64"

}

But with this versions:

implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.4'

implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.10-1.5.4'
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.10-1.5.4', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'openblas', version: '0.3.10-1.5.4', classifier: "android-arm64"

implementation group: 'org.bytedeco', name: 'opencv', version: '4.4.0-1.5.4'
implementation group: 'org.bytedeco', name: 'opencv', version: '4.4.0-1.5.4', classifier: "android-arm"
implementation group: 'org.bytedeco', name: 'opencv', version: '4.4.0-1.5.4', classifier: "android-arm64"

I got this this type of error:

More than one file was found with OS independent path 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'.

I tried all the approaches from #353, but none of them suited me :(

Those files are not needed by Android. You can exclude them.

I tried to exclude them like this:

packagingOptions {
      exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
}

And like this:

implementation (group: 'org.bytedeco', name: 'javacpp', version: '1.5.4') {
        exclude group: 'org.bytedeco.javacpp', module: 'android-arm64'
}

In both cases the error did not go anywhere

You need to add it in the android { } block, like this: https://stackoverflow.com/a/47509465/523744

Ofc i add it to android { } block, like this:

android {

    ...

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude("META-INF/*.kotlin_module")
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
    }
}

Ok, good, so that works. You'll need to do the same for the other .json files too.

I apologize for the understatement. I meant that this type of exclude did not work for me.

I'm pretty sure it works, you just have to make sure to exclude all the JSON files. There's more than one of them.

I try to exclude this JSON files:

exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
exclude 'META-INF/native-image/android-arm/jnijavacpp/jni-config.json'
exclude 'META-INF/native-image/android-x86/jnijavacpp/jni-config.json'
exclude 'META-INF/native-image/android-x86_64/jnijavacpp/jni-config.json'

But i still have this type of error:

More than one file was found with OS independent path 'META-INF/native-image/android-x86_64/jnijavacpp/jni-config.json'

I'm out of ideas for other files to exclude...

Maybe the paths have to start with "/"? According to the documentation here, for example, that looks necessary:
https://google.github.io/android-gradle-dsl/3.2/com.android.build.gradle.internal.dsl.PackagingOptions.html
In any case, this is an issue with Android, so be sure to ask upstream! Thank you

I solved the problem.

  • First of all, packagingOptions { exclude } did't work for me, because i have multimodule project and add exclude not for app module.

  • Secondly, we must exclude such a list of files (jni-config.json & reflect-config.json):

packagingOptions {
        exclude 'META-INF/native-image/android-arm/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/reflect-config.json'
    }
  • And finally, an example of how a gradle file (app module) should be:
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'org.bytedeco.gradle-javacpp-platform' version "1.5.4"
}

android {

    packagingOptions {
        exclude 'META-INF/native-image/android-arm/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/reflect-config.json'
    }

    ...

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

def openblas = '0.3.10'
def javacv = "1.5.4"
def opencv = "4.4.0"

dependencies {

   ...

   api "org.bytedeco:openblas:${openblas}-${javacv}",
   api "org.bytedeco:openblas:${openblas}-${javacv}:android-arm",
   api "org.bytedeco:openblas:${openblas}-${javacv}:android-arm64",
   api "org.bytedeco:opencv:${opencv}-${javacv}",
   api "org.bytedeco:opencv:${opencv}-${javacv}:android-arm",
   api "org.bytedeco:opencv:${opencv}-${javacv}:android-arm64"
}
  • Secondly, we must exclude such a list of files (jni-config.json & reflect-config.json):

Something like exclude 'META-INF/native-image/**' probably works just as fine though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

The-Crocop picture The-Crocop  路  5Comments

y4nnick picture y4nnick  路  3Comments

kongqw picture kongqw  路  4Comments

SenudaJayalath picture SenudaJayalath  路  3Comments

Bahramudin picture Bahramudin  路  3Comments