Changeset 17274 for lang/actionscript
- Timestamp:
- 08/08/08 23:38:39 (4 months ago)
- Location:
- lang/actionscript/ashaardetect/trunk/cv
- Files:
-
- 1 added
- 4 modified
-
HaarCascade.as (modified) (6 diffs)
-
HaarCascade.mas (modified) (6 diffs)
-
IStreamingControl.as (added)
-
RectPool.as (modified) (2 diffs)
-
VideoDetector.as (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/ashaardetect/trunk/cv/HaarCascade.as
r17214 r17274 17 17 private var mMaxWinWidth:uint = 1000000; 18 18 19 function HaarCascade() 20 { 21 19 private var mSpecificityList:Array; 20 21 function HaarCascade() 22 { 23 24 } 25 26 public function get specificityListStep():uint 27 { 28 return 10; 29 } 30 31 public function get specificityList():Array 32 { 33 return mSpecificityList; 34 } 35 36 public function initSpecificityList(n:uint):void 37 { 38 mSpecificityList = new Array(n); 39 for (var i:uint = 0;i < n;i++) 40 mSpecificityList[i] = 1; 22 41 } 23 42 … … 67 86 private static const NPASS:uint = 2; 68 87 private static const INVALID_MASK:uint = 0xffffff; 69 public function detect(bmp:BitmapData, scale_factor:Number, min_width:int = 0, min_height:int = 0, limit:int = -1):Object88 public function detect(bmp:BitmapData, entire_skip:Boolean, scale_factor:Number, min_width:int = 0, min_height:int = 0, limit:int = -1):Object 70 89 { 71 90 if (!mYieldContext.enabled) { … … 97 116 var mask_index:uint = mYieldContext.mask_index; 98 117 var hueval:Number; 118 119 var skip:Boolean = false; 99 120 100 121 if (scale_factor == 0) … … 115 136 continue; 116 137 138 if (mSpecificityList) 139 { 140 if ( mSpecificityList[int(winWidth/10)] == 0 ) 141 { 142 if (entire_skip) continue; 143 skip = true; 144 } 145 else 146 skip = false; 147 } 148 117 149 var stop_height:uint = (srcHeight - winHeight) / ystep; 118 150 var result:int; … … 124 156 for(var _iy:uint = mYieldContext._iy; _iy < stop_height; _iy++) 125 157 { 158 if (skip && (_iy & 1) != 0) 159 { 160 mYieldContext._iy = 0; 161 continue; 162 } 163 164 126 165 if (--limit == 0) 127 166 { saveContext(_iy, pass, resrects1, factor, mask_index, sums); return YIELDED; } … … 161 200 } 162 201 else if( result < 0 ) { 163 _xstep = 1; 202 if (!skip) 203 _xstep = 1; 164 204 } 165 205 -
lang/actionscript/ashaardetect/trunk/cv/HaarCascade.mas
r17214 r17274 19 19 private var mMaxWinWidth:uint = 1000000; 20 20 21 private var mSpecificityList:Array; 22 23 #define SPL_STEP 10 24 21 25 function HaarCascade() 22 26 { 23 27 28 } 29 30 public function get specificityListStep():uint 31 { 32 return SPL_STEP; 33 } 34 35 public function get specificityList():Array 36 { 37 return mSpecificityList; 38 } 39 40 public function initSpecificityList(n:uint):void 41 { 42 mSpecificityList = new Array(n); 43 for (var i:uint = 0;i < n;i++) 44 mSpecificityList[i] = 1; 24 45 } 25 46 … … 73 94 private static const NPASS:uint = 2; 74 95 private static const INVALID_MASK:uint = 0xffffff; 75 public function detect(bmp:BitmapData, scale_factor:Number, min_width:int = 0, min_height:int = 0, limit:int = -1):Object96 public function detect(bmp:BitmapData, entire_skip:Boolean, scale_factor:Number, min_width:int = 0, min_height:int = 0, limit:int = -1):Object 76 97 { 77 98 if (!mYieldContext.enabled) { … … 103 124 var mask_index:uint = mYieldContext.mask_index; 104 125 var hueval:Number; 126 127 var skip:Boolean = false; 105 128 106 129 if (scale_factor == 0) … … 121 144 continue; 122 145 146 if (mSpecificityList) 147 { 148 if ( mSpecificityList[int(winWidth/SPL_STEP)] == 0 ) 149 { 150 if (entire_skip) continue; 151 skip = true; 152 } 153 else 154 skip = false; 155 } 156 123 157 var stop_height:uint = (srcHeight - winHeight) / ystep; 124 158 var result:int; … … 130 164 for(var _iy:uint = mYieldContext._iy; _iy < stop_height; _iy++) 131 165 { 166 if (skip && (_iy & 1) != 0) 167 { 168 mYieldContext._iy = 0; 169 continue; 170 } 171 172 132 173 if (--limit == 0) 133 174 YIELD(_iy, pass, resrects1, factor, mask_index, sums) … … 167 208 } 168 209 else if( result < 0 ) { 169 _xstep = 1; 210 if (!skip) 211 _xstep = 1; 170 212 } 171 213 -
lang/actionscript/ashaardetect/trunk/cv/RectPool.as
r17214 r17274 42 42 } 43 43 44 public function mapRect(f:Function):void 45 { 46 for each(var rd:RectData in mPool) 47 { 48 if (rd.ttl >= 1) 49 f(rd.showPos, rd.alpha); 50 } 51 } 52 44 53 private static function filt_func(item:*, index:int, array:Array):Boolean 45 54 { … … 72 81 rc2[3] += rc2[1]; 73 82 for (k = 0;k < 4;k++) 74 rc2[k] += (rc1[k] - rc2[k]) * 0. 4;83 rc2[k] += (rc1[k] - rc2[k]) * 0.7; 75 84 rc1[2] -= rc1[0]; 76 85 rc1[3] -= rc1[1]; -
lang/actionscript/ashaardetect/trunk/cv/VideoDetector.as
r17214 r17274 6 6 import flash.events.*; 7 7 import flash.geom.*; 8 public class VideoDetector extends Sprite 8 public class VideoDetector extends Sprite implements IStreamingControl 9 9 { 10 10 private static const OFFSCR_WIDTH:uint = 320; … … 21 21 private var mClearTmpBuf:Boolean; 22 22 private var mGenHue:Boolean; 23 private var mTickHandler:Function = null; 23 24 24 25 private var mRectPool:RectPool = new RectPool(); 26 private var mSpList:Array; 27 private var mSpListChanged:Boolean; 28 29 private var mPlaying:Boolean = true; 30 private var mPauseBitmapData:BitmapData; 31 private var mPauseBitmap:Bitmap = new Bitmap(); 32 private var mLastRect:Array = null; 33 34 private var mOffscreenRect:Rectangle = new Rectangle(); 35 private var mOriginPt:Point = new Point(0, 0); 36 private var mSkipEntire:Boolean = false; 25 37 26 38 function VideoDetector(v:Video, dat:ByteArray) 27 39 { 40 mouseChildren = false; 28 41 mVideo = v; 29 42 mDetector = HaarCascade.fromBin(dat); 30 mDetector.maxWinWidth = 130; 43 mDetector.maxWinWidth = 190; 44 mDetector.initSpecificityList(24); 45 mouseEnabled = false; 46 addChild(v); 47 addChild(mPauseBitmap); 48 } 49 50 public function playStream():void { 51 mPauseBitmap.bitmapData = null; 52 mPlaying = true; 53 } 54 55 public function pauseStream():void { 56 mPauseBitmap.bitmapData = mOffscreen; 57 mSkipEntire = false; 58 mPlaying = false; 59 } 60 61 public function get playing():Boolean { 62 return mPlaying; 63 } 64 65 public function get lastImage():BitmapData { 66 return mPauseBitmapData; 67 } 68 69 public function get lastRect():Array { 70 return mLastRect; 71 } 72 73 public function set onTick(f:Function):void 74 { 75 mTickHandler = f; 31 76 } 32 77 … … 51 96 mHueData = new BitmapData(OFFSCR_WIDTH, OFFSCR_HEIGHT, false); 52 97 mOffscreen = new BitmapData(OFFSCR_WIDTH, OFFSCR_HEIGHT, false); 98 mPauseBitmapData = new BitmapData(OFFSCR_WIDTH, OFFSCR_HEIGHT, false); 53 99 mWRatio = Number(OFFSCR_WIDTH ) / Number(mVideo.width); 54 100 mHRatio = Number(OFFSCR_HEIGHT) / Number(mVideo.height); 101 mOffscreenRect.x = mOffscreenRect.y = 0; 102 mOffscreenRect.width = OFFSCR_WIDTH; 103 mOffscreenRect.height = OFFSCR_HEIGHT; 55 104 mCopyMat = new Matrix(); 56 105 mCopyMat.scale(mWRatio, mHRatio); 57 106 } 58 107 108 var res:Object; 59 109 var detector_limit:uint = 200; 60 if (mClearTmpBuf) 110 111 112 if (mClearTmpBuf && mPlaying) 61 113 { 114 mSkipEntire = !mSkipEntire; 62 115 detector_limit = 10; 116 mPauseBitmapData.copyPixels(mOffscreen, mOffscreenRect, mOriginPt); 63 117 mOffscreen.draw(mVideo, mCopyMat); 64 118 U.makeGrayscale(mTmpData, mOffscreen) … … 68 122 } 69 123 else if (mGenHue) { 70 detector_limit = 200;124 detector_limit = 130; 71 125 U.makeHueImage(mHueData, mOffscreen); 72 126 mDetector.generateHueSum(mHueData); … … 74 128 } 75 129 76 var res:Object = mDetector.detect(mTmpData, 1.2, 44, 44, detector_limit); 130 if (!mPlaying) 131 detector_limit = 10; 132 133 res = mDetector.detect(mTmpData, mSkipEntire, 1.2, 44, 44, detector_limit); 134 77 135 var rc:Array; 78 136 if (res !== HaarCascade.YIELDED) 79 137 { 80 STDOUT.cls(); 138 mLastRect = null; 139 // STDOUT.cls(); 81 140 if (res) { 82 STDOUT.puts(res.length + " windows passed");83 141 // STDOUT.puts(res.length + " windows passed"); 142 /* 84 143 g.lineStyle(3, 0, 0.1); 85 144 for each(rc in res) … … 89 148 for each(rc in res) 90 149 g.drawRect(rc[0], rc[1], rc[2], rc[3]); 91 150 */ 92 151 var clss:Array = U.bindNeighborRects(res as Array); 93 152 if (clss) { 94 153 res = U.uniteRects(res as Array, clss, 2); 95 mRectPool.update(res as Array); 154 if (res) 155 { 156 mLastRect = res[0]; 157 mRectPool.update(res as Array); 158 } 96 159 } 97 160 } 98 161 else { 99 162 mRectPool.update([]); 100 graphics.clear();101 STDOUT.puts("None");163 // graphics.clear(); 164 // STDOUT.puts("None"); 102 165 } 103 166 … … 106 169 107 170 mRectPool.tick(); 108 mRectPool.draw(g, 0xff0044); 171 // mRectPool.draw(g, 0xff0044); 172 if (null != mTickHandler) 173 mTickHandler(mRectPool); 174 175 mSpList = mDetector.specificityList; 176 mSpListChanged = false; 177 clearSpList(0); 178 mRectPool.mapRect(updateSpList); 179 180 if (mSpListChanged) 181 expandSpList(); 182 else 183 clearSpList(1); 184 185 // STDOUT.cls(); 186 // STDOUT.puts(mSpList.join(" ")); 187 } 188 189 private function clearSpList(k:int):void 190 { 191 var len:int = mSpList.length; 192 for (var i:int = 0;i < len;i++) 193 mSpList[i] = k; 194 } 195 196 private function expandSpList():void 197 { 198 var len:int = mSpList.length - 1; 199 for (var i:int = 1;i < len;i++) 200 { 201 if (mSpList[i] == 0) 202 { 203 if (mSpList[i-1] == 2 || mSpList[i+1] == 2) 204 mSpList[i] = 1; 205 } 206 } 207 } 208 209 private function updateSpList(rc:Array, a:Number):void 210 { 211 var i:uint = uint(rc[2] / mDetector.specificityListStep); 212 mSpList[i] = 2; 213 mSpListChanged = true; 109 214 } 110 215 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)