About Face-Recognition by Eigenfaces algorithm using opencv-android

2,868 views
Skip to first unread message

Prerana Polekar

unread,
Aug 30, 2011, 6:40:01 AM8/30/11
to android-opencv
I am able to run all samples given in the android-opencv package...I
am trying to get the face-recognition part working on android using
eigenfaces algo,is it feasible???...My project should look something
like they have done in the following video
http://www.youtube.com/user/JosemGarcia86#p/u/1/38QOp3LhfyM

I dont want to get into the ndk complexities,can it be purely
implemented using java??I read about JavaCV(OpenCV extraction for
java)...but the issue is no documentation about it available as
such...Plz suggest some links or tutorials where i can the maximum
info...

Suggestions and Advices would be of great help..Thank you

Roman

unread,
Aug 31, 2011, 9:35:45 AM8/31/11
to android-opencv
Im not sure if all features are accessible form java side (I dont know
what you are using in your project), but if you import
org.opencv.core.Core; you can use
Core.eigen(src, computeEigenvectors, eigenvalues, eigenvectors) :

Computes eigenvalues and eigenvectors of a symmetric matrix. The
functions "eigen" compute just eigenvalues, or eigenvalues and
eigenvectors of the symmetric matrix "src" : Note: in the new and the
old interfaces different ordering of eigenvalues and eigenvectors
parameters is used.
Parameters:
src Input matrix that must have "CV_32FC1" or "CV_64FC1" type, square
size and be symmetrical ("src"^"T" == "src").
computeEigenvectors a computeEigenvectors
eigenvalues Output vector of eigenvalues of the same type as "src".
The eigenvalues are stored in the descending order.
eigenvectors Output matrix of eigenvectors. It has the same size and
type as "src". The eigenvectors are stored as subsequent matrix rows,
in the same order as the corresponding eigenvalues.
See Also:
org.opencv.core.Core.eigen
org.opencv.core.PCA
org.opencv.core.Core.completeSymm

So I think you could;) I tried come projects in javacv, but it has
terrible lack of documentation and some functions does not work an
Android:/ This new concept of Opencv for Android with realy quick
responses in this forum are awsome:)

Hope it helped you.

Roman

On 30 srp, 12:40, Prerana Polekar <prerana.poleka...@gmail.com> wrote:
> I am able to run all samples given in the android-opencv package...I
> am trying to get the face-recognition part working on android using
> eigenfaces algo,is it feasible???...My project should look something
> like they have done in the following videohttp://www.youtube.com/user/JosemGarcia86#p/u/1/38QOp3LhfyM

Prerana Polekar

unread,
Aug 31, 2011, 10:24:00 AM8/31/11
to android...@googlegroups.com
Hey Roman thanks alot:) it really helped me because i am enable to get
any info on it...Yes javacv doesnot have documentation at ALL!!!It
really needs one documentation like JavaDoc,hope they make it soon...I
am using OpenCV-2.3.1-android version along with Android SDK12,i am
doing it on eclipse Helios...I went through the face-detection
sample,they have used opencv and android functionality well...If i
could get the info about for which all opencv functions they have made
the java wrapper classess it would be of great help..I am good in java
that is why dont want to get into NDK complexities...
Thanks ALOT again:)

Roman

unread,
Aug 31, 2011, 11:24:52 AM8/31/11
to android-opencv
Glad to help:) BTW dont forget, that opencv use C++ form of functions
and javacv use old C form if you migrate the project;)
I used NDK, but performance was not as good as I expect and its
terrible to debug C code in Eclipse for me.
Good luck with your project.

On 31 srp, 16:24, Prerana Polekar <prerana.poleka...@gmail.com> wrote:
> Hey Roman thanks alot:) it really helped me because i am enable to get
> any info on it...Yes javacv doesnot have documentation at ALL!!!It
> really needs one documentation like JavaDoc,hope they make it soon...I
> am using OpenCV-2.3.1-android version along with Android SDK12,i am
> doing it on eclipse Helios...I went through the face-detection
> sample,they have used opencv and android functionality well...If i
> could get the info about for which all opencv functions they have made
> the java wrapper classess it would be of great help..I am good in java
> that is why dont want to get into NDK complexities...
> Thanks ALOT again:)
>

Prerana Polekar

unread,
Aug 31, 2011, 3:07:51 PM8/31/11
to android...@googlegroups.com
Thanks alot again:)

