我的离散傅里叶变换(DFT)算法以某种方式抛出以下异常:
OpenCV错误:断言失败(!fixedType()||((Mat *)obj) - > type()== mtype)在create,file / Users / name_x / Desktop / working / opencv / modules / core /src/matrix.cpp,第2087行 2014-07-19 19:36:17.550 OpenCV_TemplateMatching [1051:60b]程序结束 libc ++ abi.dylib:以cv类型的未捕获异常终止::异常:/Users/name_x/Desktop/working/opencv/modules/core/src/matrix.cpp:2087:错误:(-215)!fixedType( )|| ((Mat *)obj) - > type()== mtype in function create
可能是什么原因?
异常似乎发生在飞机初始化:
cv::Mat planes[] = { cv::Mat_<float>(padded), cv::Mat::zeros(padded.size(), CV_32F) };
以下是整个代码:
cv::Mat cv_img = [in_image CVMat];
cv::Mat cv_img_gray = [in_image CVGrayscaleMat];
// Do some OpenCV stuff with the image
cv::Mat padded; //expand input image to optimal size
int m = cv::getOptimalDFTSize( cv_img.rows );
int n = cv::getOptimalDFTSize( cv_img.cols );
// on the border add zero values
cv::copyMakeBorder(cv_img, padded, 0, m - cv_img.rows, 0, n - cv_img.cols, cv::BORDER_CONSTANT, cv::Scalar::all(0));
// !!!! Here the exception occurs - Why ?????
cv::Mat planes[] = { cv::Mat_<float>(padded), cv::Mat::zeros(padded.size(), CV_32F) };
cv::Mat complexI;
cv::merge(planes, 2, complexI); // Add to the expanded another plane with zeros
cv::dft(complexI, complexI); // this way the result may fit in the source matrix
// compute the magnitude and switch to logarithmic scale
// => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2))
cv::split(complexI, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
cv::magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
cv::Mat magI = planes[0];
magI += cv::Scalar::all(1); // switch to logarithmic scale
cv::log(magI, magI);
// crop the spectrum, if it has an odd number of rows or columns
magI = magI(cv::Rect(0, 0, magI.cols & -2, magI.rows & -2));
// rearrange the quadrants of Fourier image so that the origin is at the image center
int cx = magI.cols/2;
int cy = magI.rows/2;
cv::Mat q0(magI, cv::Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
cv::Mat q1(magI, cv::Rect(cx, 0, cx, cy)); // Top-Right
cv::Mat q2(magI, cv::Rect(0, cy, cx, cy)); // Bottom-Left
cv::Mat q3(magI, cv::Rect(cx, cy, cx, cy)); // Bottom-Right
cv::Mat tmp; // swap quadrants (Top-Left with Bottom-Right)
q0.copyTo(tmp);
q3.copyTo(q0);
tmp.copyTo(q3);
q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
q2.copyTo(q1);
tmp.copyTo(q2);
normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
// viewable image form (float between values 0 and 1).