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