Closed eye detection opencv C++ - opencv

I need to detect closed eyes only and also both eyes separately. That means I need to tell if left eye is open or closed, also same about the right eye.
I tried few ways. One of them is to detect eyes with haarcascade_eye and haarcascade_eye_tree_eyeglasses separately and then compare the results. If both detect eye, then eye open, if one detect and another can't,then eye closed. This trick was taken from this link:
http://tech.groups.yahoo.com/group/OpenCV/messages/87666?threaded=1&m=e&var=1&tidx=1
But it doesn't work as expected.eye cascade detectors don't work as mentioned in the link. Much close results are found with those haarcascade that I mentioned above. Sometimes it gives correct result, sometimes it can't. I don't know why. Besides it can't be told with this method that which eye is open and which eye is closed.
Now can someone help me to solve this?? At least I need a way to tell that one of the eyes is closed regardless which one and need to do that accurately. Please help.......

If you want to avoid training your own Haar cascade to detect a single eye, you can attempt simpler techniques such as pupil detection. If you fail to detect a black circle, the eye is closed. If you have a smallish region of interest, this probably works very well. Another option would be color histograms of the eye region, which may look pretty different for the open and closed state.
If you cannot predict with reasonable accuracy where the eyes can be found in the image, these approaches are doomed and your best shot is training your own cascade I think.

Related

what is the range in value of levelweights in opencv detectmultiscale3?

I would like to know what range of values are returned by the levelWeights variable in OpenCV detectMultiScale3 so that I can understand the confidence level of the detection. What are minimum and maximum values? What is a good level to use as a cutoff for detection?
import cv2
faces, rejectLevels, levelWeights = faceCascade.detectMultiScale3(image_array, scaleFactor=1.05, minNeighbors=1, outputRejectLevels=True)
Just in case anyone got an answer. I am interested too.
So I did a few tests with a few subjects using the Haar Cascade Eye Detection. What I did was
Eyes wide open (abnormally raising the brows)
Eyes fully open (normal way an average person does it)
Eyes Half open (Squinting, but making sure the eye balls show a bit)
Eyes Closed (fully closed).
The sweet spot for me is anything above 3.
When eyes are fully closed, levelWeights are usually empty, but sometimes I get values that are way below 1. Anything below 3 is either half closed or fully closed.
So I guess you might have to do your own experiments to find the sweet spot.

straight line detection from a image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am doing a project which is hole detection in road. I am using a laser to emit beam on the road and using a camera to take a image of the road. the image may be like this
Now i want to process this image and give a result that is it straight or not. if it curve then how big the curve is.
I dont understand how to do this. i have search a lot but cant find a appropriate result .Can any one help me for that?
This is rather complicated and your question is very broad, but lets have a try:
Perhaps you have to identify the dots in the pixel image. There are several options to do this, but I'd smoothen the image by a blur filter and then find the most red pixels (which are believed to be the centers of the dots). Store these coordinates in a vector array (array of x times y).
I'd use a spline interpolation between the dots. This way one can simply get the local derivation of a curve touching each point.
If the maximum of the first derivation is small, the dots are in a line. If you believe, the dots belong to a single curve, the second derivation is your curvature.
For 1. you may also rely on some libraries specialized in image processing (this is the image processing part of your challenge). One such a library is opencv.
For 2. I'd use some math toolkit, either octave or a math library for a native language.
There are several different ways of measuring the straightness of a line. Since your question is rather vague, it's impossible to say what will work best for you.
But here's my suggestion:
Use linear regression to calculate the best-fit straight line through your points, then calculate the mean-squared distance of each point from this line (straighter lines will give smaller results).
You may need to read this paper, it is so interesting one to solve your problem
As #urzeit suggested, you should first find the points as accurately as possible. There's really no way to give good advice on that without seeing real pictures, except maybe: try to make the task as easy as possible for yourself. For example, if you can set the camera to a very short shutter time (microseconds, if possible) and concentrate the laser energy in the same time, the "background" will contribute less energy to the image brightness, and the laser spots will simply be bright spots on a dark background.
Measuring the linearity should be straightforward, though: "Linearity" is just a different word for "linear correlation". So you can simply calculate the correlation between X and Y values. As the pictures on linked wikipedia page show, correlation=1 means all points are on a line.
If you want the actual line, you can simply use Total Least Squares.

Eye blink detection when slightly moving/rotating photo

I implemented an eye blink detection solution using the research from this article:
http://www.iu.hio.no/~frodes/unitech10/011-Krolak/
I use a Haar eye classifier to identify the two eye regions, then using template matching on both eyes to detect blink state change. I also require that the face and eye regions remain fairly still. It works pretty well, except I occasionally get false positive on photos if I slightly move them (particularly rotate/scale). Does anyone have any suggestions to eliminate such cases? I don't want to make the stillness too strict, because it makes the live case unusable.
I have implemented with some success two cascades, one that detect open eyes and one that detect closed eyes.
You can use the face detector and restrict the search on the eyes region, then apply the "open eye" cascade. The good thing with that approach is that you can add slightly different poses and angles for the eyes on the training set. Worked really well for me.

Image Processing - Determine if someone looking into camera

with image processing libraries like opencv you can determine if there are faces recognized in an image or even check if those faces have a smile on it.
Would it be possible to somehow determine, if the person is looking directly into the camera? As it is hard even for the human eye to determine is someone is looking into the camera or to a close point, i think that this will be very tricky.
Can someone agree?
thanks
You can try using an eye detection program, I remember doing back a few years ago, and it wasn't that strong, so when we tilt our head slightly off the camera, or close our eyes, the eyes can't be detected.
Is it is not clear, what I really meant was our face must be facing straight at the camera with our eyes open before it can detect our eyes. You can try doing something similar with a bit of tweaks here and there.
Off the top of my head, split the image to different sections, for each ROI, there are different eye classifiers, for example, upper half of the image, u can train the a specific classifiers of how eyes look like when they look downwards, lower half of image, train classifiers of how eyes look like when they look upwards. and for the whole image, apply the normal eye detection in case the user move their head along while looking at the camera.
But of course, this will be based on extremely strong classifiers and ultra clear quality images, video due to when the eye is looking at. Making detection time, extremely slow even if my method is successful.
There maybe other ideas available too that u can explore. It's slightly tricky, but it not totally impossible. If openCV can't satisfy, openGL? so many libraries, etc available. I wish you best of luck!

how to recognize the object I detect in video frames is a people or a car

I have a problem to detect object in images or video frames.
I have a task that is detect some people or something who enter into the sight of web camera, and then my system will be alarm.
Next step is recognize which kind of thing the object is, in this phase I know use Hough transform to detect line, circle, even rectangle. But when a people come into the sight of camera, people's profile is more complex than line, circle and rectangle. How can i recognize the object is people not a car.
I need help to know that.
thanks in advance
I suggest you look at the paper "Histograms of Oriented Gradients for Human Detection" by Dalal and Triggs. They used Histograms of Oriented Gradients to detect humans in images
I think one method is to use Bayesian analysis on your image and see how that matches with a database of known images. I believe some people run a wavelet transform to emphasize more noticeable features.

Resources