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 .
 

rayzrocket

Member
Licensed User
Longtime User
Does a B4A 'openCV' library exist now?
This would be a huge capability and open doors to the world of visual image processing and tracking for B4A users...and likely attract more/new B4A use.
thanks,
-ray
 
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
C++ is fine if we can easily bring it into your B4A environment with ease.
C++ route may be most agile and may provide access to all aspects of OpenCV without any B4A limitations..And C++ would facilitate app' implementation to other platforms, linux, iOS, and other.. But..For quick use of Open CV in B4A, writing the related code in native B4A maybe fastest and easiest to manage for all levels of B4A programming expertise.
I would personally have a steep learning curve with C/C++ Open CV and its implimentation into B4A.
But, my use of Open CV would be quick and easy for me if you wrap the Open CV compenents with B4A constructs.
(I think this would be huge for B4A, now that the cameras on phones are so nice and processors are capable of realtime image processing.)
 
Last edited:
Upvote 0

kolbe

Active Member
Licensed User
Longtime User
Basic4Android

Good news this is.

OpenCV library (or framework) is planned.

A small question about it. Do you prefer to write the OpenCV related code in C++ or in Basic4android (equivalent to Java)?
 
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
Could I use OpenCV with B4A without any libraries as C/C++ routines with file access?
For example if one wants to image target track with control output to mount pan-tilt motion base, could we use B4A as the top level software GUI in Droid while using OpenCV algos with photo file access in parallel?
 
Upvote 0

socialnetis

Active Member
Licensed User
Longtime User
There is no chance at all of using OpenCV? I know that is like a wrapper over c++, is there a way to make a little library with some functions of the OpenCV? I did it, but it's seems that still needs the native libraries written in c++ and don't know what to do
 
Upvote 0
Top