Detecting boundaries of a person in webcam

Imagine an application where a person is standing in front of a webcam kiosk and you want to check if that person is tall enough to touch some navigation at the top of the screen. You want to position the navigation elements lower to increase the usability because the cam is fixed so can’t be moved down. The following code is a solution (there are a lot more I guess) to check how tall a person is who stands in front of a webcam. We will draw a red line above the person’s head when it is detected. If you want you can extend this little example to completely detect a persons boundaries 🙂

DETECT height of person in front of webcam

Code:

var my_cam:Camera;
my_cam = Camera.get();

//camera preferences ==> 25= frames per second
my_cam.setMode(640, 480, 25);
videoHolder.my_video.attachVideo(my_cam);

var now:BitmapData = new BitmapData(640, 480);
var before:BitmapData = new BitmapData(640, 480);
var rect:Rectangle = new Rectangle(0, 0, 640, 480);
var pt:Point = new Point(0, 0);
var counterHeight:Number = 0;
var __detectionValue:Number = 10000000;
var __trackInterval:Number = 100;

now.draw(videoHolder, videoHolder.transform.matrix, new ColorTransform(), 'difference');
now.threshold(now, rect, pt, '>', 0xffBBBBBB, 0xff000000);
//start interval
trackHeightPersonInterval = setInterval(this, "trackHeightPerson", __trackInterval/4); 

/////////////////////////// 

function trackHeightPerson() { 

////////////////////////// 

var fixedXValue:Number = videoHolder._width/2; 

if (!my_cam.muted) { 

if (counterHeight>=now.height) { 

} else 	{ 

var val = now.getPixel(fixedXValue, counterHeight);
	if (val>__detectionValue) {
		clearInterval(trackHeightPersonInterval);
		//place boundary
		_root.createEmptyMovieClip("line_mc", _root.getNextHighestDepth());
		line_mc.lineStyle(3, 0xFF0000, 100);
		line_mc.moveTo(0, counterHeight);
		line_mc.lineTo(640, counterHeight);
		var scaleValue:Number = Math.round((1/(480/counterHeight)*100));

//do some action
		//...
		counterHeight = 0; 

} else {
		counterHeight += 5;
	} 

} 

}
}
Advertisements

3 responses to “Detecting boundaries of a person in webcam

  1. tin408 25 August , 2006 at 2:54 am

    Thanks for that tip. You are so right. Definitely it’s hard to presume one’s height over the webcam. People tend to lie over the net all the time, that is if you chat with someone else. And so when asked about their height, they lie about it! Now , since you gave me the tip I suppose all lies have to end!

  2. Tem 5 December , 2006 at 8:19 pm

    Do you have a working axample of this? I tried to recreate it but i didn’t succeed.

    But the idea is great!

  3. herbert 5 February , 2007 at 1:31 pm

    nice and lovely

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s