this article is ready for a people who has some knowledge on android develop and a newer about how use opencv SDK in android .
一: what is opencv
简单的来说, opencv 是跨平台的计算机视觉开源库, 它包含了很多图像识别算法
In simple terms , opencv is a open source library about Cross-platform computer vision
here is opencv
here is opencv source code
二: Setting up OpenCv Library inside Android
1, first our develop environment
Android Studio
Opencv SDK 3.2
2, you need download and import Opencv library SDK into android studio peoject
然后你需要使用sdk的java 部分的代码作为你项目的moudle
From File -> New -> Import Module
, choose folder OpenCV-android-sdk -> sdk -> java
then add module dependency to your project
in android studio, Application -> Module Settings
, select the Dependencies tab , click +
icon at bottom ,choose Module Dependency
and select the have imported Opencv moudle
it will looks like that :
copy libs folder under sdk/native
to Android Studio under app/src/main
, and rename libs
to jniLibs
,
3, use opencv library
to use opencv, first you need to modify your Activity xml file . example activity_main.xml
|
|
then modify your activity , load the libopencv_java3.so
, in here , Note: for OpenCV version 3 at this step you should instead load the library opencv_java3
. OpenCV version 2, you should load the opencv_java
|
|
You can create the Main Activity copying the above code.
First you would like notice is that MainActivity
implements CvCameraViewListener2
interface , this interface woulf enfore us to implement few methods which are related to the camera
then
|
|
这个是你使用opencv Java code 很重要的一个方法, 它接受相机的每帧原始数据, 并且你可以在这个方法内做所有的图片片处理工作, 它返回 Mat
作为相机要接受的帧数据.
it is the best importment method for you use opencv , this will receiver the vedio as frames and you can do all the image processing inside this method and return a Mat thie this image :)
dont forget the permission of camera in your AndroidMainfest.xml
|
|
when open this application , if you get the follow prompt :
It seems that you device does not support camera (or it is locked ). Application will be closed.
at this moment , you need manually turn on the camera Permission in device settting
okay ,then yon can enjoy it