Changeset 17167 for lang/actionscript

Show
Ignore:
Timestamp:
08/06/08 18:25:18 (4 months ago)
Author:
gyuque
Message:

rewrote some snippets using macro

Location:
lang/actionscript/ashaardetect/trunk/cv
Files:
2 added
2 modified

Legend:

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

    r17159 r17167  
    99                public var rects:Array     = []; 
    1010                public var scaled_rects:Array = []; 
     11 
     12                public var sr0:SRect = null; 
     13                public var sr1:SRect = null; 
     14                public var sr2:SRect = null; 
    1115 
    1216                public function readRectsFromBin(d:ByteArray):Boolean 
     
    5155                                        sum0 += sr.weight * sr.w * th; 
    5256                        } 
     57 
     58                        sr0 = scaled_rects[0]; 
     59                        sr1 = scaled_rects[1]; 
     60 
     61                        if (len > 2) 
     62                                sr2 = scaled_rects[2]; 
    5363         
    5464                        scaled_rects[0].weight = -sum0 / area0; 
  • lang/actionscript/ashaardetect/trunk/cv/HaarCascade.as

    r17159 r17167  
    155155                } 
    156156 
    157                 public static function cvRound(v:Number):int 
    158                 { 
    159                         return v+0.5; 
    160                 } 
    161  
    162                 private function initCascade(scale:Number, sums:SumImage):void 
    163                 { 
    164                         var equ_rect_width:int  = cvRound((width-2)*scale); 
    165                         var equ_rect_height:int = cvRound((height-2)*scale); 
     157                                private function initCascade(scale:Number, sums:SumImage):void 
     158                { 
     159                        var equ_rect_width:int  = int(((width-2)*scale) + 0.5); 
     160                        var equ_rect_height:int = int(((height-2)*scale) + 0.5); 
    166161                        mWeightScale = 1.0/Number(equ_rect_width*equ_rect_height); // cascade->inv_window_area 
    167                         sums.setEqWindowRect(cvRound(scale), cvRound(scale), equ_rect_width, equ_rect_height); 
     162                        sums.setEqWindowRect(int((scale) + 0.5), int((scale) + 0.5), equ_rect_width, equ_rect_height); 
    168163//                      correction_ratio = mWeightScale; 
    169164                        for each(var stg:ClassifierStage in mStages) 
    170165                                stg.calcScale(scale, mWeightScale, sums); 
    171166                } 
    172 //public static var dcount:int = 0; 
    173                 private function cvRunHaarClassifierCascade(ix:int, iyp:int, start_stage:int, sums:SumImage, limit:int = 99):int 
    174                 { 
    175 /* 
     167 
     168                                                private function cvRunHaarClassifierCascade(ix:int, iyp:int, start_stage:int, sums:SumImage, limit:int = 99):int 
     169                { 
     170                        /* 
    176171                        if( ix < 0 || iy < 0 || 
    177172                                (ix + width)  >= (sums.width-2 ) || 
     
    192187                        var cascade_count:int = mStages.length; 
    193188                        var sum:Number; 
    194                         var rects:Array; 
     189 
    195190                        if (cascade_count > limit) 
    196191                                cascade_count = limit; 
     
    214209                                        { 
    215210                                                node = stage.nodes[j]; 
    216                                                 t = node.threshold*variance_norm_factor; 
    217                                                 rects = node.scaled_rects; 
    218                                                 r0 = rects[0]; 
    219                                                 r1 = rects[1]; 
     211                                                r0 = node.sr0; 
     212                                                r1 = node.sr1; 
    220213                                                w0 = r0.weight; 
    221214 
    222                                                 base = r0.base + ixyp; 
    223                                                 base_w = base + r0.w; 
     215                                                base = r0.base + ixyp;  
     216                                                base_w = base + r0.w;  
    224217                                                hh = r0.hh; 
    225218                                                sum =  (raw_sum[base] - raw_sum[base_w] - raw_sum[base + hh] + raw_sum[base_w + hh]) * w0; 
    226219 
    227                                                 base = r1.base + ixyp; 
    228                                                 base_w = base + r1.w; 
     220                                                base = r1.base + ixyp;  
     221                                                base_w = base + r1.w;  
    229222                                                hh = r1.hh; 
    230223                                                sum += (raw_sum[base] - raw_sum[base_w] - raw_sum[base + hh] + raw_sum[base_w + hh]) * r1.weight; 
     
    233226                                                b = node.right; 
    234227 
    235                                                 if (sum < t) stage_sum += a; 
     228                                                if (sum < (node.threshold*variance_norm_factor)) stage_sum += a; 
    236229                                                else  stage_sum += b; 
    237230 
     
    243236                                        { 
    244237                                                node = stage.nodes[j]; 
    245                                                 t = node.threshold*variance_norm_factor 
    246                                                 rects = node.scaled_rects; 
    247                                                 r0 = rects[0]; 
    248                                                 r1 = rects[1]; 
    249  
    250                                                 base = r0.base + ixyp; 
    251                                                 base_w = base + r0.w; 
     238                                                r0 = node.sr0; 
     239                                                r1 = node.sr1; 
     240 
     241                                                base = r0.base + ixyp;  
     242                                                base_w = base + r0.w;  
    252243                                                hh = r0.hh; 
    253244                                                sum =  (raw_sum[base] - raw_sum[base_w] - raw_sum[base + hh] + raw_sum[base_w + hh]) * r0.weight; 
    254245 
    255                                                 base = r1.base + ixyp; 
    256                                                 base_w = base + r1.w; 
     246                                                base = r1.base + ixyp;  
     247                                                base_w = base + r1.w;  
    257248                                                hh = r1.hh; 
    258249                                                sum += (raw_sum[base] - raw_sum[base_w] - raw_sum[base + hh] + raw_sum[base_w + hh]) * r1.weight; 
    259250 
    260                                                 if (rects[2]) 
     251                                                if (node.sr2) 
    261252                                                { 
    262                                                         r2 = rects[2]; 
    263                                                         base = r2.base + ixyp; 
    264                                                         base_w = base + r2.w; 
    265                                                         hh = r2.hh; 
     253                                                        r2 = node.sr2; 
     254                                                        base = r2.base + ixyp;  
     255                                                base_w = base + r2.w;  
     256                                                hh = r2.hh; 
    266257                                                        sum += (raw_sum[base] - raw_sum[base_w] - raw_sum[base + hh] + raw_sum[base_w + hh]) * r2.weight; 
    267258                                                } 
     
    269260                                                a = node.left; 
    270261                                                b = node.right; 
    271                                                 if (sum < t) stage_sum += a; 
     262                                                if (sum < (node.threshold*variance_norm_factor)) stage_sum += a; 
    272263                                                else  stage_sum += b; 
    273264                                        }