opencv createsamples has no error, but no samples found

廉价感情. 提交于 2019-12-02 11:04:59

问题


I'm using this tutorial, and I'm on the stage of creating lots of samples from my positive images. I'm using Windows.

This is the command:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500\  "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

And this is what I get as output, for each of the positive images:

C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -max
xangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img 60inclin
ation_315azimuth.jpg -bg tmp -vec samples0inclination_315azimuth.jpg.vec -num 62

Info file name: (NULL)
Img file name: 60inclination_315azimuth.jpg
Vec file name: samples0inclination_315azimuth.jpg.vec
BG  file name: tmp
Num: 62
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...
Done

The messages seemed successful so I went into the samples folder expecting to see 1500 samples, but there's nothing there! I noticed the info file is <NULL>, does that have anything to do with this? There doesn't seem to be any error, what went wrong?

Edit

I've changed the command to include absolute paths for everything, eg

perl bin/createsamples.pl C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ C:\my_work\code\opencv-haar-classifier-training-master\positive_images\ samples 1500\  "C:\opencv_built\bin\Release\opencv_createsamples.exe -bgcolor 0 -bgthresh 0 -maxxangle 1.1\   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

But still no luck!


回答1:


I had a similar problem I'll try to explain what I did, I hope it will solve you problem.

First of all the NULL after -info is normal. As said in the official documentation of OpenCV for opencv_createcamples you need to either input an image (-img) or a collection of images (-info) I'll let you read the documentation for further understanding, but for this example you don't need it.

Secondly you don't need to put absolute paths in this command; here is my command:

perl bin/createsamples.pl  positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 -maxzangle 0.5 -maxidev 40 -w 42 -h 40"

to do this be sure to be at the root of the gitHub directory you have download (the parent one of bin) be sure that your positives.txt and negatives. txt are in this directory. Also copy paste the opencv_createsamples.exe from OpenCV directory in this one.

This done I'll now explain the main problems: The project was developped for Ubuntu at the beginning so it works for mac easily but I think you must be under Windows. If you hadn't already please download Cygwin because it uses mainly Linux commands.

As I said I was blocked with a similar problem, so I tried to use opencv_createsample directly instead of the perl script to see if the problem was coming from there and I noticed that the problem was coming from the fact that my positives.txt and negatives.txt were under Windows format and not Unix so the Perl script wasn't able to read them properly.

The difference between windows and linux are big and Cygwin doesn't bridge the gap so there might be other encoding problems. So what I did is surely not the fastest way to resolve the problem, but it is an easy one.

I just installed an Ubuntu vm on my PC

Installed Opencv with TBB ( a lot of tutorials internet, the best is the one from the OpenCV site).

I Downloaded the gitHub Classifier training and then I followed the commands given and it worked well.




回答2:


Another simpler explanation. Let's say you are new to OpenCV (as I am), and you're just following one of the tutorial videos, to create your first object detector. You might have created a sample image by cut-pasting from the web. Sample images must be monochrome, but more than that, they must be single-channel, 8-bit monochrome. If you photoshopped your sample to appear monochrome, but didn't change its channel configuration, opencv_createsamples will ignore it if it actually has more than one channel.

Source: ~/apps/createsamples/utilities.cpp, function icvStartSampleDistortion().




回答3:


I was presented with a similar problem, also in Windows, but my solution was to check positives.txt and negatives.txt were in a format the the createsamples.pl file could understand. I'm not sure this was the same as your problem, but I ended up here so others might too.

I ran the following python script from the same directory as createsamples.pl to form the text files, which seemed to make the perl file work for me:

'''
Run this from the folder containing the positive and negative samples' folders (Note: outputs the text files to this directory)
'''
import glob
import sys

def write_locations(folder, textFile):
    print('')
    file = open(textFile, 'w')
    for contents in glob.glob('{}/*'.format(folder)):
        try:
            fileName = contents.split("\\")[-1]
            file.write('\n./{0}/{1}'.format(folder, fileName))
            print('./{0}/{1}'.format(folder, fileName))
        except:
            pass

write_locations('positive', 'positives.txt')
write_locations('negative', 'negatives.txt')

print('\n -Done.')

The organisation of my folders might be slightly different to the tutorial (I only went there for the perl file), but all I'm doing is checking that the text files read something like:

./positive/1_1.png
./positive/1_2.png
./positive/1_3.png
./positive/1_4.png

and so on.




回答4:


I had a similar problem I'll try to explain what I did, I hope it will solve your problem.

First, name the files positives.dat and negatives.dat instead of positives.txt and negatives.txt.

Second, copy and paste positives.dat and negatives.dat files into the current directory, then run:

perl bin/createsamples.pl positives.dat negatives.dat samples 1000 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

After that, check your samples folder, and you should see the positive & negative folders containing many vector files.




回答5:


I had the same problem. The problem was that I had Captital letters in the filename, but not in the terminal code.



来源:https://stackoverflow.com/questions/22504258/opencv-createsamples-has-no-error-but-no-samples-found

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