Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: OpenCV
Hie.. I am doing a project and i need to detect eye blink of person in opencv. Can someone please tell me the steps of detecting blink or suggest me some sites from where i can study.
Posted 17-Feb-12 4:25am
Comments
Philippe Mori at 18-Feb-12 8:38am
   
I think that the eye blinks faster than what a camera can see so I don't think it is possible to do with common technologies.
BupeChombaDerrick at 25-Feb-12 18:13pm
   
Totally agree with Philippe, eye blinks are too fast, besides what use can you make of such a system (enlighten me), try using haarcascade_eye.xml file that comes with openCV to detect eye positions as a pre-processing stage and then see if you can invent a classifier to tell whether a person blinked. You can only capture such high speed events (blinks) using expensive high speed cameras which makes your project unfeasible and i doubt if the system you which to design can process frames at such high frame rates to be applicable.
Member 8329163 at 26-Feb-12 0:42am
   
actually i have to detect left and right blink and accordingly monitor the computer (left click-> left blink , right click-> right blink). If its not possible then can you please suggest me some other idea how can I remote control my computer using eye.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try checking out this link
TrackEye : Real-Time Tracking Of Human Eyes Using a Webcam[^]
 
I understand what you are trying to do.But instead of detecting rapid eye blinks why not detect whether one closes a right or left eye instead. With this suggestion, you need to detect faces first, see this link on how you can train a haar classifier to detect objects.
http://note.sonots.com/SciSoftware/haartraining.html[^]
 
Then you can train a second set of classifiers to scan only those detected regions for right and left eye. You can use two classifiers, one should detect closed eyes and the other open eyes, and just using a simple geometric constraint your system can tell whether the eye is on the right or left side,and based on the two classifier outputs the system can tell whether either eye is open or closed and it could output control signals based on that.
 
See also a tutorial code for openCV 2.3
 
https://code.ros.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp[^]
 
Hope this helps.
  Permalink  
Comments
Member 8329163 at 26-Feb-12 9:53am
   
Thanks a lot for your suggestion. I'll try to do it. Thank you.
Member 8329163 at 17-Mar-12 15:46pm
   
hie, i need help. I found a code for blink detection. I studied from the site http://opencv-code.com/Real_Time_Eye_Tracking_and_Blink_Detection , but its not working properly. I am not able to fix the problem and the code is error free. Can someone please suggest me how can i improve this code.
BupeChombaDerrick at 18-Mar-12 8:44am
   
please state clearly what you mean by "not working properly" ... because if the code is error free then the algorithm must not be okay. I'am taking a look at the code will get back to you after i do some analysis!
Member 8329163 at 18-Mar-12 15:01pm
   
I mean the code is not able to detect the blink and neither it is detecting the eyes. :(
Member 8329163 at 18-Mar-12 15:11pm
   
I guess it might be the problem of camera. I am using the camera of my laptop. As per your suggestion I tried detecting eyes and applied some function for the movement of cursor along with the movement of eyes. Here is the code and its working fine but as you said I need to detect left and right eyes individually and then closed eyes. I am not getting how to do it.
 

#include
#include "cv.h"
#include "highgui.h"
#include "X11/Xlib.h"
CvHaarClassifierCascade *cascade;
CvMemStorage *storage;
 
void detectFaces( IplImage *img );
int mouse(int delta_x,int delta_y) {
Display *display = XOpenDisplay(0);
Window root = DefaultRootWindow(display);
XWarpPointer(display, None, root, 0, 0, 0, 0, delta_x, delta_y);
XCloseDisplay(display);
}
int main( int argc, char** argv )
{
CvCapture *capture;
IplImage *frame;
int key;
char *filename = "haarcascade_eye.xml";
 
cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
storage = cvCreateMemStorage( 0 );
capture = cvCaptureFromCAM( 0 );
 
assert( cascade && storage && capture );
 
cvNamedWindow( "video", 1 );
 
while( key != 'q' ) {
frame = cvQueryFrame( capture );
 
if( !frame ) {
fprintf( stderr, "Cannot query frame!\n" );
break;
}
 
cvFlip(frame,frame,2);
frame->origin = 0;
 
detectFaces( frame );
 
key = cvWaitKey( 25 );
}
 
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
 
return 0;
}
 
void detectFaces( IplImage *img )
{
int i;
 
CvSeq *faces = cvHaarDetectObjects(img,cascade,storage,1.15,3,0,cvSize( 40, 20 ) );
 
for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ )
{
CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
cvRectangle( img,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),CV_RGB( 255, 0, 0 ), 1, 8, 0 );
mouse(2.1*r->x,1.8*r->y);
}
 
cvShowImage( "video", img );
}
 
please help.
Member 8329163 at 21-Mar-12 14:19pm
   
