人机交互是当前最热门的话题,从 Microsoft 的 Kinect 到 Google 的 G-Glass ,都有可能成为划时代的产品。但与此同时,请别忘了在我们的电脑里面,本身就有一个非常独特的人机交互接口,Webcam。
该 Demo 是利用 Webcam 作为图形接口,结合 jp.maaash 作为人脸侦测的 AS3 程序,利用 ActionScript 你可以继续开发出有趣的人机互动软件,譬如人脸锁,使用人数计算器,人脸控制显示器,又或者是可以通过人脸侦测自动 Logout 等等
当然还可以通过 Opencv 做二次开发,利用其作为脸部识别的工具,这样在 Website 里面将会有更多有趣的应用,当然也可以用在智能家居的远程控制端。这些都是可行的。
首先我们需要的工具是 maaash 的库,这个可以google到很多下载的,当然本文最后提供的下载也有
主要代码如下
/**
* Initializes the detector
*/
private function _initDetector () : void {
_detector = new ObjectDetector;
_detector.options = getDetectorOptions( );
_detector.loadHaarCascades( "face.zip" );
}
初始化face库,必须的。
/**
* Gets dector options
*/
private function getDetectorOptions () : ObjectDetectorOptions {
_options = new ObjectDetectorOptions;
_options.min_size = 50;
_options.startx = ObjectDetectorOptions.INVALID_POS;
_options.starty = ObjectDetectorOptions.INVALID_POS;
_options.endx = ObjectDetectorOptions.INVALID_POS;
_options.endy = ObjectDetectorOptions.INVALID_POS;
return _options;
}
再设置下要判断的内容,大小啦等等
//timer for how often to detect
_detectionTimer = new Timer( __faceDetectInterval );
_detectionTimer.addEventListener( TimerEvent.TIMER , _detectionTimer_timer);
_detectionTimer.start();
//initalize detector
_initDetector();
//set up camera
_setupCamera();
//hook up detection complete
_detector.addEventListener( ObjectDetectorEvent.DETECTION_COMPLETE , _detection_complete );
做个timer,一个来输入bitmap数据,定义判断是否有face的event,setupCamera我就不post了,网上大把的。
/**
* Evalutates the webcam video for faces on a timer
*/
private function _detectionTimer_timer (event : TimerEvent) : void {
_bmpTarget = new Bitmap( new BitmapData( _video.width, _video.height, false ) );
_bmpTarget.bitmapData.draw( _video );
_detector.detect( _bmpTarget );
}
/**
* Fired when a detection is complete
*/
private function _detection_complete (event : ObjectDetectorEvent) : void {
//no faces found
if(event.rects.length == 0) return;
//stop the no-face timer and start back up again
_noFaceTimer.stop( );
_noFaceTimer.start();
就一句话就可以判断是否有face了。。接着就干你想干得事
感谢日本的 maaash 库,感谢OPENCV开源项目
http://www.ubekar.com/project-facedetectionAS3.html