Record video and at the same time check whether the eyes are closed,how to achieve?

General discussion about topics related to OpenMV.
sxbug
Posts: 5
Joined: Mon Nov 06, 2017 7:02 am

Record video and at the same time check whether the eyes are closed,how to achieve?

Postby sxbug » Wed Nov 29, 2017 9:00 am

I want to use openmv3 to make a VCR with a button to turn on the video record . During the record if the eyes are closed, the red light is on. No body in the camera let the blue light up.
Can you tell me how to do it? Thanks
I would to know, can I save the video files into avi format? Compacted format
Thanks
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Record video and at the same time check whether the eyes are closed,how to achieve?

Postby kwagyeman » Thu Nov 30, 2017 1:00 am

Hi, sorry about not getting back to you for a while. You're basically asking for a lot of code.

Okay, let's start with this script in the examples folder:

Code: Select all

# MJPEG Video Recording on Face Detection Example
#
# Note: You will need an SD card to run this example.
#
# You can use your OpenMV Cam to record mjpeg files. You can either feed the
# recorder object JPEG frames or RGB565/Grayscale frames. Once you've finished
# recording a Mjpeg file you can use VLC to play it. If you are on Ubuntu then
# the built-in video player will work too.
#
# This example demonstrates using face tracking on your OpenMV Cam to take a
# mjpeg.

import sensor, image, time, mjpeg, pyb

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.
sensor.set_framesize(sensor.QQVGA) # or sensor.HQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.

# Load up a face detection HaarCascade. This is object that your OpenMV Cam
# can use to detect faces using the find_features() method below. Your OpenMV
# Cam has fontalface HaarCascade built-in. By default, all the stages of the
# HaarCascade are loaded. However, You can adjust the number of stages to speed
# up processing at the expense of accuracy. The frontalface HaarCascade has 25
# stages.
face_cascade = image.HaarCascade("frontalface", stages=25)

while(True):

    pyb.LED(RED_LED_PIN).on()
    print("About to start detecting faces...")
    sensor.skip_frames(time = 2000) # Give the user time to get ready.

    pyb.LED(RED_LED_PIN).off()
    print("Now detecting faces!")
    pyb.LED(BLUE_LED_PIN).on()

    diff = 10 # We'll say we detected a face after 10 frames.
    while(diff):
        img = sensor.snapshot()
        # Threshold can be between 0.0 and 1.0. A higher threshold results in a
        # higher detection rate with more false positives. The scale value
        # controls the matching scale allowing you to detect smaller faces.
        faces = img.find_features(face_cascade, threshold=0.5, scale_factor=1.5)

        if faces:
            diff -= 1
            for r in faces:
                img.draw_rectangle(r)

    m = mjpeg.Mjpeg("example-%d.mjpeg" % pyb.rng())

    clock = time.clock() # Tracks FPS.
    print("You're on camera!")
    for i in range(200):
        clock.tick()
        m.add_frame(sensor.snapshot())
        print(clock.fps())

    m.close(clock.fps())
    pyb.LED(BLUE_LED_PIN).off()
    print("Restarting...")
It will save mjpegs on seeing a face for you. Once I release the next OpenMV IDE release this weekend you'll be able to convert the mjpeg to avi on your computer.

Let me know if you can get the above script working. Then we can can it.
Nyamekye,
sxbug
Posts: 5
Joined: Mon Nov 06, 2017 7:02 am

Re: Record video and at the same time check whether the eyes are closed,how to achieve?

Postby sxbug » Thu Nov 30, 2017 9:16 am

Your example is very helpful , thank you. I also tested an example of eye detection provided by OPENMV IDE, which was not effective and could hardly be detect eyes. I'd like to know how to test the opening and closing of the eyes? THanks
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Record video and at the same time check whether the eyes are closed,how to achieve?

Postby kwagyeman » Thu Nov 30, 2017 11:54 am

Hi, the eye detection haar Cascade we have doesn't seem to work to well. I don't know how exactly that can be improved. The pupil detection algorithm we have does work okay once an eye is found... But the issue is finding the eyes.

If the subject isn't still then I don't really know how to make this work. If the subject is in a particular area then you can hard code the ROI and just check for a reduction in white pixels (white of eye) to detect if the eyes are closed. You can use the get statistics method to check on a reduction of white.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 2 guests