0

I tried with simpleCV, got a open source code, with simple modifications i am able to write down a code which is able to detect the blinking (at a particular position of image a small change appears and gone). Now i want to calculate the blinking per minute and want to plot a live graph. I saw some code and projects those used Fourier transform for this kind of work but not able to implement in my project , i finally landed here please help me out thanks in advance:

from SimpleCV import *

cam = Camera()
threshold = 5.0 # if mean exceeds this amount do something

while True:
        previous = cam.getImage() #grab a frame
        time.sleep(0.5) #wait for half a second
        current = cam.getImage() #grab another frame
        diff = current - previous
        matrix = diff.getNumpy()
        mean = matrix.mean()

        diff.show()

        if mean >= threshold:
                print "Motion Detected"
user3218971
  • 547
  • 1
  • 6
  • 21
  • Welcome to Stack Overflow. I think you will need to clarify your question: what exactly is the help that you are asking for? What problems are you having with the code that you posted? – GreenAsJade Jan 21 '14 at 11:51
  • @GreenAsJade This code is able to detect only the motion and generate mean value which is coming due to the motion. Using this further i want to calculate the bits or blinking per minute and want to plot a live graph – user3218971 Jan 21 '14 at 11:55
  • 1
    you need some time measurement like a timer (which measures time intervals), a counter (which counts the detected blinks) and then just calculate `counter/time_interval`. You can use a `moving average` or `exponential smoothing` to overcome the problems of variance within time intervals. – Micka Jan 21 '14 at 12:09
  • @ Micka could you please explain me the counter and time_interval with the given code which is provided with the Question, i am not a hard core programmer :( thanks for your suggestions. – user3218971 Jan 21 '14 at 12:35

1 Answers1

0

You already have everything you need. Due to the sleep you measure at a fixed intervall (lets call this a timeStep). You only need to save the "Blinks" together with a count that you increment with every loop iteration. The timer between two Blinks is then:

deltaT = abs(blink1.count - blink2.count)*timeStep

To get Blinks per Minute you can simply count the occured Blinks between now (current count) and now - 1 Minute (count per minute = 60/timeStep, if timeStep in seconds)

bpm = sum(blinkcounts[now-minute:now])

Note that all code in this Answer is Pseudcode and should only show Ideas and not complete solutions.

Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46