OpenCV的使用和机器学习简单的物体检测 [英] Simple object detection using OpenCV and machine learning

查看:512
本文介绍了OpenCV的使用和机器学习简单的物体检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不code的对象检测器(在这种情况下,球)使用的OpenCV。问题是,在谷歌的每一个搜索返回我与它人脸检测的东西。所以,我需要帮助就从哪里开始,用什么等等。

I have to code an object detector (in this case, a ball) using OpenCV. The problem is, every single search on google returns me something with FACE DETECTION in it. So i need help on where to start, what to use etc..

一些信息:


  • 球并没有一个固定的颜色,它可能会是白色的,但它可能会改变。

  • 我不得不使用机器学习,并不一定是一个复杂而可靠的,建议是KNN(这是WAY简单,更容易)。

  • 我所有的搜索后,我发现,计算样本球仅适用于图像的直方图,并教给了ML可能是有用的,但我在这里主要关注的是,球的大小能够而且将会改变(从越走越进一步摄像头),我有什么要传递到ML为我归类不知道,我的意思..我不能(或者可以吗?)只是测试图像的每个像素每个可能的大小(从,可以说, 5×5至宽x高),并希望能找到一个积极的结果。

  • 有可能是不均匀的背景,喜欢的人,布球,等等。
  • 背后
  • 正如我所说的,我必须使用ML算法,这意味着没有哈尔或中提琴算法。

  • 另外,我想使用的轮廓找到Canny'ed图像上圈,就必须找到一个方法来转换成轮廓数据教KNN的一排。

  • The ball doesn't have a fixed color, it will probably be white, but it might change.
  • I HAVE to use machine learning, doesn't have to be a complex and reliable one, suggestion is KNN (which is WAY simpler and easier).
  • After all my searching, i found that calculating the histogram of samples ball-only images and teaching it to the ML could be useful, but my main concern here is that the ball size can and will change (closer and further from the camera) and i have no idea on what to pass to the ML to classify for me, i mean.. i can't (or can I?) just test every pixel of the image for every possible size (from, lets say, 5x5 to WxH) and hope to find a positive result.
  • There might be a non-uniform background, like people, cloth behind the ball and etc..
  • As I said, i have to use a ML algorithm, that means no Haar or Viola algorithms.
  • Also, I thought on using contours to find circles on a Canny'ed image, just have to find a way to transform a contour into a row of data to teach the KNN.

所以...建议?

在此先感谢。
;)

Thanks in advance. ;)

推荐答案

好了,基本上你需要检测的圈子即可。你见过 cvHoughCircles()?你被允许使用它?

Well, basically you need to detect circles. Have you seen cvHoughCircles()? Are you allowed to use it?

此页面有关于如何检测与OpenCV的东西。您可能会在<一个更感兴趣href=\"http://cgi.cse.unsw.edu.au/~cs4411/wiki/index.php?title=OpenCV_Guide#Detecting_circles\">section 2.5

This page has good info on how detecting stuff with OpenCV. You might be more interested on section 2.5.

这是一个小的演示中,我只是写来检测这幅画硬币。希望你可以使用code的某些部分,你的优势。

This is a small demo I just wrote to detect coins in this picture. Hopefully you can use some part of the code to your advantage.

输入

Input:

输出

Outputs:

// compiled with: g++ circles.cpp -o circles `pkg-config --cflags --libs opencv`
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>

int main(int argc, char** argv)
{
    IplImage* img = NULL;

    if ((img = cvLoadImage(argv[1]))== 0)
    {
        printf("cvLoadImage failed\n");
    }

    IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    CvMemStorage* storage = cvCreateMemStorage(0);

    cvCvtColor(img, gray, CV_BGR2GRAY);

    // This is done so as to prevent a lot of false circles from being detected
    cvSmooth(gray, gray, CV_GAUSSIAN, 7, 7);

    IplImage* canny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    IplImage* rgbcanny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
    cvCanny(gray, canny, 50, 100, 3);

    CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, gray->height/3, 250, 100);
    cvCvtColor(canny, rgbcanny, CV_GRAY2BGR);

    for (size_t i = 0; i < circles->total; i++)
    {
         // round the floats to an int
         float* p = (float*)cvGetSeqElem(circles, i);
         cv::Point center(cvRound(p[0]), cvRound(p[1]));
         int radius = cvRound(p[2]);

         // draw the circle center
         cvCircle(rgbcanny, center, 3, CV_RGB(0,255,0), -1, 8, 0 );

         // draw the circle outline
         cvCircle(rgbcanny, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );

         printf("x: %d y: %d r: %d\n",center.x,center.y, radius);
    }


    cvNamedWindow("circles", 1);
    cvShowImage("circles", rgbcanny);

    cvSaveImage("out.png", rgbcanny);
    cvWaitKey(0);

    return 0;
}

圈子的检测对 cvHoughCircles的参数取决于很多()。注意,在这个演示中,我使用的康力为好。

The detection of the circles depend a lot on the parameters of cvHoughCircles(). Note that in this demo I used Canny as well.

这篇关于OpenCV的使用和机器学习简单的物体检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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