Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::_OutputArray::create while Performing DFT

asked 2019-12-28 07:21:39 -0600

updated 2019-12-28 07:54:19 -0600

berak gravatar image

I am trying to perform DFT on two images such that I get a full size complex valued spectrum. In order to achieve that I have written following code:

cv::Mat_<std::complex<float>> DFTReal2Complex(const cv::Mat_<float>& input)
    cv::Mat_<float> result = cv::Mat::zeros(input.size(), input.type());
    cv::dft(input, result, cv::DFT_COMPLEX_OUTPUT);     //,     
        return result; 

When I execute the code, I get an exception

Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::_OutputArray::create, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 2130.

If I remove DFT_COMPLEX_OUTPUT flag, the code executes fine but am looking for a complex valued spectrum.

  1. Am I using DFT_COMPLEX_OUTPUT flag in a wrong way? Is there another way to do this
  2. Is there any way to get a complex valued spectrum in an alternate way?
edit retag flag offensive close merge delete


I don't know anything about this, but it seems to not like the type of the output Mat. I'd try to not initialize it and let the function figure out a type for it.

mvuori gravatar imagemvuori ( 2019-12-28 09:39:28 -0600 )edit

a complex output won't fit into cv::Mat_<float> result, and the type of it cannot be changed (to e.g CV_32FC2)

try to use a plain Mat instead

berak gravatar imageberak ( 2019-12-29 04:43:04 -0600 )edit

Oh yes, you're right. I used std::complex<float> and it worked. Thank you very much for pointing out.

Anupama Rajkumar gravatar imageAnupama Rajkumar ( 2019-12-29 05:49:03 -0600 )edit