when i run opencv_createsamples command on ubuntu server it says "invalid background file". Please help

asked 2016-07-27 02:52:52 -0600

updated 2016-07-27 03:20:47 -0600

berak gravatar image

my bg.txt file contains paths like :-

neg/1.jpg neg/2.jpg

etc

edit retag flag offensive close merge delete

Comments

1

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)

berak gravatar imageberak ( 2016-07-27 03:06:49 -0600 )edit

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-27 03:18:00 -0600 )edit
1

@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.

akumar6 gravatar imageakumar6 ( 2016-07-27 03:44:41 -0600 )edit

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?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-27 03:54:33 -0600 )edit

And also make an absolute path for -img parameter! That is the one screwing stuff up!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-27 03:55:52 -0600 )edit

@StevenPuttemans i tried using absolute paths everywhere necessary, still it's of no use :(

akumar6 gravatar imageakumar6 ( 2016-07-28 01:51:07 -0600 )edit

Well there is also a typo -pngoutput info. That info 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.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-28 03:18:51 -0600 )edit

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

akumar6 gravatar imageakumar6 ( 2016-07-28 04:40:54 -0600 )edit

Can you replace info by again an absolute path. No the tool works just fine on ubuntu in my case!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-28 09:13:16 -0600 )edit
2

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

akumar6 gravatar imageakumar6 ( 2016-07-29 06:20:33 -0600 )edit

You hit a known bug. Completely forgot about this! Keeps in mind that this need to be fixed rather soon!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-29 06:31:49 -0600 )edit

@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 ?

akumar6 gravatar imageakumar6 ( 2016-08-01 07:01:31 -0600 )edit

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!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-01 07:29:33 -0600 )edit

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 this 0001_0014_0045_0028_0028.jpg 1 14 45 28 28. Then opencv_createsamples -info info/info.lst -num 2000 -w 20 -h 20 -vec positives.vec creates positive vector file. Finally opencv_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.

akumar6 gravatar imageakumar6 ( 2016-08-02 00:18:21 -0600 )edit