Thursday, June 14, 2012

Webcam real time background remove using Flash/Actionscript/Flex

Today, I was trying a small prototype for my new project on actionscript for Hobby Coders, for that I had to make a good background remove script in actionscript. I wanted to choose HTML5 for this. If it were a desktop app, its wise to go with openCV with C for their rich libraries and speed. But for certain modules, flash was chosen.

Demo (Fixed threshold): http://hobbycoders.com/demos/backgroundremove/fixed_threshold
Code (Fixed threshold - Actionscript): http://hobbycoders.com/demos/backgroundremove/fixed_threshold/code.txt

Demo (Variable threshold): http://hobbycoders.com/demos/backgroundremove/variable_threshold
Code (Variable threshold - Flex 3): http://hobbycoders.com/demos/backgroundremove/variable_threshold/code.txt

Here is the algorithm Im using:
1. Save a bitmap (we will call it BMP_BG) of the background without the person
2. From now the current frame is compared with BMP_BG, pixel by pixel
3. For comparison, I calculate the luminance value (one used in Grey scale) for each pixel for both the images and compare this value, so that their difference lie inside a threshold value
4. If they both are same, I put the pixel of the rendered image as white otherwise, I copy the corresponding pixel from the current frame 

Please take a look at them guys, if someone wants similar codes, ofcourse feel free to use mine but please give your feedbacks here! If anyone can suggest me a better method, please post here too.

Still im continuously optimizing the algorithm that Im using to get a perfect result. If I get a better result, I will definitely share the idea with you all.

No comments:

Post a Comment