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.

Tuesday, June 12, 2012

Simple HTML Counter - count on tap - for Touchphones Android/iOS etc

I have a practice of chanting daily. For that I used to use a mechanical counter. Many times I bought that and it broke. I have a Android Smartphone. This time I made a small HTML page that will count on finger tap anywhere on mobile screen. The good thing in this is, when I walk, I can tap anywhere in the screen without seeing the screen and the count occurs unlike many other apps that contains a specific button to be pressed for counting. I made this thing for my personal use, but thought of sharing with people of similar requirements

Screenshot:  (In device: Tap anywhere on screen, count increases) Tested and working in Android and iOS (its HTML, device independent)
Steps:
from your mobile browser. If you want the code to be hosted online and follow from step 5 below

OR If you want to have it offline without Internet, follow the steps

1. Create a new file called "simplecounter.html"
2. Open it with any text editor (notepad, etc)
3. Paste this code in it
<!DOCTYPE html>
<html>
<head>
<title>Simple Counter by Hobby Coders</title>
</head>
<body>
<center>
<br/><br/><br/>
<h1>
<div id="count">0</div></h1>
<br/><br/><br/>
<font size="1">&copy;2012-13 HobbyCoders.com</font>
</center>
<script type="text/javascript">
var count=0;
var countPtr=document.getElementById('count');
document.addEventListener('touchstart', function(e){e.preventDefault(); count++; countPtr.innerHTML=count;}, false);
</script>
</body>
</html>
4. Copy this html file to your mobile device
5. Open this file in Android/iOS browser. Tap anywhere on the screen to count up
If in android it doesnt work in default browser, do this
RECOMMENDED FOR ANDROID: Install this file manager app from Google Play (https://play.google.com/store/apps/details?id=com.rhmsoft.fm) and open the html file with the "HTML Viewer" of this app. It works neat and clean
6. People who dont require hi-fi app for counting, people who just need such an app for chanting or similar purposes can use this app
7. And I didnt complicate the app with save last count, reset etc because, you go back from app and open it again in browser, count resets, and press Home key, the browser goes to background and you can continue later from the same count (multitasking)