OpenCV library.

keylab83

Member
Licensed User
Longtime User
Hi all. Please can someone help me. I'v try to wrap a openCV library for b4a but without successes.My knowledge with java is NONE. I got all the materials need to wrap openCV library but not the knowledge how to do it. I believe most of us need that library so can someone do anything about it pls. there is a java code for that

OpenCV in Android
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
OpenCV in Android
Using OpenCV in Android. This tutorial is tested under Ubuntu 10.04 + Android SDKr07 + Android NDKr4b.
Preparing the development environment
Download and install Android SDK. Details can be found here
Download eclipse and install the ADT plugin. Details can be found here
Download Androdi NDK. This tool is used to cross compile OpenCV source code to Android. Currently (NDK r4) only C is fully supported, so I can only use OpenCV 1.1 under Android. The laterst version of OpenCV uses lots of STL functions. :(
Create the test project
Create a new Android project in eclipse. For example, called testOpenCV. Name the package name as: edu.stanford.android.
In the root directory of the project, create a new folder called jni and extract all files in android_opencv.tar.gz to this folder.
Run “$NDK/ndk-build” from your project directory. It will generate libopencv.so in the libs/armeabi folder.
Write Java code to use OpenCV functions. I have three java files which can be downloaded here. They are a little bit long so I do not want to paste the source code here. The general idea is that I use the intent to start the camera or gallery activities to get the image and send this image to OpenCV. After OpenCV finishes extracting SURF features, it send the processed image back to JVM. The interface between JVM and OpenCV is pretty simple: setSourceImage and getSourceImage.
OpenCV.java
package edu.stanford.zixuanpc;

public class OpenCV {
static{
System.loadLibrary("opencv");
}
public native boolean setSourceImage(int[] pixels, int width, int height);
public native byte[] getSourceImage();
public native void extractSURFFeature();
}
And here is the code how we use these two functions:

Code snippet in testOpenCVActivity.java
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentImagePath);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
opencv.setSourceImage(pixels, width, height);
opencv.extractSURFFeature();
byte[] imageData = opencv.getSourceImage();
bitmap = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length);
mImageView.setImageBitmap(bitmap);
Run the program
Press the menu button to select your camera to capture an image. The down-sampled image is saved in your gallery. Press the menu button again to select it from your gallery and features are automatically extracted.
Notice: if you select a large image in the gallery, the program may crash due to limited memory.
On my DROID phone, it usually takes 4 seconds to extract features from one image.


Thank you guys and hope someone gonna surprise us with OpenCV library soon .
 

canalrun

Well-Known Member
Licensed User
Longtime User
I haven't used OpenCV since October 2015, and I think others have mentioned this same thing, but OpenCV is more of a collection of individual functions rather than something that would be convertible to a library.

It is extremely powerful, but it does take a significant learning curve to use it effectively.

Since I have used OpenCV, B4A has introduced things like embedded Java and External Library References which might make integration a lot easier.

The way I ended up using it was to develop a very specific "processing string" (group of functions executed as a library call) in visual C then converting that to a Java library to be called by B4A. I can't imagine converting OpenCV into a general-purpose library.

Barry.
 
Upvote 0
Top