OpenCV split function doesn't work properly
I get a 2 channels Mat from the result of dft and I want to split it into real part and the imaginary part. However, when using the split function in OpenCV, it give me some error after split.
cv::dft(fft2u_in,fft2u_in);
cv::Mat fftImg[2];
cv::split(fft2u_in,fftImg);
std::cout<<cv::sum(fft2u_in)<<std::endl;
std::cout<<cv::sum(fftImg[0])<<std::endl;
std::cout<<cv::sum(fftImg[1])<<std::endl;
The output is:
[3.39149e+08, 2.82766, 0, 0] //sum before split
[3.39149e+08, 0, 0, 0] //sum of real part after split
[11.1087, 0, 0, 0] //sum of imag after split
The real part is equal while the imaginary part has huge error. I don't know why. Is it because the Mat type change or any thing else?
Also, my dft
calculated by opencv has little error in comparison with doing the fft2
in Matlab. Is this acceptable and is there any way I can make them identical? Thanks.