Hi,
I'm new to OpenCV, and I would like to compare the results of a python program with my calculations in OpenCV. My matrix contains complex numbers since its the result of a cvDFT. Python handles complex numbers well and displays it with scientific notation. My C++ program is not effective when trying to use std::cout.
I tried to store my numbers array in a std::complex[] instead of a double[] but it is not compiling.
Here is my code, and its result :
CvMat *dft_A;
dft_A = cvCreateMat(5, 5, CV_64FC2); // complex matrix
double a[] = {
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
3, 3, 3, 3, 3,
4, 4, 4, 4, 4
};
dft_A->data.db = a;
std::cout << "before : " << a[0] << std::endl;
cvDFT( dft_A, dft_A, CV_DXT_FORWARD); // DFT !
std::cout << "after : " << a[0] << std::endl;
>> before : 0
Here is the same in python, with the output :
>>> a = np.mgrid[:5, :5][0]
>>> a
array([[0, 0, 0, 0, 0],
[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4]])
>>> np.fft.fft2(a)
array([[ 50.0 +0.j , 0.0 +0.j , 0.0 +0.j ,
0.0 +0.j , 0.0 +0.j ],
[-12.5+17.20477401j, 0.0 +0.j , 0.0 +0.j ,
0.0 +0.j , 0.0 +0.j ],
[-12.5 +4.0614962j , 0.0 +0.j , 0.0 +0.j ,
0.0 +0.j , 0.0 +0.j ],
[-12.5 -4.0614962j , 0.0 +0.j , 0.0 +0.j ,
0.0 +0.j , 0.0 +0.j ],
[-12.5-17.20477401j, 0.0 +0.j , 0.0 +0.j ,
0.0 +0.j , 0.0 +0.j ]])
>>>
The problem is obviously coming from the second cout which is inefficient with the type of date (CV_64FC2 for complex number).
My question is : how can I dump the result so I can check that my python code is doing the same as my cpp/opencv code ?
Thanks !