Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::_OutputArray::create while Performing DFT
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.
- Am I using DFT_COMPLEX_OUTPUT flag in a wrong way? Is there another way to do this
- Is there any way to get a complex valued spectrum in an alternate way?
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.
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
insteadOh yes, you're right. I used std::complex<float> and it worked. Thank you very much for pointing out.