Ideas to improve Haar training results

杀马特。学长 韩版系。学妹 提交于 2019-12-11 09:24:56

问题


Please help to get more knowledge on the my first-time haar training results. So I want to train Haar classifier to recognize simple pen, following Dileep Kumar’s article.

Using my cellphone I made 14 pen pictures. These pictures size is big about: 263x2814
Then I collected negative pictures, some of them downloaded from web, with size 640x480, and some of them made using my phone camera, with size: 1920x1080,5313x2388

Some of these negative images are really big. I have total 158 negative images.
After that create negative and positive images list and run the: createsamples command:

 perl createtrainsamples.pl positives.dat negatives.dat samples 250  "opencv_createsamples  -bgcolor 0 -bgthresh 0 -maxxangle 0.5 -maxyangle 0.5 maxzangle 0.5 -maxidev 40 -w 160 -h 20"

I am not sure here if 160 for with and 20 for height is okay or not?
And then after having samples.vec file I run the cascade training, using this command:

opencv_traincascade -data firstTry -vec samples.vec  -bg negatives.dat -numPos 250 -numNeg 99 -numStages 25 –featureType HAAR  -mode ALL -w 160  -h 20 -mem 2048

I used the same width and height, but not sure if this is something right. I took the width and height values from some reference script. After getting the cascade.xml file, I am running the detectMultiScale on my picture using the following argument:

faces = faceCascade.detectMultiScale(   image,   scaleFactor=1.4,  minNeighbors=3,   minSize=(30, 30) )

The detection does not work well. It is just detecting some parts of the pen and not the full pen.
Also when I have some photo where pen is put in environment, than pen is not being detected.

I think I need to resize all positive and negative images and make them same size, though not sure on this.
Could you please provide some opinions on what I have done wrong here and how I can improve my results.

You can find all my files here:


回答1:


These are only based on own my experience:

  1. I think createsamples works well only when the width and height of your original image are equal. This is because when createsamples rotates your image, if the width and height are different the image gets cut (Go into your positive folder and look at the images it created. You'll see.) So my advice is... if this is your first time and you want to test createsamples (and don't know any other ways), choose a round or square object with equal width and height.
  2. Your number of negative and positive images are very very low... it should be in the thousands.
  3. As I said in #1 your -w -h should be equal (if using createsamples). And don't EVER use more than 25 for each of them (I recommend 20 20 or even 15 15). As I have experienced very very long training times without much gain in detection (actually once I experienced lower detection rate with maybe 5 or 6 times the training time).
  4. Resize all your negative images to be the same size before using createsamples (maybe 100x100). and resize your original image to be half or lower in width and height (maybe 50x50).
  5. There are some important variables you can change in traincascade command that make detection far better but they will make the training excruciatingly long:

    -minHitRate 0.999 -maxFalseAlarmRate 0.1 -maxWeakCount 1000
    

    Be warned: If you are going to use the above numbers you basically have to use LBP instead of HAAR. HAAR has better detecting but with LBP you can use better values because it takes way less time (although with these numbers and lots of images (+10000) it might still take days but use these with HAAR and I may be seeing you in a few months ). Here's how you make it LBP: -featureType LBP.
    The closer -minHitRate is to 1 the better. The lower -maxFalseAlarmRate is to 0 the better. And the higher -maxWeakCount the better.
    Also note that the better you set these up the less number of stages you need to go. You might have a 25-stage cascade that performs worse than a 6-stage cascade with a good set up. Also also note that your traincascade might seem like it is stuck on getting the negative images when you use these numbers (It's okay though).

  6. Also lighting is very important in detection. Use a room with good lighting to get better results.

On a weird note: why did you use faces = faceCascade.detectMultiScale when you want to detect pens. :D Don't make the computer more confused than it already is mate. :D



来源:https://stackoverflow.com/questions/45798288/ideas-to-improve-haar-training-results

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