Python script with opencv_createsamples doesn't create samples

asked 2016-10-02 00:56:49 -0600

bighealthkick gravatar image

updated 2016-10-02 01:15:36 -0600

I create positive samples to get classificator through opencv_traincascade. I wrote a Python script that iterates through all the positive images and does "opencv_createsamples" command on them. Everything works fine, there's no error, it looks as the samples are really creating (in terminal, after each command, all parameters are written and 'Done' after them). I run my script with absolute path to project directory as parameter. The "opencv_createsamples" command for one of positive images looks like:

opencv_createsamples -bg /home/path_to_project/project_dir/negatives.txt -num 2 -maxxangle 0.0 -maxyangle 0.0 -maxzangle 0.3 -bgcolor 0 -bgthresh 8 -w 40 -h 40 -img /home/path_to_project/project_dir/positives/18.JPG -info /home/path_to_project/project_dir/samples/info21.txt

That command should create two .jpg files and info21.txt file in 'samples' directory, but it doesn't. If I run exactly that command above separately in terminal (in any directory), it would create files in 'samples' folder. I have no idea why it works alone and doesn't work when it is run from python script.

Edit: I run Python script with just calling opencv_createsamples command and it worked fine - it created samples. The problem is that the same command doesn't work in loop:

for fname in os.listdir(directory+POSITIVES):
    if fname.endswith(".jpg") or fname.endswith(".JPG"): 
        call("opencv_createsamples (...)", shell=True)
edit retag flag offensive close merge delete

Comments

1

wait, you got something wrong entirely.

you're supposed to make a single info.txt with all your positives (e.g. with the opencv_annotation app), and pass that to opencv_createsamples once, not for each image.

berak gravatar imageberak ( 2016-10-02 01:53:59 -0600 )edit
1

have another look here , please

berak gravatar imageberak ( 2016-10-02 02:00:39 -0600 )edit

I was basing on this tutorial

bighealthkick gravatar imagebighealthkick ( 2016-10-02 03:31:35 -0600 )edit

your script is doing something else, and it's plain wrong.

berak gravatar imageberak ( 2016-10-02 03:35:53 -0600 )edit

as I said, I was basing on tutorial - my script was meant to create n infoXX.txt (n-number of positive images), then everything from n infoXX.txt would be saved in a single info.txt file and than I would run again opencv_createsamples but with -info as input and -vec as output. so idea to create info.txt file was the same but opencv_annotation app only mark regions where positive sample is, so I cannot increase number of positive samples like I do with my script. it also applies no distortion, while samples created with my script will be with distortion.

bighealthkick gravatar imagebighealthkick ( 2016-10-02 04:58:35 -0600 )edit
1

the whole idea of "synthesizing" a lot of samples from a few real images is broken anyway (i guess, that's what your script is trying to do). don't do that.

rather get as many "real" positive images as possible.

(what are you trying to detect, btw ?)

berak gravatar imageberak ( 2016-10-02 06:11:33 -0600 )edit

ok. I am trying to detect different ingredients. if I could recognize some fruits and vegetables, then it will be awesome :D. too bad, they don't have too many features. training classifiers look for me like the best option for solving this problem.

bighealthkick gravatar imagebighealthkick ( 2016-10-02 06:44:38 -0600 )edit
1

training classifiers look for me like the best option

oh, i disagree in your case. you can only train one cascade for one single thing

some fruits and vegetables

now we have a multi-class problem. if you want to classify, what it is (from many), then you need something entirely else.

berak gravatar imageberak ( 2016-10-02 07:38:47 -0600 )edit

what would you suggest? I know that! :) I am planning to train couple of classifiers. each for different ingredient.

bighealthkick gravatar imagebighealthkick ( 2016-10-02 09:51:39 -0600 )edit