when i run opencv_createsamples command on ubuntu server it says "invalid background file". Please help
my bg.txt file contains paths like :-
neg/1.jpg neg/2.jpg
etc
please show us your complete cmdline.
(also, always use an absolute path for filenames in bg.txt, info.txt, and also the txt files on the cmdline)
If it says invalid background file, then it was not able to open the image file, as seen on this line of code. So like @berak said, this is solved by using absolute paths, probably the file is not on the exact relative position to the executable. This isssue is avoided with absolute paths.
@berak and @StevenPuttemans command i'm using is "opencv_createsamples -img original.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 2000"
and i tried using absolute paths in bg.txt file such as /home/ubuntu/opencv_dir/neg/1.jpg
still facing the same issue.
Can you do a
eog /home/ubuntu/opencv_dir/neg/1.jpg
at the location of your executable and check whether the image opens up?And also make an absolute path for
-img
parameter! That is the one screwing stuff up!@StevenPuttemans i tried using absolute paths everywhere necessary, still it's of no use :(
Well there is also a typo
-pngoutput info
. Thatinfo
should not be there. Can you remove it and try again? Also provide your new complete command and content of your files by editing the question.that info is the directory where i want to send my positive images created by merging original.jpg and negative images. Also, I tried same thing on CentOS. Command worked fine there and it created samples. Can it be because of the platform ??? @StevenPuttemans
Can you replace info by again an absolute path. No the tool works just fine on ubuntu in my case!
command worked. I used python script to create the bg.txt file and it was, I'm guessing, inserting some character which is normally not visible after every new line statement and hence opencv was failing to read it. I manually created the bg.txt with VI editer on server itself by putting in location of 10 images and it worked. That way i automated the process for all images and it is working fine.
thanks a lot for your time and support, @StevenPuttemans
You hit a known bug. Completely forgot about this! Keeps in mind that this need to be fixed rather soon!
@StevenPuttemans when I train the cascade with opencv_traincascade command, it starts and ends up quickly even though i use 10 stages. It finishes up in 7-10 minutes and when i run the python script using the developed cascade.xml file, it shows video frame full of boxes and it is not detecting the required object. My question is why is training ending up so quickly even though there are 2000+ positive samples and 10 stages ?
no way of telling that without the complete training output, the model, the data, ... so I guess you can start by adding the necessary info!
yes. I've been using the following commands
opencv_createsamples -img original.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 2000
. This command generates positive images and info.lst file which has content like this0001_0014_0045_0028_0028.jpg 1 14 45 28 28
. Thenopencv_createsamples -info info/info.lst -num 2000 -w 20 -h 20 -vec positives.vec
creates positive vector file. Finallyopencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1900 -numNeg 950 -numStages 10 -w 20 -h 20
is for training. The whole process ends up in few minutes. I have negative images of 100 by100 and original image is of 50 by50. Combined both to form positive images. I am running on 2gb memory of unix server.