Show
Ignore:
Timestamp:
08/13/08 00:51:51 (5 months ago)
Author:
gyuque
Message:

updated and added sample

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/ashaardetect/trunk/cv/HaarCascade.as

    r17274 r17558  
    1919                private var mSpecificityList:Array; 
    2020 
     21                private var mSourceWindow:IntRect = null; 
     22 
    2123                                function HaarCascade() 
    2224                { 
     
    3234                { 
    3335                        return mSpecificityList; 
     36                } 
     37 
     38                public function setSourceWindow(x:int, y:int, w:int, h:int):void 
     39                { 
     40                        if (!mSourceWindow) 
     41                                mSourceWindow = new IntRect(); 
     42 
     43                        mSourceWindow.x = x; 
     44                        mSourceWindow.y = y; 
     45                        mSourceWindow.w = w; 
     46                        mSourceWindow.h = h; 
    3447                } 
    3548 
     
    93106                                mYieldContext.res  = null; 
    94107                                mYieldContext.factor = 1; 
    95                                 mYieldContext.sumimage = new SumImage(bmp); 
     108                                if (mSourceWindow) 
     109                                        mYieldContext.sumimage = new SumImage(bmp, true, mSourceWindow.y, mSourceWindow.h); 
     110                                else 
     111                                        mYieldContext.sumimage = new SumImage(bmp, true); 
     112 
    96113                                mYieldContext.Hsumimage = null; 
    97114                                mYieldContext.mask_index = 1; 
     
    107124                        var pass:uint = 0; 
    108125 
     126                        var ox:int = 0; 
     127                        var oy:int = 0; 
     128 
    109129                        mSumRaw = sums.raw; 
    110130                        mSumW = sums.width; 
     
    112132                        var srcWidth:uint = bmp.width; 
    113133                        var srcHeight:uint = bmp.height; 
     134 
     135                        if (mSourceWindow) { 
     136                                srcWidth  = mSourceWindow.w; 
     137                                srcHeight = mSourceWindow.h; 
     138                                ox = mSourceWindow.x; 
     139                                oy = mSourceWindow.y; 
     140                        } 
     141 
    114142                        var winWidth:uint; 
    115143                        var winHeight:uint; 
     
    123151 
    124152                        for( ; factor*Number(width)  < (srcWidth  - 10) && 
    125                                  factor*Number(height) < (srcHeight - 10); 
     153                                 factor*Number(height) < (srcHeight - 20); 
    126154                                factor *= scale_factor, ++mask_index ) 
    127155                        { 
     
    169197 
    170198                                                var _ix:uint, _xstep:uint = 1; 
    171                                                 iy = int((_iy*ystep) + 0.5); 
     199                                                iy = int((_iy*ystep) + 0.5) + oy; 
    172200                                                iyp = iy * mSumW; 
    173201 
     
    175203                                                for( _ix = 0; _ix < stop_width; _ix += _xstep ) 
    176204                                                { 
    177                                                         var ix:int = _ix*ystep; // it really should be ystep 
     205                                                        var ix:int = _ix*ystep + ox; // it really should be ystep 
    178206 
    179207                                                        if(pass == 0) 
     
    384412        public var Hsumimage:SumImage; 
    385413} 
     414 
     415class IntRect 
     416{ 
     417        public var x:int, y:int, w:int, h:int; 
     418}