Sunday, 27 April 2014

Project 3. Painting in the air!

If you've followed all my tutorials till now, this project will seem very easy.
The only thing I've done is combine and interlink different concepts.
Object Detection, Circle Detection, Creating an Image Matrix, Video Rendering and Drawing Circles are included in this project.
With this, you've got quite a good exposure to Computer Vision and Image Processing.
You can play around with it and create your own applications.
Keep posting your doubts!

#include<iostream>
#include<highgui.h>
#include<cv.h>
using namespace std;
using namespace cv;

int main()
{
 VideoCapture cap(0);
 Mat frame;
 Mat img;

 namedWindow("video");
 namedWindow("shapes");
 namedWindow("paintbox");
 vector<Vec3f> circles;

 double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
 double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
 Mat paintbox=Mat(dHeight,dWidth,CV_8UC3,Scalar(255,255,255));
imshow("paintbox",paintbox);
 Mat pb_flipped;
 while(char(waitKey(1))!='q'){

  cap>>frame;

  cvtColor(frame,img,CV_RGB2GRAY);
  imshow("shapes",img);

  HoughCircles(img,circles,CV_HOUGH_GRADIENT,1,10,100,95,5);

  for(int i=0;i<circles.size();i++){

   Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));
   int radius=cvRound(circles[i][2]);


   circle(frame,center,3,Scalar(0,0,255),-1);
   circle(frame,center,radius,Scalar(0,0,255),3,8,0);

 //  Mat img_local=paintbox.clone();
   circle(paintbox,center,3,Scalar(0,0,255),-1);
   flip(paintbox,pb_flipped,1);
   imshow("paintbox",pb_flipped);
  }
  imshow("video",frame);
 }
 return 0;
}



No comments:

Post a Comment