Ask Your Question
3

How do I run opencv_createsamples with multiple positive images?

asked 2014-03-10 20:52:34 -0600

w1res gravatar image

updated 2014-03-10 22:49:10 -0600

I know how to run opencv_createsamples with a single example of a positive image. How do I run it with multiple examples of positive images? I want to generate multiple positive images using my few (5) sample images, so simply using an info file will not work (as I will need more than 5 positive images!).

I've thought about running it on each file separately, but then I am left with multiple *.vec files and have no way to combine them!

edit retag flag offensive close merge delete

Comments

I think you're supposed to run opencv_createsamples with a text file that contains multiple images names.

GilLevi gravatar imageGilLevi ( 2014-03-11 09:02:33 -0600 )edit
1
tidy gravatar imagetidy ( 2014-09-09 22:13:39 -0600 )edit

5 answers

Sort by ยป oldest newest most voted
1

answered 2014-04-04 10:24:09 -0600

To my knowledge, there are two ways to use opencv_createsamples

(1) Given an info file, listing multiple sample images and the bounding box of the object, it will create the vec file of samples.

(2) Given a single image file (using -img), it will generate various distorted versions of that image, and create a vec file of samples.

The tool does not allow you to use -img with multiple files, or -info with distortions.

One of the guys who created a training tutorial has an (outdated) tool for merging multiple vec files. This is what you are wanting.. unfortunately, i dont know anyone who has the merge tool working these days (there's open questions about that on this site)

edit flag offensive delete link more
0

answered 2014-03-10 23:47:10 -0600

tans2 gravatar image

I think there is a mergevec executable floating somewhere.

edit flag offensive delete link more
0

answered 2014-03-12 00:06:29 -0600

I am just getting into testing some cv stuff and built this little nodejs script to help with training. it does not do any of the compiling for you, but once you have opencv going, it should get you some ways there.

lemme know if this helps: https://github.com/liquidg3/cascadetrainer

edit flag offensive delete link more
0

answered 2015-04-13 03:15:00 -0600

The utility applications that come with opencv as of vers 3.0 don't support generating positive sample from multiple positive image.

To accomplish this you would need generate a script that loops through all your positive images and for each one, run it through the opencv_createsamples app and tag each generated vector file with a unique name. Once this process is finished you would need to, as mentioned in the other comments and answers, stich together all the generated vector files into one big vector file for use in training.

Having said all of this you might want to check out this page and this page.

The author of the first linked to page has create scripts that accomplish what i described above.

edit flag offensive delete link more
0

answered 2019-07-11 01:03:21 -0600

Here is a code that could help. This is assuming your setup is like in the well-known sentdex tutorial: everything is in a folder called opencv_workspace, which contains a folder with your negatives (called 'negs'), and a folder called 'info' where your positive samples are going to go. In this case, all your positives are in a folder called 'pos'. What this code does, is run the opencv_createsamples command for each positive you have in the 'pos' folder, each with it's own info.lst. Then it combines the separate info.lst files into one big info.lst file, and creates the vector file. When I applied it in my case, it worked, except for a small bug where a couple of positives won't be included in the .vec file (specifically, number_of_negatives*2 % number_of_positives) because of a parse error. I don't know how to fix that, but if you have thousands of positives, it'll be a tiny number so it shouldn't matter. You can have as many positives as you want and you won't have to do any manual labor. I attached a picture of the code because otherwise this website renders the text, which changes the code and stops you from copy-pasting. image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-03-10 20:52:34 -0600

Seen: 12,631 times

Last updated: Apr 04 '14