Question

I'm in my OPENCV_ROOT folder and running the following command in Win-x64:

opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 
maxzangle 0.5 -maxidev 40 -w 80 -h 40 
-img ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg 
-bg ABSOLUTE_PATH_TO_PROJECT\negatives.txt
-vec ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec 
-num 125

My negatives.txt looks like this:

negative_images\city01_02.jpg
negative_images\city01_04.jpg
negative_images\city01_05.jpg
negative_images\city01_06.jpg
negative_images\city01_07.jpg

This is my output:

Info file name: (NULL)
Img file name: ABSOLUTE_PATH_TO_POSITIVE_IMAGES_FOLDER\car.jpg
Vec file name: ABSOLUTE_PATH_TO_SAMPLES_FOLDER\car.jpg.vec
BG  file name: ABSOLUTE_PATH_TO_PROJECT\negatives.txt
Num: 125
BG color: 0
BG threshold: 0
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 80
Height: 40
Create training samples from single image applying distortions...
Invalid background description file.

What's invalid about my negatives collection file (negatives.txt)? I tried listing the files within it both with absolute paths and with relative paths. I'm following this tutorial.

Was it helpful?

Solution 2

Problem solved! The issue was simply that I had written the collection file names in Notepad++, and it all seemed fine. But when I happened to open the same file in notepad, I noticed there were no newlines after each image filename! When I added the newlines, and ran the command, the samples got created without errors!

OTHER TIPS

If you created the file on Windows, and running it on Linux e.g. Ubuntu, you have to change the "End of line sequence".

Click on the bottom of the editor on CR LF and change it to LF and try again!

Notepad++:

Notepad++ image:

Visual Studio Code:

Visual Studio Code image:

Geany: Documents > Set Line Endings > Convert and Set to LF (Unix)

Geany image

I had the same problem. Just skip lines between addresses of the images. For example: before my negatives.dat file was:

./Negative_Images/197.
./Negative_Images/69.
./Negative_Images/510.
./Negative_Images/513.
./Negative_Images/169.png

Now it's:

./Negative_Images/197.png



./Negative_Images/69.png



./Negative_Images/510.png



./Negative_Images/513.png



./Negative_Images/169.png

Problem solved.

In my case, I was creating this bg.txt file with a script. Basically, it was doing :

for (int i = 0; i < numberOfImages; i++)
    {
                myDescFile << imagesFolder + std::to_string(i) + ".jpg\n";
    }

I simply added another \n and the problem went away!

myDescFile << imagesFolder + std::to_string(i) + ".jpg\n\n";

EDIT:

You also have to make sure that your paths have/or\\ as separators. Else, you will be able to run the opencv_createsamples.exe cmd, won't have error, but will never see the Done at the end.

ex:L:/imgTraining/plant/bnw/0.jpg

Here's a picture of a good bg file from notepad++ (With View>Show Symbol>Show End of Line activated and Edit>EOL Conversion>Windows (CR LF) selected):

enter image description here

Install dos2unix on Linux by sudo apt-get install dos2unix. And now you just need to use dos2unix YourFileName.txt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top