Andrey Pavlenko

unread,
Sep 1, 2011, 4:46:32 AM9/1/11
to android-opencv
>> If i could get the info about for which all opencv functions they have made the java wrapper classess it would be of great help..
I'd suggest following:
open the latest OpenCV ref man at http://opencv.itseez.com/
if the function has a Python wrapper starting with 'cv2.' (e.g. for
Canny it's cv2.Canny) the function most likely is included to Java API
as well.
The Python 'cv2.' wrappers and Java API have some shared code so they
intersect for ~90%.
/Andrey.

On Aug 31, 11:07 pm, Prerana Polekar <prerana.poleka...@gmail.com>
wrote:

hehui

unread,
Sep 1, 2011, 4:48:44 AM9/1/11
to android-opencv
who  can  tell  me  how to  build  opencv  in  ubuntu without  NDK ?

Andrey Pavlenko

unread,
Sep 1, 2011, 5:21:28 AM9/1/11
to android-opencv
Hehui,
could you start another thread instead of changing the current
subject?
thanks

Roman

unread,
Sep 1, 2011, 6:38:04 AM9/1/11
to android-opencv
Andrey, thanks a lot for your tip with Python cv2 wrappers to found
what is in Java API, maybe it could be useful mentioned this in
android wiki. Do you know any good tutorial how to make own wrapper? I
would like to use some basic functions like setImageROI but they are
not included in Java, now I'm using submat(roi) to create submatrix,
but (I think) setting ROI in original matrix would be better for
performance on android, instead of creating new matrix from original
(maybe I'm wrong, just thought). So if you know some good tutorial for
creating own wrapper for opencv function, please send me a link, if I
succeeded, I will share it to others.

Roman

Andrey Pavlenko

unread,
Sep 1, 2011, 7:39:53 AM9/1/11
to android-opencv
cvSetImageROI() is a part of legacy C (1.x) interface (working with
IplImage)
Please use the new C++ (2.x) interface (working with Mat) when
possible.
Working with sub-Mat is implemented without data copying, it's very
efficient!
See http://opencv.itseez.com/trunk/modules/core/doc/basic_structures.html#mat
for more details.

Andrey Pavlenko

unread,
Sep 1, 2011, 7:50:25 AM9/1/11
to android-opencv
As for JNI wrappers - we don't do anything special, just what is
described on Sun docs at
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
The only difference is that our .java and .cpp code for Java wrappers
is generated from templates by Python script based on OpenCV C++
headers.
OpenCV sources are open, you can download it, build using instructions
from our wiki (http://opencv.willowgarage.com/wiki/AndroidTrunk) and
see the source code of existing Java wrappers.
Actually .java files are included into the prebuilt package, but .cpp
part is precompiled to libopencv_java.so
/Andrey.

On Sep 1, 2:38 pm, Roman <hruskozr...@gmail.com> wrote:

Saurav

unread,
Sep 5, 2011, 7:39:34 AM9/5/11
to android-opencv
Hi Andrie
I am working on face detection on android with open cv.
The problem I faced was that with detecting
objects(CvHaarDetectOjects), when there are no face in the input
image .
In that case while on emulator(android emulator ) the program is able
to come out of HaarDetectObjects , but the same code while running on
hardware(I have Nexus One 2.2) it never comes out of this function and
ultimately shows the force quit dialog(Freezes).
the function I using is --
int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH;
CvSize minFeatureSize = cvSize(20, 20);
float search_scale_factor = 1.1f;
CvSeq* rects = cvHaarDetectObjects( detectImg, cascade, storage,
search_scale_factor, 3, flags, minFeatureSize);

Any suggestions or ideas for the above problem, please let me know


Regards
Saurav

Andrey Pavlenko

unread,
Sep 5, 2011, 8:16:04 AM9/5/11
to android-opencv
Hi Saurav,
could you please start a new thread and don't change the subject of
existing ones?

rja

unread,
Oct 1, 2011, 2:47:42 AM10/1/11
to android-opencv
Roman, are there any rules about how the symmetric matrix should be
built?
I only have a single array of images (say size 50) I want to calulate
the eigenvectors and values of. So can I simply create a matrix of
size 50x50 with the same values in the first row and column, and
remaining being empty? The old C interface - cvCalcEigenObjects - used
a simple array as the input. What would it take to use the new eigen()
functions?

Thanks,
Rajesh
Reply all
Reply to author
Forward
0 new messages