Reputation: 1924
I have found some examples in C++ of how to detect a blink of an eye using OpenCV.
Unhapilly its pretty hard to find the same for Android.
I have found this:
case Sample2NativeCamera.VIEW_MODE_HOUGH_CIRCLES:
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2GRAY, 4);
// doing a gaussian blur prevents getting a lot of small false circles
Imgproc.GaussianBlur(mGray, mGray, new Size(5, 5), 2, 2);
// the lower this figure the more spurious circles you get
// 50 looks good in CANNY, but 100 is better when converting that into Hough circles
iCannyUpperThreshold = 100;
Imgproc.HoughCircles(mGray, mIntermediateMat, Imgproc.CV_HOUGH_GRADIENT, 2.0, mGray.rows() / 8,
iCannyUpperThreshold, iAccumulator, iMinRadius, iMaxRadius);
if (mIntermediateMat.cols() > 0)
for (int x = 0; x < Math.min(mIntermediateMat.cols(), 10); x++)
{
double vCircle[] = mIntermediateMat.get(0,x);
if (vCircle == null)
break;
pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
radius = (int)Math.round(vCircle[2]);
// draw the found circle
Core.circle(mRgba, pt, radius, colorRed, iLineThickness);
// draw a cross on the centre of the circle
DrawCross (mRgba, pt);
}
if (bDisplayTitle)
ShowTitle ("Hough Circles", 1);
break;
But I have no idea on how to use it in my OpenCV sample code. I have all OpenCV sample codes. I am playing with the OpenCV - Face Detection.
I just changed the cascade from Frontal Face to Eyes. So, it works... it detects the eyes.
However I need to detect more than just the position of the eyes. I need to detect when a user blinks an eye. I saw the code above but I have no idea on how to use it in my OpenCV Face Detection code, since it uses a cascade to detect the eyes. The method above is not using cascades. So, how can I use it?
Any ideas on how can I check the blink of an eye using OpenCV?
I am for almost one week looking for this information in Google and in here but I just can't find one that works with Android. =(
Any help is welcome!
Upvotes: 2
Views: 7120
Reputation: 1586
Google has released a FaceDetectorApi() for Android which gives us the probability of the eye opened for both eyes, using which we can detect eye blinks, here is the project implementation I have done, it works in real time https://github.com/murali129/Eye-blink-detector
Upvotes: 1
Reputation: 81
I don't know exactly how are your implementation but this code will be helpful to recognize circles, in this case for pupil. You can get a eye roi (region of interest) with Viola Jones, apply the Canny detector and after look for circles (open eye) or line (closed eye) using Hough Transformation.
Some useful links:
Viola Jones: http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html
Hough Transform: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html
Canny detector: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html
Another approach is using Match Template, like http://www.technolabsz.com/2013/05/eye-blink-detection-using-opencv-in.html
Upvotes: 1
Reputation: 46415
If you can detect the eyes, then you could look for the eyes disappearing then reappearing very quickly. This would look like a blink. If you can detect the mouth, then you could make sure it remained in roughly the same place also.
Upvotes: 1
Reputation: 692
If you have the blink detection function in c++ you can use a Native function (JNI) call to the function from android than return a boolean True or false depending the detection to your java code.
Upvotes: 0