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