内容发布更新时间 : 2024/12/23 12:29:34星期一 下面是文章的全部内容请认真阅读。
VelBufY[i & 1][imageWidth - 1] = averageY - (II[address].xy * averageX +
II[address].yy * averageY + II[address].yt) * II[address].alpha;
/* update Epsilon */
if( criteria.type & CV_TERMCRIT_EPS ) {
tmp = (float)fabs(velocityX[Line2 + imageWidth - 1] - VelBufX[i & 1][imageWidth - 1]); Eps = MAX( tmp, Eps );
tmp = (float)fabs(velocityY[Line2 + imageWidth - 1] - VelBufY[i & 1][imageWidth - 1]); Eps = MAX( tmp, Eps ); }
address++;
/* store new velocity from old buffer to velocity frame */ if( i > 0 ) {
memcpy( &velocityX[Line1], VelBufX[(i - 1) & 1], imageWidth * sizeof( float ));
memcpy( &velocityY[Line1], VelBufY[(i - 1) & 1], imageWidth * sizeof( float )); }
} /*for */
/* store new velocity from old buffer to velocity frame */ memcpy( &velocityX[imageWidth * (imageHeight - 1)],
VelBufX[(imageHeight - 1) & 1], imageWidth * sizeof( float ));
memcpy( &velocityY[imageWidth * (imageHeight - 1)],
VelBufY[(imageHeight - 1) & 1], imageWidth * sizeof( float ));
if( (criteria.type & CV_TERMCRIT_ITER) && (iter == criteria.max_iter) )
Stop = 1;
if( (criteria.type & CV_TERMCRIT_EPS) && (Eps < criteria.epsilon) )
Stop = 1; }
/* Free memory */
for( k = 0; k < 2; k++ ) {
cvFree( &MemX[k] ); cvFree( &MemY[k] ); cvFree( &VelBufX[k] ); cvFree( &VelBufY[k] ); }
cvFree( &II );
return CV_OK;
} /*icvCalcOpticalFlowHS_8u32fR*/
/*F/////////////////////////////////////////////////////////////////////////////////////// // Name: cvCalcOpticalFlowHS // Purpose: Optical flow implementation // Context: // Parameters:
// srcA, srcB - source image // velx, vely - destination image // Returns: //
// Notes: //F*/
CV_IMPL void
cvCalcOpticalFlowHS( const void* srcarrA, const void* srcarrB, usePrevious,
void* velarrx, void* velarry,
double lambda, CvTermCriteria criteria ) {
CV_FUNCNAME( \ );
__BEGIN__;
CvMat stubA, *srcA = (CvMat*)srcarrA; CvMat stubB, *srcB = (CvMat*)srcarrB; CvMat stubx, *velx = (CvMat*)velarrx; CvMat stuby, *vely = (CvMat*)velarry;
CV_CALL( srcA = cvGetMat( srcA, &stubA )); CV_CALL( srcB = cvGetMat( srcB, &stubB ));
CV_CALL( velx = cvGetMat( velx, &stubx )); CV_CALL( vely = cvGetMat( vely, &stuby ));
int
if( !CV_ARE_TYPES_EQ( srcA, srcB ))
CV_ERROR( CV_StsUnmatchedFormats, \images have different formats\ );
if( !CV_ARE_TYPES_EQ( velx, vely ))
CV_ERROR( CV_StsUnmatchedFormats, \different formats\ );
if( !CV_ARE_SIZES_EQ( srcA, srcB ) || !CV_ARE_SIZES_EQ( velx, vely ) || !CV_ARE_SIZES_EQ( srcA, velx ))
CV_ERROR( CV_StsUnmatchedSizes, \ );
if( CV_MAT_TYPE( srcA->type ) != CV_8UC1 || CV_MAT_TYPE( velx->type ) != CV_32FC1 )
CV_ERROR( CV_StsUnsupportedFormat, \images must have 8uC1 type and \
\images must have 32fC1 type\ );
if( srcA->step != srcB->step || velx->step != vely->step )
CV_ERROR( CV_BadStep, \and destination images have different step\ );
IPPI_CALL( icvCalcOpticalFlowHS_8u32fR( (uchar*)srcA->data.ptr, (uchar*)srcB->data.ptr,
srcA->step, cvGetMatSize( srcA ), usePrevious,
velx->data.fl, vely->data.fl,
velx->step, (float)lambda, criteria )); __END__; }
/* End of file. */