Android Studio中安装OpenCV SDK
来源:互联网 发布:有域名怎么免费建网站 编辑:程序博客网 时间:2024/04/28 04:13
Android Studio中安装OpenCV SDK
Open Source Computer Vision (OpenCV) is a library used for computer vision and machine learning. It has many optimized algorithms which can be used to perform tasks easily. In the first part of this tutorial we will setup OpenCV Android SDK in our Android Studio project. In the next one we will change the brightness of a Image in real time using OpenCV.
OpenCV Android SDK can be downloaded from opencv.org. The latest version at the time of writing is 3.1.0.
Extract the downloaded zip file.
Open Android Studio and create a new project with package of your choice. Here I have created a new project with com.learn2crack.opencvdemo
Then select File ->New -> Import Module
You need to select the OpenCV SDK location. Select OpenCV-android-sdk/sdk/java. Then select Next and Finish. OpenCV sdk is imported as a module.
But it may throw error. Lets see how to fix this.
In the project explorer change the project view from Android to Project. Open Project -> openCVLibrary -> build.gradle
Change the compileSdkVersion, targetSdkVersion and buildToolsVersion value to the latest version you use. Here I use 23, 23 and 23.0.2. Then sync the project. The errors will be gone.
7. Switch back to Android view in Project explorer. Right click on the app module and select Open Module Settings.
8. For the app module in the Dependencies tab, select Add -> Module Dependency -> openCVLibrary
Now we need to add native JNI libraries in our project. These libraries should be added in jniLibs directory. Create a new jniLibs directory in app-> src -> main.
Open the extracted OpenCV SDK directory. Switch to OpenCV-android-sdk/sdk/native/libs directory.
You will find directories for many CPU architectures. Copy the required architecture directory to the jniLibs directory. Here I copied x86_64 and armeabi-v7a because my Android emulator has x86_64 architecture and my OnePlus One has armeabi-v7a architecture. Delete all files except libopencv_java3.so.
Open your gradle.properties file and enter the following code.
android.useDeprecatedNdk=true
Now we have setup SDK in our Android Studio project. Lets test whether OpenCV is loaded.
We use OpenCVLoader to test whether OpenCV is loaded. The Activity code is given as,
package com.learn2crack.opencvdemo;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import org.opencv.android.OpenCVLoader;public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; static { if(!OpenCVLoader.initDebug()){ Log.d(TAG, "OpenCV not loaded"); } else { Log.d(TAG, "OpenCV loaded"); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
Now run the project. Check log, You will see message OpenCV loaded and many other OpenCV debug messages similar to,
V/StaticHelper: General configuration for OpenCV 3.1.0 =====================================
I/OpenCV/StaticHelper: Version control: 3.1.0
I/OpenCV/StaticHelper: Platform:
I/OpenCV/StaticHelper: Host: Darwin 15.0.0 x86_64
I/OpenCV/StaticHelper: Target: Android 1 x86_64
- Android Studio中安装OpenCV SDK
- Android Studio中使用OpenCV Android SDK
- Android Studio项目中配置使用OpenCV Android SDK
- Android Studio导入OpenCV Android SDK
- Setup OpenCV SDK in Android Studio project
- 安装Android Studio中SDK Manager出现的问题
- android studio 在线安装SDK
- 在Android Studio中安装OpenCV mac环境/Linux环境
- Android studio 安装 opencv-Android环境搭建
- Android Studio安装与SDK配置
- Android Studio正式版带SDK安装教程
- 在android studio中集成JPush SDK
- Android Studio中添加使用arcgis sdk
- Android Studio 中如何更改SDK路径
- android studio中导入百度自动更新SDK
- Android Studio中配置科大讯飞SDK
- android studio中关联SDK源码
- Android Studio不安装opencv manager配置
- 13周练 D - Beautiful Paintings 【升数列】
- qt在Windows下生成包含动态库的动态库
- 几种枚举窗口的方法(包括猥琐的你懂得)
- objective-c - 基础篇 - 数据库网络 -- 使用NSURLSession进行POST请求的网络数据
- 【android】:android之创建多个活动
- Android Studio中安装OpenCV SDK
- sdk版本对应的android版本
- 比较字符串
- leetcode---Swap Nodes in Pairs
- ListView优化之一:重用convertView
- Firefox必备的24款web开发插件
- @RequestParam @RequestBody @PathVariable 等参数绑定注脚详解
- 解决HierarchyViewer不能连接真机的问题
- 延迟菜单实现