Advertisement
lamiastella

calcPyrLKTrack gcov -b

Jun 22nd, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.27 KB | None | 0 0
  1.         -:    0:Source:calcPyrLKTrack.c
  2.         -:    0:Graph:calcPyrLKTrack.gcno
  3.         -:    0:Data:calcPyrLKTrack.gcda
  4.         -:    0:Runs:1
  5.         -:    0:Programs:1
  6.         -:    1:/********************************
  7.         -:    2:Author: Sravanthi Kota Venkata
  8.         -:    3:********************************/
  9.         -:    4:
  10.         -:    5:#include "tracking.h"
  11.         -:    6:
  12.         -:    7:/** calcPyrLKTrack tries to find the displacement (translation in x and y) of features computed in the previous frame.
  13.         -:    8:    To compute the displacement, we interpolate the existing feature position around the pixel neighborhood.
  14.         -:    9:    For better results, we perform interpolatations across all pyramid levels.
  15.         -:   10:
  16.         -:   11:    Input:  Previous frame blurred images, vertical and horizontal
  17.         -:   12:            Current frame edge images, vertical and horizontal
  18.         -:   13:            Current frame blurred images, for level 0 and 1
  19.         -:   14:            Number of features from previous frame
  20.         -:   15:            Window size
  21.         -:   16:            Accuracy
  22.         -:   17:            Number of iterations to compute motion vector
  23.         -:   18:            Features from the previous frame
  24.         -:   19:            currentFrameFeatures, Populate the current frame features' displacements
  25.         -:   20:    Output: Number of valid features
  26.         -:   21:
  27.         -:   22:**/
  28.         -:   23:
  29. function calcPyrLKTrack called 4 returned 100% blocks executed 91%
  30.         4:   24:I2D* calcPyrLKTrack(F2D* previousImageBlur_level1, F2D* previousImageBlur_level2, F2D* vertEdge_level1, F2D* vertEdge_level2, F2D* horzEdge_level1, F2D* horzEdge_level2, F2D* currentImageBlur_level1, F2D* currentImageBlur_level2, F2D* previousFrameFeatures, int nFeatures, int winSize, float accuracy, int max_iter, F2D* currentFrameFeatures)
  31.         -:   25:{
  32.         -:   26:    int idx, level, pLevel, i, j, k, winSizeSq;
  33.         -:   27:    I2D *valid;
  34.         -:   28:    F2D *rate, *iPatch, *jPatch, *iDxPatch;
  35.         -:   29:    F2D *iDyPatch;
  36.         -:   30:    float tr, x, y, dX, dY, c_xx, c_yy, c_xy;
  37.         -:   31:    int imgSize_1, imgSize_2;
  38.         -:   32:    float mX, mY, dIt, eX, eY, c_det;
  39.         -:   33:    I2D *imgDims;
  40.         -:   34:
  41.         4:   35:    imgDims = iMallocHandle(2, 2);
  42. call    0 returned 100%
  43.         4:   36:    subsref(imgDims,0,0) = previousImageBlur_level1->height;
  44.         4:   37:    subsref(imgDims,0,1) = previousImageBlur_level1->width;
  45.         4:   38:    subsref(imgDims,1,0) = previousImageBlur_level2->height;
  46.         4:   39:    subsref(imgDims,1,1) = previousImageBlur_level2->width;
  47.         -:   40:
  48.         -:   41:    pLevel = 2;
  49.         4:   42:    rate = fMallocHandle(1, 6);
  50. call    0 returned 100%
  51.         -:   43:
  52.         4:   44:    asubsref(rate,0) = 1;
  53.         4:   45:    asubsref(rate,1) = 0.5;
  54.         4:   46:    asubsref(rate,2) = 0.25;
  55.         4:   47:    asubsref(rate,3) = 0.125;
  56.         4:   48:    asubsref(rate,4) = 0.0625;
  57.         4:   49:    asubsref(rate,5) = 0.03125;
  58.         -:   50:    
  59.         4:   51:    winSizeSq = 4*winSize*winSize;
  60.         4:   52:    valid = iSetArray(1,nFeatures, 1);
  61. call    0 returned 100%
  62.         -:   53:
  63.         -:   54:    /** For each feature passed from previous frame, compute the dx and dy, the displacements **/
  64.        24:   55:    for(i=0; i<nFeatures; i++)
  65. branch  0 taken 83%
  66. branch  1 taken 17% (fallthrough)
  67.         -:   56:    {
  68.         -:   57:        dX = 0;
  69.         -:   58:        dY = 0;
  70.         -:   59:
  71.         -:   60:        /** Compute the x and y co-ordinate values at "pLevel" **/
  72.        20:   61:        x = subsref(previousFrameFeatures,0,i) * asubsref(rate,pLevel);
  73.        20:   62:        y = subsref(previousFrameFeatures,1,i) * asubsref(rate,pLevel);
  74.         -:   63:        c_det = 0;
  75.         -:   64:
  76.         -:   65:        /** For each pyramid level, try to find correspondence.
  77.         -:   66:            We look for the correspondence in a given window size
  78.         -:   67:            , (winSize x winSize) neighborhood **/
  79.        60:   68:        for(level = pLevel-1; level>=0; level--)
  80. branch  0 taken 67%
  81. branch  1 taken 33% (fallthrough)
  82.         -:   69:        {
  83.        40:   70:            x = x+x;
  84.        40:   71:            y = y+y;
  85.        40:   72:            dX = dX + dX;
  86.        40:   73:            dY = dY + dY;
  87.        40:   74:            imgSize_1 = subsref(imgDims,level,0);
  88.        40:   75:            imgSize_2 = subsref(imgDims,level,1);
  89.         -:   76:
  90.         -:   77:            c_xx = 0;
  91.         -:   78:            c_xy = 0;
  92.         -:   79:            c_yy = 0;
  93.         -:   80:        
  94.        40:   81:            if((x-winSize)<0 || (y-winSize)<0 || (y+winSize+1)>=imgSize_1 || (x+winSize+1)>=imgSize_2)
  95. branch  0 taken 100% (fallthrough)
  96. branch  1 taken 0%
  97. branch  2 taken 100% (fallthrough)
  98. branch  3 taken 0%
  99. branch  4 taken 100% (fallthrough)
  100. branch  5 taken 0%
  101. branch  6 taken 0% (fallthrough)
  102. branch  7 taken 100%
  103.         -:   82:            {
  104.     #####:   83:                asubsref(valid,i) = 0;
  105.     #####:   84:                break;
  106.         -:   85:            }
  107.         -:   86:
  108.         -:   87:            /** Perform interpolation. Use co-ord from previous
  109.         -:   88:                frame and use the images from current frame **/
  110.         -:   89:
  111.        40:   90:            if(level ==0)
  112. branch  0 taken 50% (fallthrough)
  113. branch  1 taken 50%
  114.         -:   91:            {
  115.        20:   92:                iPatch = getInterpolatePatch(previousImageBlur_level1, imgSize_2, x, y, winSize);
  116. call    0 returned 100%
  117.        20:   93:                iDxPatch = getInterpolatePatch(vertEdge_level1, imgSize_2, x, y, winSize);
  118. call    0 returned 100%
  119.        20:   94:                iDyPatch = getInterpolatePatch(horzEdge_level1, imgSize_2, x, y, winSize);
  120. call    0 returned 100%
  121.         -:   95:            }
  122.        40:   96:            if(level ==1)
  123. branch  0 taken 50% (fallthrough)
  124. branch  1 taken 50%
  125.         -:   97:            {
  126.        20:   98:                iPatch = getInterpolatePatch(previousImageBlur_level2, imgSize_2, x, y, winSize);
  127. call    0 returned 100%
  128.        20:   99:                iDxPatch = getInterpolatePatch(vertEdge_level2, imgSize_2, x, y, winSize);
  129. call    0 returned 100%
  130.        20:  100:                iDyPatch = getInterpolatePatch(horzEdge_level2, imgSize_2, x, y, winSize);
  131. call    0 returned 100%
  132.         -:  101:            }
  133.         -:  102:
  134.         -:  103:            /** Compute feature strength in similar way as calcGoodFeature **/
  135.    368680:  104:            for(idx=0; idx<winSizeSq; idx++)
  136. branch  0 taken 99%
  137. branch  1 taken 1% (fallthrough)
  138.         -:  105:            {
  139.    368640:  106:                c_xx += asubsref(iDxPatch,idx) * asubsref(iDxPatch,idx);
  140.    368640:  107:                c_xy += asubsref(iDxPatch,idx) * asubsref(iDyPatch,idx);
  141.    368640:  108:                c_yy += asubsref(iDyPatch,idx) * asubsref(iDyPatch,idx);
  142.         -:  109:            }
  143.         -:  110:            
  144.        40:  111:            c_det = (c_xx * c_yy -c_xy * c_xy);
  145.        40:  112:            tr = c_xx + c_yy;
  146.         -:  113:
  147.        40:  114:            if((c_det/(tr+0.00001)) < accuracy)
  148. branch  0 taken 0% (fallthrough)
  149. branch  1 taken 100%
  150.         -:  115:            {
  151.     #####:  116:                asubsref(valid,i) = 0;
  152.     #####:  117:                fFreeHandle(iPatch);
  153. call    0 never executed
  154.     #####:  118:                fFreeHandle(iDxPatch);
  155. call    0 never executed
  156.     #####:  119:                fFreeHandle(iDyPatch);
  157. call    0 never executed
  158.     #####:  120:                break;
  159.         -:  121:            }
  160.        40:  122:            c_det = 1/c_det;
  161.         -:  123:
  162.         -:  124:            /** We compute dX and dY using previous frame and current
  163.         -:  125:                frame images. For this, the strength is computed at each
  164.         -:  126:                pixel in the new image.  **/
  165.       472:  127:            for(k=0; k<max_iter; k++)
  166. branch  0 taken 96%
  167. branch  1 taken 4% (fallthrough)
  168.         -:  128:            {
  169.       453:  129:                if( (x+dX-winSize)<0 || (y+dY-winSize)<0 || (y+dY+winSize+1)>=imgSize_1 || (x+dX+winSize+1)>=imgSize_2)
  170. branch  0 taken 100% (fallthrough)
  171. branch  1 taken 0%
  172. branch  2 taken 99% (fallthrough)
  173. branch  3 taken 1%
  174. branch  4 taken 100% (fallthrough)
  175. branch  5 taken 0%
  176. branch  6 taken 0% (fallthrough)
  177. branch  7 taken 100%
  178.         -:  130:                {
  179.         1:  131:                    asubsref(valid,i) = 0;
  180.         1:  132:                    break;
  181.         -:  133:                }
  182.         -:  134:                
  183.       452:  135:                if(level == 0)
  184. branch  0 taken 49% (fallthrough)
  185. branch  1 taken 51%
  186.       223:  136:                    jPatch = getInterpolatePatch(currentImageBlur_level1, imgSize_2, x+dX, y+dY, winSize);
  187. call    0 returned 100%
  188.       452:  137:                if(level == 1)
  189. branch  0 taken 51% (fallthrough)
  190. branch  1 taken 49%
  191.       229:  138:                    jPatch = getInterpolatePatch(currentImageBlur_level2, imgSize_2, x+dX, y+dY, winSize);
  192. call    0 returned 100%
  193.         -:  139:                
  194.         -:  140:                eX = 0;
  195.         -:  141:                eY = 0;
  196.   4166084:  142:                for(idx=0; idx<winSizeSq; idx++)
  197. branch  0 taken 99%
  198. branch  1 taken 1% (fallthrough)
  199.         -:  143:                {
  200.   4165632:  144:                    dIt = asubsref(iPatch,idx) - asubsref(jPatch,idx);
  201.   4165632:  145:                    eX += dIt * asubsref(iDxPatch,idx);
  202.   4165632:  146:                    eY += dIt * asubsref(iDyPatch,idx);
  203.         -:  147:                }
  204.         -:  148:                
  205.       452:  149:                mX = c_det * (eX * c_yy - eY * c_xy);
  206.       452:  150:                mY = c_det * (-eX * c_xy + eY * c_xx);
  207.       452:  151:                dX = dX + mX;
  208.       452:  152:                dY = dY + mY;
  209.         -:  153:            
  210.       452:  154:                if( (mX*mX+mY*mY) < accuracy)
  211. branch  0 taken 4% (fallthrough)
  212. branch  1 taken 96%
  213.         -:  155:                {
  214.        20:  156:                    fFreeHandle(jPatch);
  215. call    0 returned 100%
  216.        20:  157:                    break;
  217.         -:  158:                }
  218.         -:  159:                
  219.       432:  160:                fFreeHandle(jPatch);
  220. call    0 returned 100%
  221.         -:  161:            }
  222.         -:  162:
  223.        40:  163:            fFreeHandle(iPatch);
  224. call    0 returned 100%
  225.        40:  164:            fFreeHandle(iDxPatch);
  226. call    0 returned 100%
  227.        40:  165:            fFreeHandle(iDyPatch);
  228. call    0 returned 100%
  229.         -:  166:        }
  230.         -:  167:
  231.        20:  168:        subsref(currentFrameFeatures,0,i) = subsref(previousFrameFeatures,0,i) + dX;
  232.        20:  169:        subsref(currentFrameFeatures,1,i) = subsref(previousFrameFeatures,1,i) + dY;
  233.         -:  170:        
  234.         -:  171:    }
  235.         -:  172:
  236.         4:  173:    fFreeHandle(rate);
  237. call    0 returned 100%
  238.         4:  174:    iFreeHandle(imgDims);
  239. call    0 returned 100%
  240.         4:  175:    return valid;
  241.         -:  176:}
  242.         -:  177:
  243.         -:  178:
  244.         -:  179:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement