Ignoring black frames while starting a webcam

While playing with motion detection with a Webcam, I ran into a surprising problem. First n frames are 100% black. The number of frames vary, so this problem wasn’t solved with ignoring first 10 frames or anything similar. So I used getColorBoundsRect to detect any non-black pixels and when found, the WebCam class would start to send an event. The video will be visible before dispatching events, but it could be hidden until the event is dispatched.

This class also handles the size of the video, errors, bitmap capturing and almost anything so it is quite usable in any webcam project. You can also skip the deteection of those black frames.

(note: maybe this could have been done with Camera.activityLevel, but this solution was quicker for me)

Download the class and sample files.

Kommentoi