Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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)