Ask Your Question
1

Unable to create positive samples

asked 2013-06-25 05:20:44 -0600

eric gravatar image

I am building a Haar classifier. I have a set of 109 positive samples and 3000 negative samples. To increase my number of positive samples (to say 600), I try using the following command:

opencv_createsamples -vec out.vec -w 24 -h 24 -bg bg.txt -num 600 -info positives.dat

But I get the following error message:

positives.dat(109) : parse errorDone. Created 108 samples

How can I "force" opencv to produce the 600 samples from those 109 I have?

edit retag flag offensive close merge delete

Comments

2

Kindly refer to this link. Read it completely. This should give you a better picture.

Prasanna gravatar imagePrasanna ( 2013-06-25 10:25:23 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
3

answered 2013-07-06 05:32:00 -0600

Prasanna gravatar image

Its really awesome that you made your own tool. Let me clear the air about opencv_createsamples. See if it helps.

You need to use the opencv_createsamples utility on each of the positive images (you have to pass image and not info.dat) and create 5 new images with different (random) distortions (perspective and intensity). You can skip bg file (A black background will be used if you do). This will create a vec file for each of the image with the distortions. Then you should use the mergevec.cpp to merge these vecs into one. Kindly look at the tutorial for more info about this merging of vec files. (You will have 109 vec files and 109*5 positive samples if you use -num 5)

Note : These images created are not a perfect substitute for the lack of original images. They seem to work but they cant capture all of the "variance" in the positive class. It will work the best when you have 600 natural positive images.

So,

  • Use createsamples utility to generate the vec file for each image with random distortions
  • Merge these vec files using mergevec.cpp provided here along with instructions.
  • Put the path of negative images (relative to bg.txt) in bg.txt
  • Pass the final (merged) vec file, bg.txt, and the rest of the parameters (like feature type, stages, falseAlarm Rate, HitRate, etc.) to traincascade to train.

But once again, It was really nice that you put time into it and solved it in a different way.

If you need any more clarifications, comment below. Glad to help.

Regards,

Prasanna S

PS : We need that guide soon, @steve. People are losing hope on opencv_createsamples utility :( . Hope the developers' feelings aren't hurt.

edit flag offensive delete link more
0

answered 2013-07-05 12:26:39 -0600

eric gravatar image

updated 2013-07-05 12:26:54 -0600

What I wanted to do with the opencv_createsamples tool is impossible.

When used on a list of negative images, now transformations are applied, so I will never generate more images than are given in the list.

Instead, I built my own tool to create the 600 distorted images and then fed that into opencv_createsamples

edit flag offensive delete link more

Comments

Actually when I see people deforming images to get more samples, I am getting a big inside laugh. In practical applications this will never yield the desired result. Just put more effort in collecting 600 real life examples which is a far better approach then artificial altering images...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-19 07:42:20 -0600 )edit
0

answered 2014-08-19 06:28:38 -0600

arijoon gravatar image

The -num denotes the number of images you have. That is why you have an error on positives.dat(109) since the program is looking for 109th image but it doesn't exist. Set your -num to 108 and it will work.

If you want OpenCV to produce more samples then as Prasana said you will have to produce each sample individualy. You can write a bash script to do this. If I knew which operating system you are using I would provice that for you considering your image names can be calculated by an incrementing integer.

edit flag offensive delete link more

Comments

hi, i'm trying to get more positive images from my images database, to get some results on my face detection program. i'm working with a 200 images database. thank you,

amine91 gravatar imageamine91 ( 2016-03-24 04:25:46 -0600 )edit

Question Tools

Stats

Asked: 2013-06-25 05:20:44 -0600

Seen: 6,924 times

Last updated: Aug 19 '14