本文介绍了改善Haar训练效果的想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助获得更多有关我的首次哈尔训练结果的知识.因此,我想根据 Dileep Kumar's 文章.

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.

使用手机,我拍了14张笔图片.这些图片的尺寸很大: 263x2814
然后,我收集了负面图片,其中一些是从网上下载的,尺寸为 640x480 ,其中一些是使用我的手机摄像头制作的,尺寸为: 1920x1080,5313x2388

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

其中一些负面图片确实很大.我总共有158张负面图片.
之后,创建负片和正片图像列表并运行:createsamples命令:

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"

我不确定这里的160高度和20高度是否可以?
然后,在拥有samples.vec文件之后,使用以下命令运行级联训练:

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

我使用了相同的宽度和高度,但是不确定是否正确.我从一些参考脚本中获取了width和height值.获取了cascade.xml文件之后,我使用以下参数在图片上运行detectMultiScale:

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.

此处:

推荐答案

这些仅基于我的经验:

  1. 我认为,当原始图片的宽度和高度相等时,createsamples仅适用于 .这是因为当createsamples旋转图像时,如果宽度和高度不同,则图像将被剪切(进入正文件夹并查看其创建的图像.您将看到.)所以我的建议是...第一次,并且您想测试createsample(并且不知道其他方法),请选择宽度和高度相等的圆形或正方形对象.
  2. 您的负片和正片数量非常少...应该是数千个.
  3. 正如我在#1中所述,您的-w -h应该相等(如果使用createsamples).并且不要曾经使用超过25个(我建议20 20甚至15 15).因为我经历了非常长的训练时间而没有获得太多的检测(实际上,一旦我经历了较低的检测率,可能是训练时间的5到6倍).
  4. 在使用createsamples(也许100x100)之前,将所有负片图像调整为相同大小.并将原始图像的宽度和高度调整为一半或更小(也许是50x50).
  5. 您可以在traincascade命令中更改一些重要的变量,这些变量可以使检测效果更好,但它们会使训练变得异常冗长:

  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

警告::如果您要使用上述数字,则 基本上必须 使用LBP代替HAAR. HAAR的检测效果更好,但是使用LBP可以使用更好的值,因为它花费的时间更少(尽管使用这些数量和大量图像(+10000),可能仍需要几天的时间,但是将它们与HAAR一起使用,我 (几个月后见)).制作LBP的方法如下:-featureType LBP.
-minHitRate越接近1越好. -maxFalseAlarmRate越低,则越好. -maxWeakCount越高越好.
还要注意,设置得越好,所需的阶段数就越少.您可能拥有25个阶段的级联,而性能却不如6个阶段的级联,但设置良好.还应注意,当您使用这些数字时,您的火车级联可能似乎卡在获取负像上(虽然可以).

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

奇怪的是:为什么要检测笔时为什么使用faces = faceCascade.detectMultiScale? :D 不要让计算机比已经配对的计算机更加混乱. :D

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

这篇关于改善Haar训练效果的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 07:54