Re: [javacv] Creating training samples from a single image

843 views
Skip to first unread message

Samuel Audet

unread,
Jun 29, 2012, 3:46:28 AM6/29/12
to jav...@googlegroups.com
Hello,

cvhaartraining is by itself a complete application. Obviously we could
port it to Java, but are there any reason why you cannot use it as is?

Samuel

On 06/28/2012 11:08 PM, Coredumped wrote:
> I have recently started using OpenCV and the JavaCV wrapper to do some
> image processing for my master thesis. I've mostly been following the
> examples provided with JavaCV along with an OpenCV tutorial made by
> Naotoshi Seo (http://note.sonots.com/SciSoftware/haartraining.html).
> One thing I want to do is produce several training samples from a single
> image (this is a requirement for my work) and the OpenCV tutorial has a
> section named "Create training samples from one" which pretty much
> seemed to be the thing I was looking for. However, I've tried searching
> for some sort of equivalent function that I could use in java to achieve
> this goal.
>
> Is there a function in JavaCV that allows me to do this? If not, I would
> appreciate some suggestions on how to proceed.
>
> ps: It might be relevant explaining why I need this - I pretty much need
> to make facial recognition between two pictures, one retrieved from a
> smart card (which only has the one) and the other being a profile
> picture from a social network. Since trying facial recognition with only
> one training image seems to have pretty bad results, I thought the above
> method would be by best bet, however, if there is another way I would
> alos apreciate some insight.
>
> Thank you!

Coredumped

unread,
Jun 29, 2012, 9:45:37 AM6/29/12
to jav...@googlegroups.com
Well, I probably could, but since I am mostly used to programming in java and all of my project has been written in java so far, it would make things easier. But if there is no similar function I'll try to make it work in C, and then probably make an exec call to use it inside my code. Or is there an easier way of doing this?

Samuel Audet

unread,
Jul 1, 2012, 9:36:32 PM7/1/12
to jav...@googlegroups.com
Hello,

cvhaartraining is an independent program that uses OpenCV. We could
obviously port it to Java, but merely to use it, we don't need to do
that. The tutorial doesn't mention anywhere how to use its
cvCreateTrainingSamples() function either, so I don't think it's meant
to be used outside of the program anyway.

Samuel

On 06/29/2012 10:45 PM, Coredumped wrote:
> Well, I probably could, but since I am mostly used to programming in
> java and all of my project has been written in java so far, it would
> make things easier. But if there is no similar function I'll try to make
> it work in C, and then probably make an exec call to use it inside my
> code. Or is there an easier way of doing this?
>
> Quinta-feira, 28 de Junho de 2012 15:08:12 UTC+1, Coredumped escreveu:
>
> I have recently started using OpenCV and the JavaCV wrapper to do
> some image processing for my master thesis. I've mostly been
> following the examples provided with JavaCV along with an OpenCV
> tutorial made by Naotoshi Seo
> (http://note.sonots.com/SciSoftware/haartraining.html

Coredumped

unread,
Jul 3, 2012, 9:38:36 AM7/3/12
to jav...@googlegroups.com
Ok, I understand what you're saying.

I need a different approach then, and I have also recently discovered that the facial recognition I'm currently using is giving terrible results. Pretty much my current problem is:

1- The pictures I have that I can identify are retrieved from a social network or an identifying smart card (only one picture, but I know who it belongs to).

2- Given that I can only get one identifiable picture, if I were to use it as the training set, my results would probably be very bad, since from what I have read it is advisable to use at least 50 training images.

3- To try and work around this issue, I am using the live frame captures from my camera (currently using 100 frames) as the training set, and then try to use the picture I used from the smart card as the test image.

This seemed like a good idea at the time, but what happens is that when I try to recognize different pictures to the captured frames, they all give very similar confidence values... I often also get higher confidence values from other peoples' test images than my own (when comparing to the frame captures of my face).

I'm certainly doing something wrong, or have the recognition system mixed up in my head. I'm hoping that somebody has had this problem before and if so, some help would be greatly appreciated!

Thank you for all the help so far :)

Samuel Audet

unread,
Jul 3, 2012, 9:17:06 PM7/3/12
to jav...@googlegroups.com
So you're trying to do facial /recognition/. You certainly won't be
getting any /recognition/ results from a facial /detection/ method.
Those are not the same thing..

Coredumped

unread,
Jul 4, 2012, 9:56:10 AM7/4/12
to jav...@googlegroups.com
Maybe I explained myself badly in my previous post, but I think I am using the correct facial recognition method.. I only use the face detection part to process the camera frames, grayscale the images, detect the face, and save the resized, equalized cropped face in a file (which I was using as input for the training set).

I was then doing face recognition with one of the sample code files that came in the javacv package named FaceRecognition.java which even contains in the comment section "(Fixed April 22, 2012, Samuel Audet)".

Another person advised me to get a face database (I downloaded and tried the Cambridge_FaceDB) and add to it the face images I collect from the smart cards, having a bigger, possibly more reliable training set. With this database as my training set, I tried to do face recognition with the test set being faces from different people which I had collected with the webcam (the collected smart card pictures belonged to these people, so if working correctly, they should match with a good confidence value right?).
With this different approach, the same thing happens, my test pictures are being recognized to different people (random people in the Cambridge face db) with very high confidence values of ~95... This makes no sense to me.
Do you know what could be causing this behavior ?

Samuel Audet

unread,
Jul 7, 2012, 10:46:02 AM7/7/12
to jav...@googlegroups.com
Ah, I see now. There is a new "FaceRecognizer" in OpenCV BTW. You might
want to try that one see if it works better for your application:
http://code.google.com/p/javacv/source/browse/src/main/java/com/googlecode/javacv/cpp/opencv_contrib.java#841

Samuel

Coredumped

unread,
Jul 8, 2012, 8:21:04 AM7/8/12
to jav...@googlegroups.com
Hello Samuel, thank you for your reply.
I am also trying to get some infro through stack overflow, and I recently got an update there from a nice user which pretty much suggested to look into that same new feature: http://stackoverflow.com/questions/11315157/opencv-javacv-face-recognition-very-similar-confidence-values

In sum, he pretty much suggested that eigenfaces might not be my best bet since my training data is so small, and should try different methods, which FaceRecognizer seems to have (I am going to start studying it).

I was going to ask if FaceRecognizer had been wrapped to java in javacv, but your previous post seems to answer that :)

