根据OpenCV4Android的文档一步步往下走。
导入这些项目后,出现如下的构建问题:
* Build of configuration Default for project OpenCV Tutorial 2 - Mixed Processing *
/ndk-build.cmd
Cannot run program “/ndk-build.cmd”: Unknown reason
Error: Program “/ndk-build.cmd” is not found in PATH
PATH=[/home/vonzhou/software/android-sdk-linux/platform-tools:/home/vonzhou/software/android-sdk-linux/tools:/home/vonzhou/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games]
* Build Finished *
主要原因是:
Warning After the initial import, on a non-Windows (Linux and Mac OS) operating system Eclipse will still show build errors for applications with native C++ code. To resolve the issues, please do the following:
Open Project Properties -> C/C++ Build, and replace “Build command” text to “${NDKROOT}/ndk-build” (remove .cmd at the end).
当然要确保安装了NDK。
The Native Development Kit (NDK) is a set of tools that allow you to leverage C and C++ code in your Android apps. You can use it either to build from your own source code, or to take advantage of existing prebuilt libraries.
经过反复折腾,从opencv for android sdk中导入的project没有错误了
如果这时你运行那些实例,(在AVD中)你会被告知“OpenCV Manager package was not installed ….” ,SO 我们需要安装那个apk!(那个apk在哪儿?在OpenCV-android-sdk/apk下面,选择对应的版本,然后copy到android sdk platformt-tools下面,运行adb进行安装,这样就安装到了我们的AVD中),看图:
利用javah工具通过Class文件的本地函数声明,生成.h头文件,这里得到 com_example_test_ImageProc.h
Usage: javah [options]
where [options] include:
-help Print this help message and exit
-classpath Path from which to load classes
-bootclasspath Path from which to load bootstrap classes
-dOutput directory
-o Output file (only one of -d or -o may be used)
-jni Generate JNI-style header file (default)
-version Print version information
-verbose Enable verbose output
-force Always write output files
are specified with their fully qualified names (for
instance, java.lang.Object).
把这个头文件(可以重命名)放到我们的jni folder下(将在这里写C/C++代码),接下来会构建ImageProc.c 已经makefile文件。
接下来使用ndk-build命令来得到共享库文件(要切换到jni folder下面哦),比如libabc.so,所以你在Java程序中能够System.load这个module!
然后运行这个Android app, 显然遇到了问题
06-16 10:53:32.354: E/AndroidRuntime(832): FATAL EXCEPTION: main
06-16 10:53:32.354: E/AndroidRuntime(832): java.lang.UnsatisfiedLinkError: Cannot load library: load_library(linker.cpp:745): library “image_proc” not found
06-16 10:53:32.354: E/AndroidRuntime(832): at java.lang.Runtime.load(Runtime.java:340)
06-16 10:53:32.354: E/AndroidRuntime(832): at java.lang.System.load(System.java:521)
06-16 10:53:32.354: E/AndroidRuntime(832): at com.example.test.MainActivity1.onManagerConnected(MainActivity.java:29) 06-16 10:53:32.354: E/AndroidRuntime(832): at org.opencv.android.AsyncServiceHelper1.onManagerConnected(MainActivity.java:29)06?1610:53:32.354:E/AndroidRuntime(832):atorg.opencv.android.AsyncServiceHelper 1.onServiceConnected(AsyncServiceHelper.java:318)
06-16 10:53:32.354: E/AndroidRuntime(832): at android.app.LoadedApkServiceDispatcher.doConnected(LoadedApk.java:1101) 06-16 10:53:32.354: E/AndroidRuntime(832): at android.app.LoadedApkServiceDispatcher.doConnected(LoadedApk.java:1101)06?1610:53:32.354:E/AndroidRuntime(832):atandroid.app.LoadedApk ServiceDispatcherRunConnection.run(LoadedApk.java:1118) 06-16 10:53:32.354: E/AndroidRuntime(832): at android.os.Handler.handleCallback(Handler.java:725) 06-16 10:53:32.354: E/AndroidRuntime(832): at android.os.Handler.dispatchMessage(Handler.java:92) 06-16 10:53:32.354: E/AndroidRuntime(832): at android.os.Looper.loop(Looper.java:137) 06-16 10:53:32.354: E/AndroidRuntime(832): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-16 10:53:32.354: E/AndroidRuntime(832): at java.lang.reflect.Method.invokeNative(Native Method) 06-16 10:53:32.354: E/AndroidRuntime(832): at java.lang.reflect.Method.invoke(Method.java:511) 06-16 10:53:32.354: E/AndroidRuntime(832): at com.android.internal.os.ZygoteInitRunConnection.run(LoadedApk.java:1118)06?1610:53:32.354:E/AndroidRuntime(832):atandroid.os.Handler.handleCallback(Handler.java:725)06?1610:53:32.354:E/AndroidRuntime(832):atandroid.os.Handler.dispatchMessage(Handler.java:92)06?1610:53:32.354:E/AndroidRuntime(832):atandroid.os.Looper.loop(Looper.java:137)06?1610:53:32.354:E/AndroidRuntime(832):atandroid.app.ActivityThread.main(ActivityThread.java:5041)06?1610:53:32.354:E/AndroidRuntime(832):atjava.lang.reflect.Method.invokeNative(NativeMethod)06?1610:53:32.354:E/AndroidRuntime(832):atjava.lang.reflect.Method.invoke(Method.java:511)06?1610:53:32.354:E/AndroidRuntime(832):atcom.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:793)
06-16 10:53:32.354: E/AndroidRuntime(832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-16 10:53:32.354: E/AndroidRuntime(832): at dalvik.system.NativeStart.main(Native Method)
虽然发生UnsatisfiedLinkError的原因很多,但是这里的症结是那个 library “image_proc” not found ,那么你为何不找找刚才build得到的libimage_proc.so文件在哪儿呢?通过上图可以看到在该工程下libs目录中:
vonzhou@CHOWN:~/GitHub/AndroidProject/Test$ ls libs/armeabi-v7a/
libimage_proc.so
*为何跑到了armeabi-v7a下面? 因为APP_ABI := armeabi-v7a。
FUCK!为何文件存在,还是说找不到??
思考,思考哪里出了问题?怎么可能,完全不知道这一切是如何发生的好吗!
好吧!上面完全是根据网上的教程画图,忽略了本质!本质就是小即是大。
只能从头开始,你试过自己通过JNI调用简单的本地方法实现吗?这其中也是遇到各种问题
(1)error: ‘JNIEXPORT’ does not name a type
需要引入头文件(JNIEXPORT定义在jni.h中)
(2)error: base operand of ‘->’ has non-pointer type ‘JNIEnv {aka _JNIEnv}’
注意是C还是C++参考这里
//C
return (*env)->NewStringUTF(env, "Hello from JNI !");
//C++
return env->NewStringUTF("Hello from JNI !");
(3)要在Android.mk中include OpenCV.mk,否则出错
[armeabi-v7a] Compile++ thumb: native-util <= native-util.cpp
/home/vonzhou/GitHub/AndroidProject/Test/jni/native-util.cpp:1:33: fatal error: opencv2/core/core.hpp: No such file or directory
#include
LOCAL_PATH:= $(call my-dir)
$(warning $(LOCAL_PATH))
include $(CLEAR_VARS)
include /opt/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
#LOCAL_MODULE := imageproc
#LOCAL_SRC_FILES := ImageProc.cpp
LOCAL_SRC_FILES := native-util.cpp
LOCAL_MODULE := native-util
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
库加载代码:
public class MainActivity extends Activity implements OnClickListener {
private TextView tv;
private Button btn;
private ImageView imageView;
private Bitmap bitmap;
private static final String TAG = "Sample::Feature Detection::Activity";
// callback for handling the connection status
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
try {
Log.i(TAG, "OpenCV loaded successfully");
System.load("native-util");
} catch (Exception e) {
e.printStackTrace();
}
}
default:
super.onManagerConnected(status);
}
}
};
public void onResume() {
super.onResume();
// Loads and initializes OpenCV library using OpenCV Engine service.
// You can choose it.
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_11, this,
mLoaderCallback);
}
}
Oops~!出错:
06-17 02:38:42.371: E/AndroidRuntime(1445): FATAL EXCEPTION: main
06-17 02:38:42.371: E/AndroidRuntime(1445): java.lang.UnsatisfiedLinkError: Cannot load library: load_library(linker.cpp:745): library “native-util” not found
06-17 02:38:42.371: E/AndroidRuntime(1445): at java.lang.Runtime.load(Runtime.java:340)
06-17 02:38:42.371: E/AndroidRuntime(1445): at java.lang.System.load(System.java:521)
06-17 02:38:42.371: E/AndroidRuntime(1445): at com.example.test.MainActivity1.onManagerConnected(MainActivity.java:34)06?1702:38:42.371:E/AndroidRuntime(1445):atorg.opencv.android.AsyncServiceHelper 1.onServiceConnected(AsyncServiceHelper.java:318)
06-17 02:38:42.371: E/AndroidRuntime(1445): at android.app.LoadedApkServiceDispatcher.doConnected(LoadedApk.java:1101)06?1702:38:42.371:E/AndroidRuntime(1445):atandroid.app.LoadedApk ServiceDispatcherRunConnection.run(LoadedApk.java:1118)06?1702:38:42.371:E/AndroidRuntime(1445):atandroid.os.Handler.handleCallback(Handler.java:725)06?1702:38:42.371:E/AndroidRuntime(1445):atandroid.os.Handler.dispatchMessage(Handler.java:92)06?1702:38:42.371:E/AndroidRuntime(1445):atandroid.os.Looper.loop(Looper.java:137)06?1702:38:42.371:E/AndroidRuntime(1445):atandroid.app.ActivityThread.main(ActivityThread.java:5041)06?1702:38:42.371:E/AndroidRuntime(1445):atjava.lang.reflect.Method.invokeNative(NativeMethod)06?1702:38:42.371:E/AndroidRuntime(1445):atjava.lang.reflect.Method.invoke(Method.java:511)06?1702:38:42.371:E/AndroidRuntime(1445):atcom.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:793)
06-17 02:38:42.371: E/AndroidRuntime(1445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-17 02:38:42.371: E/AndroidRuntime(1445): at dalvik.system.NativeStart.main(Native Method)
so库明显存在,为何说找不到呢?难道加载库的函数有什么不为人知的地方?
好吧,System.load 和 System.loadLibrary 是不同的,不同!修改代码
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
try {
Log.i(TAG, "OpenCV loaded successfully");
System.loadLibrary("native-util");
} catch (Exception e) {
e.printStackTrace();
}
}
default:
super.onManagerConnected(status);
}
}
};
是的,这个错误没了,但是运行失败:
06-17 02:47:11.041: E/AndroidRuntime(1624): FATAL EXCEPTION: main
06-17 02:47:11.041: E/AndroidRuntime(1624): java.lang.UnsatisfiedLinkError: Couldn’t load native-util from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.test-2.apk,libraryPath=/data/app-lib/com.example.test-2]: findLibrary returned null
06-17 02:47:11.041: E/AndroidRuntime(1624): at java.lang.Runtime.loadLibrary(Runtime.java:365)
06-17 02:47:11.041: E/AndroidRuntime(1624): at java.lang.System.loadLibrary(System.java:535)
06-17 02:47:11.041: E/AndroidRuntime(1624): at com.example.test.MainActivity1.onManagerConnected(MainActivity.java:35)06?1702:47:11.041:E/AndroidRuntime(1624):atorg.opencv.android.AsyncServiceHelper 1.onServiceConnected(AsyncServiceHelper.java:318)
06-17 02:47:11.041: E/AndroidRuntime(1624): at android.app.LoadedApkServiceDispatcher.doConnected(LoadedApk.java:1101)06?1702:47:11.041:E/AndroidRuntime(1624):atandroid.app.LoadedApk ServiceDispatcherRunConnection.run(LoadedApk.java:1118)06?1702:47:11.041:E/AndroidRuntime(1624):atandroid.os.Handler.handleCallback(Handler.java:725)06?1702:47:11.041:E/AndroidRuntime(1624):atandroid.os.Handler.dispatchMessage(Handler.java:92)06?1702:47:11.041:E/AndroidRuntime(1624):atandroid.os.Looper.loop(Looper.java:137)06?1702:47:11.041:E/AndroidRuntime(1624):atandroid.app.ActivityThread.main(ActivityThread.java:5041)06?1702:47:11.041:E/AndroidRuntime(1624):atjava.lang.reflect.Method.invokeNative(NativeMethod)06?1702:47:11.041:E/AndroidRuntime(1624):atjava.lang.reflect.Method.invoke(Method.java:511)06?1702:47:11.041:E/AndroidRuntime(1624):atcom.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:793)
06-17 02:47:11.041: E/AndroidRuntime(1624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-17 02:47:11.041: E/AndroidRuntime(1624): at dalvik.system.NativeStart.main(Native Method)
解决方法是不指定库的存放路径(这些东西为了兼容各种硬件,搞得各种复杂~~),修改Application.mk如下,这样得到的库默认存放在libs/armeabi 下面
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
#APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
好了!到达这一步的却不容易,只是让Java中正确加载了Opencv,以及知道如何如何写本地代码,还没牵扯如何调用opencv API来进行实际的图像处理.到这一步的日志输出也值得看看。
06-17 03:25:58.930: D/OpenCVManager/Helper(2647): Service connection created
06-17 03:25:58.950: D/OpenCVManager/Helper(2647): Trying to get library path
06-17 03:25:59.241: D/OpenCVManager/Helper(2647): Trying to get library list
06-17 03:25:59.491: D/OpenCVManager/Helper(2647): Library list: “”
06-17 03:25:59.491: D/OpenCVManager/Helper(2647): First attempt to load libs
06-17 03:25:59.491: D/OpenCVManager/Helper(2647): Trying to init OpenCV libs
06-17 03:25:59.501: D/OpenCVManager/Helper(2647): Trying to load library /data/app-lib/org.opencv.engine-1/libopencv_java.so
06-17 03:25:59.511: D/dalvikvm(2647): Trying to load lib /data/app-lib/org.opencv.engine-1/libopencv_java.so 0x40ce1fb8
06-17 03:25:59.711: D/dalvikvm(2647): Added shared lib /data/app-lib/org.opencv.engine-1/libopencv_java.so 0x40ce1fb8
06-17 03:25:59.711: D/OpenCVManager/Helper(2647): OpenCV libs init was ok!
06-17 03:25:59.711: D/OpenCVManager/Helper(2647): First attempt to load libs is OK
06-17 03:25:59.731: I/OpenCVManager/Helper(2647): General configuration for OpenCV 2.4.11 =====================================
06-17 03:25:59.731: I/OpenCVManager/Helper(2647): Version control: 2.4.11-dirty
06-17 03:25:59.741: I/OpenCVManager/Helper(2647): Platform:
06-17 03:25:59.741: I/OpenCVManager/Helper(2647): Host: Linux 3.2.0-77-generic x86_64
06-17 03:25:59.741: I/OpenCVManager/Helper(2647): Target: Linux 1 armv5te
06-17 03:25:59.751: I/OpenCVManager/Helper(2647): CMake: 2.8.12.1
06-17 03:25:59.751: I/OpenCVManager/Helper(2647): CMake generator: Ninja
06-17 03:25:59.761: I/OpenCVManager/Helper(2647): CMake build tool: /usr/local/bin/ninja
06-17 03:25:59.761: I/OpenCVManager/Helper(2647): Configuration: Release
06-17 03:25:59.771: I/OpenCVManager/Helper(2647): C/C++:
06-17 03:25:59.771: I/OpenCVManager/Helper(2647): Built as dynamic libs?: NO
06-17 03:25:59.771: I/OpenCVManager/Helper(2647): C++ Compiler: /usr/bin/ccache /opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ (ver 4.6)
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): C++ flags (Release): -fexceptions -frtti -fpic -Wno-psabi –sysroot=/opt/android-ndk-r8c/platforms/android-8/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): C++ flags (Debug): -fexceptions -frtti -fpic -Wno-psabi –sysroot=/opt/android-ndk-r8c/platforms/android-8/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -O0 -DDEBUG -D_DEBUG
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): C Compiler: /usr/bin/ccache /opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): C flags (Release): -fexceptions -fpic -Wno-psabi –sysroot=/opt/android-ndk-r8c/platforms/android-8/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): C flags (Debug): -fexceptions -fpic -Wno-psabi –sysroot=/opt/android-ndk-r8c/platforms/android-8/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fdata-sections -ffunction-sections -Wa,–noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -O0 -DDEBUG -D_DEBUG
06-17 03:25:59.781: I/OpenCVManager/Helper(2647): Linker flags (Release): -Wl,–no-undefined -Wl,–gc-sections -fuse-ld=gold -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
06-17 03:25:59.791: I/OpenCVManager/Helper(2647): Linker flags (Debug): -Wl,–no-undefined -Wl,–gc-sections -fuse-ld=gold -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
06-17 03:25:59.791: I/OpenCVManager/Helper(2647): Precompiled headers: NO
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): OpenCV modules:
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): To be built: core androidcamera flann imgproc highgui features2d calib3d ml objdetect video contrib photo java legacy ocl stitching superres ts videostab
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): Disabled: gpu nonfree world
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): Disabled by dependency: -
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): Unavailable: dynamicuda python viz
06-17 03:25:59.801: I/OpenCVManager/Helper(2647): Android:
06-17 03:25:59.811: I/OpenCVManager/Helper(2647): Android ABI: armeabi
06-17 03:25:59.811: I/OpenCVManager/Helper(2647): STL type: gnustl_static
06-17 03:25:59.811: I/OpenCVManager/Helper(2647): Native API level: android-8
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): SDK target: android-14
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Android NDK: /opt/android-ndk-r8c (toolchain: arm-linux-androideabi-4.6)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): android tool: /hdd2/opt/tadp-3.0r3/android-sdk-linux/tools/android (Android SDK Tools, revision 23.0.2.)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Google Play package: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Android examples: YES
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): GUI:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): GTK+ 2.x: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): GThread : NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): GtkGlExt: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): OpenGL support: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): VTK support: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Media I/O:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): ZLib: z (ver 1.2.3)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): JPEG: build (ver 62)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): PNG: build (ver 1.5.12)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): TIFF: build (ver 42 - 4.0.2)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): JPEG 2000: build (ver 1.900.1)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): OpenEXR: build (ver 1.7.1)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Video I/O:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): AndroidNativeCamera: YES, use prebuilt libraries
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Other third-party libraries:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use IPP: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use Eigen: YES (ver 3.1.2)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use TBB: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use OpenMP: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use GCD NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use Concurrency NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use C=: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use Cuda: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use OpenCL: YES
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): OpenCL:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Version: dynamic
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Include path: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/3rdparty/include/opencl/1.2
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use AMD FFT: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Use AMD BLAS: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Python:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Interpreter: /usr/bin/python2 (ver 2.7.3)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Java:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): ant: /usr/bin/ant (ver 1.8.2)
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Java tests: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Tests and samples:
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Tests: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Performance tests: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): C/C++ Examples: NO
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): Install path: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/build/builds/o4a/install
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): cvconfig.h is in: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/build/builds/o4a
06-17 03:25:59.821: I/OpenCVManager/Helper(2647): —————————————————————–
06-17 03:25:59.821: D/OpenCVManager/Helper(2647): Init finished with status 0
06-17 03:25:59.821: D/OpenCVManager/Helper(2647): Unbind from service
06-17 03:25:59.930: D/OpenCVManager/Helper(2647): Calling using callback
06-17 03:25:59.930: I/Sample::Feature Detection::Activity(2647): OpenCV loaded successfully
06-17 03:25:59.930: D/dalvikvm(2647): Trying to load lib /data/app-lib/com.example.test-1/libnative-util.so 0x40ce1fb8
06-17 03:26:00.100: D/dalvikvm(2647): Added shared lib /data/app-lib/com.example.test-1/libnative-util.so 0x40ce1fb8
06-17 03:26:00.100: D/dalvikvm(2647): No JNI_OnLoad found in /data/app-lib/com.example.test-1/libnative-util.so 0x40ce1fb8, skipping init
06-17 03:26:00.120: I/Choreographer(2647): Skipped 787 frames! The application may be doing too much work on its main thread.
06-17 03:26:00.400: I/Choreographer(2647): Skipped 52 frames! The application may be doing too much work on its main thread.
06-17 03:26:00.461: D/gralloc_goldfish(2647): Emulator without GPU emulation detected.
06-17 03:26:02.791: D/dalvikvm(2647): GC_CONCURRENT freed 1127K, 28% free 3430K/4708K, paused 6ms+5ms, total 82ms
06-17 03:26:03.120: D/dalvikvm(2647): GC_CONCURRENT freed <1K, 17% free 3918K/4708K, paused 6ms+4ms, total 43ms
06-17 03:26:03.120: D/dalvikvm(2647): WAIT_FOR_CONCURRENT_GC blocked 29ms
06-17 03:26:03.160: I/Choreographer(2647): Skipped 299 frames! The application may be doing too much work on its main thread.
06-17 03:26:03.240: D/dalvikvm(2647): GC_CONCURRENT freed <1K, 7% free 4406K/4708K, paused 6ms+22ms, total 98ms
下面做点可以看得见的效果,图像哪种处理最简单??把一个彩色图转换成灰度图,并显示!这里直接调用API就能完成,还没有在Native C++ code中具体操作。运行示意图如下:
点击按钮后:
参考:
1.OpenCV4Android SDK
2.Android Development with OpenCV
3.base operand of ‘->’ has non-pointer type ‘JNIEnv’
4.Working With Java Arrays in Native Methods
5.cvtColor
原文地址:http://blog.csdn.net/vonzhoufz/article/details/46533045