JavaCV + Android Studio + gradle- 可能吗? [英] JavaCV + Android Studio + gradle- possible?
问题描述
我正在尝试将 JavaCV 与 Android Studio 和 Gradle 结合使用.我写了这样的代码片段:
I'm trying use JavaCV with Android Studio and Gradle. I wrote such code fragment:
repositories {
mavenCentral()
maven {
url "http://maven2.javacv.googlecode.com/git/"
}
}
dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'com.googlecode.javacpp', name: 'javacpp', version: '0.5'
compile group: 'com.googlecode.javacv', name: 'javacv', version: '0.5'
}
我在外部库目录中看到了导入的库.所以我试着运行这个:
and I see imported libraries in dir External Libraries. So I tried to run this:
...
IplImage zdjecie=cvLoadImage(Environment.getExternalStorageDirectory().getPath()+ "/1.bmp");
cvSaveImage(Environment.getExternalStorageDirectory().getPath()
+ "/2.bmp", zdjecie);
...
我得到了错误:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniopencv_core: findLibrary returned null
...因为我不知道我应该如何处理 opencv(和其他)的 .so 文件.
...because I don't know what should I do with opencv's (and others) .so files.
那么我们应该如何在 Android Studio 中使用 JavaCV?
So how should we use JavaCV in Android Studio?
推荐答案
1.警告:这还不够!:
dependencies { compile group: 'org.bytedeco', name: 'javacv', version: '0.9'}
<小时>
2.对不起,我最近的解决方案是我张贴在这里,只告诉上面的行是错误的.但我检查了一下,这对我有用:
2. Sorry for mistake, my recent solution which
I posted here and which told only about line above was wrong. But I checked it out and this works for me:
a)添加依赖
dependencies {
compile group: 'org.bytedeco', name: 'javacv', version: '0.9'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.9-0.9', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.3-0.9', classifier: 'android-arm'
}
b) 在您的项目中创建 jniLibs 目录(与普通 libs 目录在同一级别.如果你有一些麻烦尝试将 jniLibs 移动到 app/src/main).
c) 将从 opencv-android-arm.jar 和 ffmpeg-android-arm.jar(或仅您真正需要的文件)中提取的所需 .so 文件添加到创建的 jniLibs 目录中.(如果你不知道什么我是说你可以从 JavaCV 页面 和里面下载 javacv-0.9-bin.zip你可以找到这两个 .jars).
b) Create jniLibs dir inside your project (on the same level as normal libs dir. If
you have some troubles try moving jniLibs to app/src/main).
c) Add required .so files extracted from opencv-android-arm.jar and ffmpeg-android-arm.jar (or only this files which you really need) to created jniLibs dir. (If you don't know about what
I'm talking you can download javacv-0.9-bin.zip from JavaCV page and inside it
you can find these 2 .jars).
这篇关于JavaCV + Android Studio + gradle- 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!