内容发布更新时间 : 2025/1/23 2:18:10星期一 下面是文章的全部内容请认真阅读。
金字塔LK光流算法
constintMAX_CORNERS = 500;
voidCImageExampleDlg::OnBnClickedButton8() { // TODO: Add your control notification handler code here IplImage* imgA =
cvLoadImage(\,CV_LOAD_IMAGE_GRAYSCALE); IplImage* imgB =
cvLoadImage(\,CV_LOAD_IMAGE_GRAYSCALE); CvSizeimg_sz = cvGetSize( imgA ); intwin_size = 10; IplImage* imgC =
cvLoadImage(\,CV_LOAD_IMAGE_UNCHANGED); // The first thing we need to do is get the features // we want to track. // IplImage* eig_image = cvCreateImage( img_sz, IPL_DEPTH_32F, 1 ); IplImage* tmp_image = cvCreateImage( img_sz, IPL_DEPTH_32F, 1 ); intcorner_count = MAX_CORNERS; CvPoint2D32f* cornersA = newCvPoint2D32f[ MAX_CORNERS ]; cvGoodFeaturesToTrack( imgA, eig_image, tmp_image, cornersA, &corner_count, 0.01, 5.0, 0, 3, 0, 0.04 ); cvFindCornerSubPix( imgA, cornersA, corner_count, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03) ); // Call the Lucas Kanade algorithm // charfeatures_found[ MAX_CORNERS ]; floatfeature_errors[ MAX_CORNERS ]; CvSizepyr_sz = cvSize( imgA->width+8, imgB->height/3 ); IplImage* pyrA = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1 ); IplImage* pyrB = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1 ); CvPoint2D32f* cornersB = newCvPoint2D32f[ MAX_CORNERS ]; cvCalcOpticalFlowPyrLK( imgA,
}
imgB, pyrA, pyrB, cornersA, cornersB, corner_count, cvSize( win_size,win_size ), 5, features_found, feature_errors, cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3 ), 0 );
// Now make some image of what we are looking at: //
for( inti=0; i
cvNamedWindow(\,0); cvNamedWindow(\,0);
cvNamedWindow(\,0); cvShowImage(\,imgA); cvShowImage(\,imgB);
cvShowImage(\,imgC);