利用 AS3 实现人脸侦测的代码

人机交互是当前最热门的话题,从 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


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值