Ask Your Question

Revision history [back]

real-time pupil center from video code cant work??

#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap("D:/MyVideo1.avi"); // open the video camera no. 0
    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
   while (1)
   {
       Mat frame, grey, edge;
       bool bSuccess0 = cap.read(frame); // read a new frame from video 0
       if (!bSuccess0) //if not success, break loop
       {
           cout << "ERROR: Cannot read a frame from video file" << endl;
           break;
       }
       cvtColor(frame, grey, CV_BGR2GRAY);   // get a new frame from   camera
       Canny(grey, edge, 50, 150, 3);
       threshold(edge, edge, 150, 255, THRESH_BINARY | THRESH_OTSU);      
       vector<Vec3f> circles;
       HoughCircles(edge, circles, 3, 1, 10, 100, 30, 11, 49);

       for (size_t i = 0; i < circles.size(); i++)
       {
           printf("Found circles");
           Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
           int radius = cvRound(circles[i][2]);
           circle(frame, center, 3, Scalar(0, 255, 0), -1, 8, 0);
           circle(frame, center, radius, Scalar(0, 0, 255), 3, 8, 0);
       }
       imshow("MyVideo", grey);
       if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
           cout << "esc key is pressed by user" << endl;
           break;
       }
   }

   return 0;
}

real-time pupil center from video code cant work??

video download: (https://) drive.google.com/open?id=0ByiWjC8usraqZGVmWjlmeE9TVzQ

#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap("D:/MyVideo1.avi"); // open the video camera no. 0
    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
   while (1)
   {
       Mat frame, grey, edge;
       bool bSuccess0 = cap.read(frame); // read a new frame from video 0
       if (!bSuccess0) //if not success, break loop
       {
           cout << "ERROR: Cannot read a frame from video file" << endl;
           break;
       }
       cvtColor(frame, grey, CV_BGR2GRAY);   // get a new frame from   camera
       Canny(grey, edge, 50, 150, 3);
       threshold(edge, edge, 150, 255, THRESH_BINARY | THRESH_OTSU);      
       vector<Vec3f> circles;
       HoughCircles(edge, circles, 3, 1, 10, 100, 30, 11, 49);

       for (size_t i = 0; i < circles.size(); i++)
       {
           printf("Found circles");
           Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
           int radius = cvRound(circles[i][2]);
           circle(frame, center, 3, Scalar(0, 255, 0), -1, 8, 0);
           circle(frame, center, radius, Scalar(0, 0, 255), 3, 8, 0);
       }
       imshow("MyVideo", grey);
       if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
           cout << "esc key is pressed by user" << endl;
           break;
       }
   }

   return 0;
}