I’ve been experimenting with image mosaicking for some time now. I finally achieved some interesting results.
In this experiment I recorded a video of a landscape inside my faculty.
The algorithm to create these panoramic images is something like this:
1: draw first frame image 2: 3: For each image 4: find important points on previous image 5: find the same points on current image 6: remove invalid points ( too close from the border, too different from average) 7: find homography rotation matrix( RANSAC method ) 8: Warp image with rotation matrix 9: Blend current image rotated above the other images 10: endfor
The above example was created with OpenFrameworks and OpenCV using the following functions:
1: /* detect good points to track, such as corners*/
2: cvGoodFeaturesToTrack( firstImageGray, eig, temp, points[0], &pointsCount, 3: TRACK_QUALITY, MIN_DISTANCE, 0, 3, 0, 0.04 ); 4: 5: /* detect the same points on second image */
6: cvCalcOpticalFlowPyrLK( firstImageGray, secondImageGray, prev_pyramid, pyramid, 7: points[0], points[1], pointsCount, cvSize(WIN_SIZE,WIN_SIZE ),3, status, 0, 8: cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,2000,0.001), flags ); 9: 10: /*Find Homography*/
11: CvMat _imagePoints1 = cvMat(1, pointsCount, CV_32FC2, &points[0][0] ); 12: 13: CvMat _imagePoints2 = cvMat(1, pointsCount, CV_32FC2, &points[1][0] ); 14: 15: CvMat* warp_mat = cvCreateMat(3,3,CV_32FC1); 16: 17: cvFindHomography( &_imagePoints2, &_imagePoints1,warp_mat, CV_RANSAC, 1 ); 18: 19: /*Warp Image*/
20: cvWarpPerspective( secondImage, secondImageRot, warp_mat ); 21: 22: /*blend image: copy only the parts that are not black*/
23: cvCvtColor(secondImageRot, secondImageRotGray, CV_BGR2GRAY ); 24: cvErode(secondImageRotGray,secondImageRotGray); 25: cvCopy( secondImageRot, mainImage, secondImageRotGray ); 26: These are separated bits of code. If you want the full code please send me an email.
rui.nobrega [at] di.fct.unl.pt