Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Essentially the answer to creating a complex matrix in OpenCV is to use 2 channels. In a 2 channel matrix, separate the real component and imaginary component of a number into a channel each.

So if we want e^(i*x) here, we know that is cos(x)+isin(x) from Euler's formula. So real part of the complex is cos(x) and imaginary is sin(x) (take care to account for all constants to ix in the cos(x) part). Can Core.merge if you use two matrices for real and imaginary.

As for something like an image matrix that has no imaginary component, we know that x+0i is still x so we can have one matrix for the image real data and another matrix filled with zeroes (Mat.zeros(...)) as the imaginary component and then merge same as above.

Thanks to @berak for the pointers that helped me work it out