简单的OpenCV项目-检测和跟踪网球 [英] Simple OpenCV project - detecting and tracking a tennis ball

查看:230
本文介绍了简单的OpenCV项目-检测和跟踪网球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我需要使用OpenCV来检测网络摄像头上的物体(网球),并且要获得奖励积分,请在将其滑过桌子时对其进行跟踪.

I have a project where I need to use OpenCV to detect an object (Tennis Ball) on a webcam, and for bonus credit, track it when I roll it across the table.

由于我使用的是OpenCV 2.4,C ++,因此没有太多运气来查找信息,而很多信息都在较旧的OpenCV版本中.我已经阅读了很多有关执行此操作的不同方法的信息,但是我只是不知道如何将其实现到我的代码中.

I haven't had much luck finding info on this, since I'm using OpenCV 2.4, C++, and a lot of information is in the older OpenCV version. I've read a lot of about different ways to do it, but I just don't know how to implement it into my code.

任何帮助将不胜感激,尤其是在如何将检测/跟踪功能集成到我的代码中

Any help would be appreciated, especially on how to integrate a detection/tracking function into my code

到目前为止,这是我的代码,我认为应在应用过滤器后执行图像检测/跟踪代码:

Here is my code so far, I think the image detection/tracking code should go after I apply the filters:

//Includes & Namespaces
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace cv;
using namespace std;


//Main Function
int main(int, char**)
{
    VideoCapture vid(0); //Capture from Webcam
    if(!vid.isOpened()) //Error Check for Webcam
    {
        cout << "Could not open camera" << endl;
        return -1;
    }

    Mat pic; //Create Matrix to store image
    namedWindow("video",1); //Open Window

    for(;;) //Infinite loop
    {
        Mat frame; //Create Matrix for a single frame
        vid >> frame; //Transfer from webcam to matrix

        //Filters
        cvtColor(frame, pic, CV_BGR2HSV);
        GaussianBlur(pic, pic, Size(7,7), 1.5, 1.5);

        /*Image Detection Here */           

        imshow("Picture", pic); //Show image

        if(waitKey(30) >= 0)
        break;
    }
    return 0;
}

推荐答案

您尝试谷歌搜索您的问题吗?有很多关于此的信息.

Did you try to google your question? There are many info about that.

下一步是简单的想法:使用颜色阈值检测(似乎是黄色或白色)来检测您的对象颜色)和圆圈检测.检测到球后,您只需使用(例如) Lucas-Kanade对其进行跟踪方法.

Simple idea is next: detect your object using color thresholding (it seems that it's yellow or white color) and circle detection. After ball is deteccted you need to just track it using (for example) Lucas-Kanade method.

以下是一些指南/手册:

Here are some guides/manuals:

  1. 跟踪彩色对象OpenCV
  2. 运动分析和对象跟踪
  3. 学习OpenCV
  4. 查看OpenCV的文件夹samples.有很多非常有用的例子.根据您的情况,最好的示例是samples/cpp/lkdemo.cpp.
  1. Tracking colored objects OpenCV
  2. Motion Analysis and Object Tracking
  3. Learning OpenCV
  4. Look at OpenCV's folder samples. There'are many very useful examples. In your situation the best example is samples/cpp/lkdemo.cpp.

这篇关于简单的OpenCV项目-检测和跟踪网球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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