-1

the problem is to fourie transform ( cv::dft ) a signal with fourie descriptors. So the mat should be complex numbers :(

But my problem is how can make a mat with complex numbers ? Please help me to find an example or any other that show me how to store a complex number(RE + IM) to a mat ?

Is there a way to use merge ?

My code

Mat koopa(contours5[0], true);
Mat re;
Mat im;
re.convertTo(re,CV_32SC1);
im.convertTo(re, CV_32SC1);
vector channel(2);
// split coordinates in two mat
split(koopa, channel);
re = channel[0];
im = channel[1];
Mat planes[] = { re, im };
Mat complexImg;
merge(planes, 2, complexImg);
dft(complexImg, complexImg);
split(complexImg, planes);

why doesn't work ? Link error picture

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Alf85
  • 1
  • 3
  • Please don't post a picture (or worse, a link to a picture) of your error(s). Copy-paste the *text* of the error into the question. And please, copy the *complete* error/build log, and also please mark out on which lines you are getting the errors. – Some programmer dude Dec 01 '14 at 13:57
  • I think its quite clear. Its a datatype mismatch problem. You are not imputing the data type dft expects. If you check your error you can see that. Read what an assertion is in programing also. – Ander Biguri Dec 01 '14 at 13:59
  • Matlab gives me with the identical content of the matrix a totally different result why? Opencv [4718, 4534; -19.523417, 35.777447; -299.86957, -1409.5095] -10,5683297180044 + 0,00000000000000i -2219,69900075834 + 721,815545935725i 13,4949824676201 + 34,0769293182730i -2219,69900075834 - 721,815545935725i – Alf85 Dec 01 '14 at 15:55

1 Answers1

0

Because it wants CV_32FC or CV_64FC datatype, but you feed CV_32SC.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42
  • okay I have fixed it , and the code runs ! But Matlab gives me with the identical content of the matrix a totally different result why? – Alf85 Dec 01 '14 at 15:47
  • Seems you need normalize result. See DFT_SCALE flag. – Andrey Smorodov Dec 01 '14 at 16:10
  • is there nothing to do except to change the dft funktion ? from dft(complexImg, complexImg); in dft(complexImg, complexImg, DFT_SCALE); ? when I do this the results are very small and there is no peak so high how in matlab ?? – Alf85 Dec 02 '14 at 12:25
  • is it really like in the above example , the pay in the matrix complexImg now imaginary numbers in the form zi = 5 + 6i are generated by this merge ? – Alf85 Dec 02 '14 at 12:30
  • Can't really undestand the problem. But take a look also here: http://stackoverflow.com/questions/20045768/fft-and-ifft-difference-between-results-in-matlab-and-opencv/20046438#20046438 – Andrey Smorodov Dec 02 '14 at 13:21
  • the problem is matlab results are high numbers ( 0 to 700 or 1500) and the first result after the fft in matlab have only a real part ... in openCV after the dft the results are very low numbers ( 0 to 30 ) and the first result after the dft have real und complex part ...why is there such a difference ? – Alf85 Dec 02 '14 at 13:29
  • Try use DFT_SCALE|DFT_COMPLEX_OUTPUT flags together. – Andrey Smorodov Dec 02 '14 at 13:31
  • And it seems that MALAB's fft gives you magnitude and phase, but OpenCV gives imaginary and real parts of transform. These things are not the same. – Andrey Smorodov Dec 02 '14 at 13:39
  • there is no difference with these flags to the result of behind the other flags :( , i will check your answer with the magnitude and the phase but i think matlab gives RE and IM back after use fft ? – Alf85 Dec 02 '14 at 13:58