I want to detect closed eyes after it closed 3 seconds [closed]

asked 2016-09-09 04:45:41 -0600

Pain gravatar image

This is a program to detect eyes closed. But i want after eyes closed 3 seconds, it will print "Warning" in terminal.

      for (x, y, w, h) in faces:
            cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)

            roi_gray = gray[y:y+h, x:x+w]
            roi_color = image[y:y+h, x:x+w]
            eyes = eyesCascade.detectMultiScale(roi_gray)
            if eyes is not():
                for (ex,ey,ew,eh) in eyes:
                    cv2.rectangle(roi_color,(ex -10 ,ey - 10),(ex+ew + 10,ey+eh + 10),(0,255,0),2)
                    twoeyes = twoeyesCascade.detectMultiScale(roi_gray)
                    checkyeys = 0
                    if twoeyes is not():
                        for (exx,eyy,eww,ehh) in twoeyes:
                            checkyeys = 0
                            led.write(1)
                            cv2.rectangle(roi_color,(exx-5 ,eyy -5  ),(exx+eww -5,eyy+ehh -5 ),(0,0, 255),2)
                    else:
                        #when eyes close
                        print "------------------------------------"
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-18 10:37:05.281125

Comments

1

And how do you think this will work? The cascade will trigger way to many false positives on closed eyes to ever get this to work. It is not robust enough for this task.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-09 05:52:28 -0600 )edit

You can suggest a few alternatives feasible.

Pain gravatar imagePain ( 2016-09-09 05:58:14 -0600 )edit

I think "eyes = eyesCascade.detectMultiScale(roi_gray)" will detect eyes area And " twoeyes = twoeyesCascade.detectMultiScale(roi_gray)" will detect two eyes. When I see eyes area but don't see two eyes that's when detect closed eyes.

Pain gravatar imagePain ( 2016-09-09 06:15:35 -0600 )edit

That won't work. Also, I only know of a right and left eye model and a general eye model, but there isn't a combined one. So where did you get that model?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-09 06:18:40 -0600 )edit

Thanks you! How to you know if eyes closed in 3 seconds

Pain gravatar imagePain ( 2016-09-09 06:27:02 -0600 )edit
1

For that you will need to either

  • Train a seperate model for open and one for closed eyes, using the positives of model one as negatives for the second one
  • Or use a single eye detector, then train an SVM to classify each eye as open or closed
StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-09 06:29:30 -0600 )edit