Ask Your Question

calculating how many times white pixels appear form frame difference

asked 2015-12-06 05:40:43 -0500

tofi gravatar image


I'm now working on this steps to detect blinks

  1. calculate Frame difference = current frame - previous frame using (cv2.absdiff)

  2. convert the result of Frame difference to binary image (threshold cv2.threshold) and cv2.countNonZero() ) .

  3. Eroding and Dilating (cv2.morphologyEx (openmorphologyEx )

with these steps the result is when the eyes blinks there is white pixels like the image below :

image description


when the eyes open there is not whote pixels only black output like image below

image description

Now I want to calculate rate of blinks based on white pixels when eyes blinks . for example a counter that counts

how many these white pixels detected . thanks for help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-12-06 09:53:08 -0500

Brandon212 gravatar image

You can use countNonZero() which returns an int of how many nonzero pixels are in a frame. To account for noise you could use some kind of minimum score that's required before you count the eyes as present, but just put that in your loop and you'll be set.

edit flag offensive delete link more


I have used countNonZero() like this :

delta_count = cv2.countNonZero(frame_delta) print delta_count it shows different numbers like : 1151 878 751 891 868 I don't know how to classify them . is there any other ways like contours ?

tofi gravatar imagetofi ( 2015-12-06 10:03:28 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-12-06 05:40:43 -0500

Seen: 301 times

Last updated: Dec 06 '15