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

asked 2017-04-30 11:11:58 -0600

WCF gravatar image

updated 2017-04-30 11:18:03 -0600

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;
}
edit retag flag offensive close merge delete

Comments

Must we guess your problem? Please extract a frame from video and show result with problem on this frame

LBerger gravatar imageLBerger ( 2017-04-30 11:20:44 -0600 )edit

try to detect the face first, then use facial landmarks(flandmark, dlib, FaceX) to get the eye/pupil position.

berak gravatar imageberak ( 2017-05-01 01:10:50 -0600 )edit

Problem are These two lines cant work.

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

You cant download video and figure out what error I have..

WCF gravatar imageWCF ( 2017-05-01 23:09:02 -0600 )edit