Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
  <mx:Script>
    <![CDATA[
      import mx.core.BitmapAsset;
      import flash.display.*;

      import com.suckatmath.detector.classifier.IntegralImage;

      /**
       * Run a hard coded test case of a 10x10 bitmap that is manually constructed ( see makeImage() )
       * 
       **/ 
      public function init():void{
        var bmp:BitmapData = makeImage();
        var ii:IntegralImage = new IntegralImage( bmp );
        ii.setTiltEnabled(true);
        ii.update();

        /*
        1        2    (3)    4    5    6  7  8  9  10
        11      (12)  (13)  (14)  15    16  17  18  19  20  
        21    22    (23)  (24)    (25)  26  27  28  29  30  
        31    32    33    (34)  35    36  37  38  39  40  
        41    42    43    44    45    46  47  48  49  50  
        51    52    53    54    55    56  57  58  59  60  
        61    62    63    64    65    66  67  68  69  70  
        71    72    73    74    75    76  77  78  79  80  
        81    82    83    84    85    86  87  88  89  90  
        91    92    93    94    95    96  97  98  99  100

        if we want a rotated sum consisting of the rotated rectangle that are in the brackets above, according to leinhart papaer, this rectangle is

        x = 2, y = 0, w = 1, h = 3

        */

        var expected:Number = (3+12+13+14+23+24+25+34)/255;

        var actual:Number = ii.getTiltRectSum(new Rectangle(2,0,1,3) );

        trace("expected is: " + expected + " actual is: " + actual );
        // on my machine, I got: expected is: 0.5803921568627451 actual is: -0.02352941176470591
        // shudn't get negative value for the integral image
        
      }
      
      
      // initialize a bitmapdata with each pixel at a different value
      // image would appear as
      // 1 , 2, 3, 4, 5, 6, ...... 10
      // 11, 12, ................. 20
      // ............................
      // 91, 9, 93 ................100
      protected function makeImage():BitmapData{
        var bmp:BitmapData = new BitmapData(10,10,true,0x00000000);
        var c:int = 1;
        var img:String  ="image is: \n";
        for( var i:int =0; i<10; i++ ){
          for( var j:int=0; j<10; j++ ){
            bmp.setPixel32(j, i, makeColor(c));
            img += c + "\t";
            c++;
          }
          img += "\n";
        }
        trace(img) // make sure I'm sane....
        return bmp;
      }

      // make a greyscale color with R G and B of same value, so the image appears as
      protected function makeColor( val:uint ):uint{
        return 0xFF000000 + ( val << 16 ) + ( val << 8 ) + ( val );
      }


    ]]>
  </mx:Script>
</mx:Application>