/* * Clusters.as - Live Color Pointer Detection Example * Copyright (c) 2009 Yusuke Kawasaki http://www.kawa.net/ * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * */ package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.media.Camera; import flash.media.Video; import org.libspark.LivePointers.LP_Detector; public class Clusters extends Sprite { private var bmLive:Bitmap; private var lpdetector:LP_Detector; private var video:Video; static private var captureFPS:int = 30; static private var captureX:int = 320; static private var captureY:int = 240; static private var displayX:int = 640; static private var displayY:int = 480; static private var workX:int = 80; static private var workY:int = 60; public function Clusters ():void { bmLive = new Bitmap(); var spLive:Sprite = new Sprite(); spLive.addChild( bmLive ); spLive.scaleX = displayX / captureX; spLive.scaleY = displayY / captureY; this.addChild( spLive ); // Webcam var camera:Camera = Camera.getCamera(); if (!camera) { throw new Error('No camera found.'); } camera.setMode(captureX, captureY, captureFPS); // Video video = new Video(captureX, captureY); video.attachCamera(camera); // Live Pointer lpdetector = new LP_Detector(workX,workY); var spPointer:Sprite = lpdetector.getPreview(displayX,displayY); this.addChild(spPointer); this.addEventListener( Event.ENTER_FRAME, this.onEnterFrame ); } private function onEnterFrame (e:Event):void { var bmdLive:BitmapData = new BitmapData( captureX, captureY, false, 0xCCCCCC ); bmdLive.draw( video ); bmLive.bitmapData = bmdLive; lpdetector.setFrame(bmdLive); lpdetector.findClusters(); } } }