iOS/OpenCV: Image Alignment/ Motion Compensation

asked 2013-12-16 22:26:35 -0500

yonasstephen gravatar image

updated 2013-12-17 01:27:17 -0500

I am trying to detect the shift between 2 images using OpenCV in iOS. The function that I used is phaseCorrelate, which is supposed to return the Point2d given the 2 cv::Mat images. I followed the sample code here by converting the UIImage to Mat, and then convert the Mat to CV_32F type. But I kept on getting this error:

OpenCV Error: Assertion failed (src1.type() == CV_32FC1 || src1.type() == CV_64FC1) in            phaseCorrelateRes, file /Users/alexandershishkov/dev/opencvIOS/opencv-2.4.7/modules/imgproc/src/phasecorr.cpp, line 498
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/alexandershishkov/dev/opencvIOS/opencv-2.4.7/modules/imgproc/src/phasecorr.cpp:498: error: (-215) src1.type() == CV_32FC1 || src1.type() == CV_64FC1 in function phaseCorrelateRes

I don't understand why I got that error, because I have converted the Mat type to CV_32F. FYI: the reason why I didn't convert to CV_64F is because it cost huge memory and the app in iOS will immediately closed due to heavy memory.

Here's the snippet of my code where error occurred (at phaseCorrelate call):

#ifdef __cplusplus
-(void)alignImages:(NSMutableArray *)camImages
{
int i;
Mat matImages, refMatImage, hann;
Point2d pcPoint;

for (i = 0; i < [camImages count]; i++) {
    if(i == 0){
        UIImageToMat([camImages objectAtIndex:i], refMatImage);
        refMatImage.convertTo(refMatImage, CV_32F);
        createHanningWindow(hann, refMatImage.size(), CV_32F);
    }
    else{
        UIImageToMat([camImages objectAtIndex:i], matImages);
        matImages.convertTo(matImages, CV_32F);

        pcPoint = phaseCorrelate(refMatImage, matImages, hann);
        NSLog(@"phase correlation points: (%f,%f)",pcPoint.x, pcPoint.y);
    }
}
NSLog(@"Done Converting!");
}
#endif
edit retag flag offensive close merge delete