OpenCV:detectMultiScale()给出太多的点对象 [英] OpenCV: detectMultiScale() gives too many points out of the object

查看:2221
本文介绍了OpenCV:detectMultiScale()给出太多的点对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我训练我的电脑与 opencv_traincascade 所有一天,以检测2€硬币使用超过6000正面图像类似于以下:

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

现在,我只是尝试运行一个简单的OpenCV程序来查看结果,以检查文件 cascade.xml 。最终结果非常令人失望:

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

< img src =http://i.stack.imgur.com/xzcSw.jpgalt =enter image description here>

有许多点在硬币,但也有许多其他点在背景上。这是我的正面图像用于培训的一个问题吗?或者,我可以使用带有错误参数的 detectMultiScale()吗?

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

这是我的代码:

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  //equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}



我还试图减少邻居的数量,但效果是一样的,只是与许多较少的点...这可能是一个问题的事实,在积极的图像有那些4角作为背景周围的硬币?我使用Gimp从一个拍摄视频显示硬币生成png图像,所以我不知道为什么 opencv_createsamples 放这四个角。

推荐答案

这些正图片只是简单的 错误

Those positive images are just plain wrong

更多的噪音你给你的图像的训练数据的部分,那么更强大,它会是,但是,需要更长的时间训练。然而,这是你的消极sampels将采取行动。如果你有尽可能多的负训练样本尽可能多的范围,那么你会创建更强大的检测器。您需要确保您的正面图片只有您的硬币,您的所有负片图片都有其中的所有 硬币

The more "noise" you give your images on the parts of the training data then the more robust it will be, but yes the longer it will take to train. This is however where your negative sampels will come into action. If you have as many negative training samples as possible with as many ranges as possible then you will create more robust detectors. You need to make sure your positive images only have your coins in, all your negative images have everything but coins in them

我见过你的几个问题到现在&我想你想检测三种不同类型的欧元硬币。你最好在这些不同的硬币上训练三个分类器,然后在你的图像上运行这三个分类器。

I've seen a couple of your questions up to now & I think you want to detect three different types of euro coins. You would be best training three classifiers all on those different coins and then running all three on your images.

我想你也缺少一个关于HAAR作品(或LBP或其他),它从你的正面图像创建一组功能,然后试图找到这些功能在运行分类器的图像。它通过确定你的正面图像和你的负面图像之间的不同,创建这些功能。

I think also you are missing a key piece of knowledge on how HAAR works (or LBP or whatever) effectively it creates a set of "features" from your positive images then tries to find those features in the images you run the classifier over. It creates these features by working out what is different between your positive images and your negative images. You don't want anything that isnt going to be the thing you are trying to detect in your positive images.

编辑1 - 范例

想象一下,为道路停车标志创建一个分类器,这是一个类似于硬币的检测。它很大,它是红色&它是六角形的。

Imagine creating a classifier for a road stop sign, which is a similar detection to coins. It's big, it's red & it's hexagonal. Creating a classifier for this is relatively easy - as long as you don't confuse the training stage with erroneous data.

编辑2 - 缩放图像:

Edit 2 - Scaling of images:

你还要记住,当运行检测阶段时,它需要你的分类器,开始小,然后放大。大的,明显的特征将被更快地检测到 - 在我的前面的示例中大红色斑点&六边形。

You have to also remember that when running the detection stage it takes your classifier and starts small and then scales up. Large, obvious features will get detected quicker - in my previous example big red blobs & hexagonal shapes. It would then start on small features i.e. text, or numbers.

编辑3 - 更好的例子

这个例子显示了你如何训练级联对象检测器的工作原理。事实上,它甚至有一个与停车标志相同的例子!

This example shows you really well how training a cascade object detector works. In fact it even has the same example as with a stop sign!

这篇关于OpenCV:detectMultiScale()给出太多的点对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