Python script with opencv_createsamples doesn't create samples
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)
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.
have another look here , please
I was basing on this tutorial
your script is doing something else, and it's plain wrong.
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.
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 ?)
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.
oh, i disagree in your case. you can only train one cascade for one single thing
now we have a multi-class problem. if you want to classify, what it is (from many), then you need something entirely else.
what would you suggest? I know that! :) I am planning to train couple of classifiers. each for different ingredient.