2013-12-17 55 views
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 

回答

0

没关系,这实际上是由事实的UIImage在首位3个信道引起的。当转换成Mat和CV_32F类型时,生成的Mat实际上是CV_32FC3类型(3个通道);因此,参数类型不匹配时发生错误。

我的解决办法是分割原始垫到通道的阵列,然后通过一个通道仅向phaseCorrelate功能:

vector<Mat> refChannels; 
split(refMatImage, refChannels); 
phaseCorrelate(refChannels[0],...); 
相关问题