I will try to work with it, and see if I can get better results with the methods described in the answer to that stackoverflow post.

Thank you!

Coredumped

unread,
Jul 9, 2012, 10:17:19 AM7/9/12
to jav...@googlegroups.com
Also, I forgot to mention in my previous reply, I was advised to use Local Binary Patterns Histograms in small sample scenarios (which is my case), so far I have only found documentation for this in C++. Is there any sample code/tutorial for this method in JavaCV?
Message has been deleted

Samuel Audet

unread,
Jul 13, 2012, 11:13:08 PM7/13/12
to jav...@googlegroups.com
Not that I am aware of, but let me know if you have any issues porting
the C++ sample to Java...

Samuel

Samuel Audet

unread,
Jul 13, 2012, 11:15:42 PM7/13/12
to jav...@googlegroups.com
On 2012-07-10 23:07, Coredumped wrote:
> Another update, since I haven't been able to find any sample
> code/tutorials for it, I've been trying to follow
> thishttp://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html
> in the Local Binary Patterns Histograms in OpenCV
> <http://docs.opencv.org/trunk/modules/contrib/doc/facerec/facerec_tutorial.html#id40>
> section.
> The first part of the method seems to be the "train" phase where we
> should input the training images right? I have tried to do this also
> using your Face Recognition sample code, feeding the train function of
> FaceRecognizer with IplImage[] trainingFaceImgArr which we already had
> in your example. Since the train function receives 2 CvArr as arguments,
> and according to
> http://opencv.willowgarage.com/documentation/basic_structures.html -
> "The metatype CvArr is used /only/ as a function parameter to specify
> that the function accepts arrays of multiple types, such as IplImage*,
> CvMat* or even CvSeq* sometimes. The particular array type is determined
> at runtime by analyzing the first 4 bytes of the header.", however, when
> I try using the IplImage array as argument it says the method is not
> ready to receive that type of argument. Just out of curiosity I tried
> using a single IplImage as argument instead of the array and the method
> doesn't complain... Is this supposed to happen? Or am I doing something
> wrong?

It's been fixed in the source repo:
http://code.google.com/p/javacv/source/detail?r=a76160e335b70da95d5f570a25edf8bc2051086e

If you're not inclined to recompile the source, you'll have to wait for
the next release...

Samuel
Reply all
Reply to author
Forward
0 new messages