please help.. its urgent... I need to give update but i am not able to proceed further. :(
BupeChombaDerrick at 22-Mar-12 12:00pm
   
i think "haarcascade_eye.xml" is corrupted try "haarcascade_eye_tree_eyeglasses.xml" for eyes and "haarcascade_frontalface_alt.xml" for faces. see the code below for face detection,its a modification of your code. I ran it using OpenCV 2.3.1,though i did not include mouse(int delta_x,int delta_y) function here,i believe that's for you to do. But i see you want to detect eyes right away... though that will be error prone... do face detection using fast haar detector and then eye detection probably using template matching because haar classifiers don't seem to perform better than template matching on eyes. And use cvSize(20,20) for better results but you can always check the size in the xml file itself so don't use any size.
 
#include "opencv2/opencv.hpp"
 
using namespace cv;
 
CvHaarClassifierCascade *cascade;
 
CvMemStorage *storage;
 
void detectFaces( IplImage *img );
 
int main( )
{
CvCapture *capture; IplImage *frame = 0;
int key;
char *filename = "haarcascade_frontalface_alt.xml";
 
capture = cvCreateCameraCapture(0);
 
storage = cvCreateMemStorage(0);
 
cascade = (CvHaarClassifierCascade*)cvLoad( filename,storage, 0, 0 );
 
assert( cascade && storage && capture );
cvNamedWindow( "video", 1 );
while( capture )
{
frame = cvQueryFrame( capture );
if( !frame )
{
fprintf( stderr, "Cannot query frame!\n" );
break;
}

detectFaces( frame ); key = cvWaitKey( 25 );
}

cvReleaseCapture( &capture );
cvDestroyWindow( "video" );

cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
return 0;
}

void detectFaces( IplImage *img )
{
int i;
CvSeq *faces = cvHaarDetectObjects(img,cascade,storage,1.15,3,0,cvSize( 20, 20 ) );
for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ )
{
CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
cvRectangle( img,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),CV_RGB( 255, 0, 0 ), 1, 8, 0 );
}
 
cvClearMemStorage( storage );
cvShowImage( "video", img );
}
Member 8329163 at 24-Mar-12 2:14am
   
Thank you. But how to detect close eyes individually. Please help me.
Member 8329163 at 24-Mar-12 8:49am
   
I am not able to proceed further. I am going through IEEE papers. Do i need to track pupil or iris for this?
BupeChombaDerrick at 24-Mar-12 10:52am
   
You have to train your own haar classifier for that, but you can use template matching... or train an SVM (Support Vector Machine) classifier on open and closed eyes for both right and left eye ... detect faces using haar classifier and then run the SVM open and closed eye detector on those regions with faces. There is no easy way around this and so you need to put in the effort to train your own classifier.
Member 8329163 at 27-Mar-12 3:37am
   
thank you. And i am sorry to bother you so much but i need your help, i have not done any programming in image processing. I am new to it so i am getting lots of problem. I need to complete this project in 2 weeks. Can you please tell me what is wrong in this program http://opencv-code.com/Real_Time_Eye_Tracking_and_Blink_Detection . please..
Member 8329163 at 1-Apr-12 13:45pm
   
help please.. :(
Member 8329163 at 5-Apr-12 13:58pm
   
someone please help me.. its very urgent.. please help me with the code.. I am trying to detect close eyes by detecting pupil but its not working. I am getting circle randomly. I have used Hough transformation. Please I need help, I need to show my project within 5 days. Please can someone post the code for detecting close eye. Please...
BupeChombaDerrick at 5-Apr-12 18:36pm
   
Hey i wish i could help ... but i did look at the code. I couldn't find a reason why the program was not working. Try downloading and modifying this code http://www.codeproject.com/Articles/26897/TrackEye-Real-Time-Tracking-Of-Human-Eyes-Using-a
Just use template matching for closed eyes and set a detection threshold.
Member 8329163 at 11-Apr-12 7:13am
   
hie, I have tracked open eye and close eye. And i am able to detect whether left or right is open. Now i have to use click function. How can i left click and right click. Please can someone post the code. Please its urgent
Member 8877504 at 24-Apr-12 10:56am
   
Can you please send me the source code
Thanks in advance......
DASH_BODHISATTVA at 20-Apr-13 14:59pm
   
Can you please help me with the code you have implemented to find out whethr the eye i open or closed .. URGENT PLEASE !!!
Vikas Singh 10430882 at 27-Nov-13 22:47pm
   
Dear member 832916,
Can you please provide the source code to me so that I can work up on the same for my project as well.
I want the same mouse clicks to be generated by the blink of the eye. Please help.
 
Thanks in advance. Seeking your cooperation over this.
 
BupeChombaDerrick at 11-Apr-12 7:39am
   
wow i'am impressed. I think on the part of clicks you need to simulate mouse events. check http://msdn.microsoft.com/en-us/library/ms171548.aspx
Member 8329163 at 11-Apr-12 11:24am
   
Thank you :) but i didn't get anything. I am using opencv with c. But the code here is in .net and vb.Can you please suggest me Any other link from where I can get help.
BupeChombaDerrick at 11-Apr-12 12:34pm
   
check out http://www.cplusplus.com/forum/lounge/17053/
RaisKazi at 20-Apr-12 23:54pm
   
My 5.
BupeChombaDerrick at 21-Apr-12 13:13pm
   
Thanks RaisKazi
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I use your program in the first cite. but it said "cannot initialize capture"
how to solve it? please help me
  Permalink  
Comments
CHill60 at 1-Apr-14 18:50pm
   
if you have a question of your own then use the Red "Ask a question" link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 1 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100