OpenCV createsamples - invalid background description file

…衆ロ難τιáo~ 提交于 2019-12-01 12:01:40

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!

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++:

Visual Studio Code:

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):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!