【发布时间】:2014-01-04 17:27:57
【问题描述】:
我正在尝试在 iOS 中使用 OpenCV 检测 2 个图像之间的转换。我使用的函数是 phaseCorrelate,它应该返回给定 2 个cv::Mat 图像的 Point2d。我按照示例代码here 将UIImage 转换为Mat,然后将Mat 转换为CV_32F 类型。但我不断收到此错误:
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
我不明白为什么会出现该错误,因为我已将 Mat 类型转换为 CV_32F。仅供参考:我没有转换为 CV_64F 的原因是因为它占用了巨大的内存,并且 iOS 中的应用程序会由于内存过大而立即关闭。
这是发生错误的代码的 sn-p(在 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
【问题讨论】:
标签: c++ ios image opencv camera