0
我试图检测在iOS中使用OpenCV的2个图像之间的移位。我使用的函数是phaseCorrelate,它应该返回Point2d给定的2 cv::Mat
图像。我通过将UIImage转换为Mat来跟踪示例代码here,然后将Mat
转换为CV_32F
类型。但我一直在得到这个错误:iOS和OpenCV错误:断言在PhaseCorrelateRes失败
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
我不明白为什么我得到的错误,因为我已经转换的垫类型CV_32F
。仅供参考:我没有转换为CV_64F的原因是因为它耗费巨大的内存,iOS中的应用程序由于内存过大而立即关闭。
这里是我的代码段,其中发生错误(phaseCorrelate调用):
#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