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.
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;
}