Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Martin Brown <|||newspam|||@nezumi.demon.co.uk> Newsgroups: sci.image.processing Subject: Re: problem about replace opencv dft() function with fftw api Date: Thu, 12 Jan 2017 08:22:34 +0000 Organization: Aioe.org NNTP Server Lines: 62 Message-ID: References: NNTP-Posting-Host: 3GhpzT84sg/pRzW4FgEbGg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com sci.image.processing:4205 On 10/01/2017 13:39, Zhi Sun wrote: > Hi guy, > > we are encountering an issue about programing fftw api to replace > cv:dft to speed-up image/video process,but the result output of fftw > looks like not correctly. > A couple of quick points from the code. It looks like you are asking FFTW to do a 1d transform of size 640x480 rather than a 2D transform 640,480. Is this what you intend? Also when loading the complex array the image needs to go in the real components and the imaginary components identically zero. The complex array needs to be N+1 long to accommodate the alternating component. > the background is that,we have a video analysis program to handle > video frame one by one, saying that a serial of images (640x480), and > we originally call cv::dft,that is slow. the video is 20 fps. It will be a little bit harder to get going but using the Real to complex conjugate symmetric form of the FFTW library will give you transforms that can be done in place. Also comment out the tranform and check that the conversion to and from the real array is actually working correctly. That code isn't pretty. > we have use opencv(2.4.13) sample code about dft, and implement a > function (fftd) to replace the cv::dft as below. > > > is there anything we missed? ,maybe there are some misunderstanding > about the FFT output, any suggestion would be appreciated! I suspect FFTW is doing what you asked it to do - give or take any indexing errors that might have crept in elsewhere. I'd suggest testing the 1D transform on the first line of the image as a starting point now. (after you have checked that the convertion to and from reals is OK) Then alter it to use a 2D transform and you stand a chance. > cv::Mat fftd( cv::Mat img, bool backwards) { > > plan_f = fftwf_plan_dft_1d( width * height, data_in, fft, backwards ? FFTW_BACKWARD : FFTW_FORWARD, FFTW_ESTIMATE ); > t1[1] = Microseconds(); for( i = 0, k = 0 ; i < height ; i++ ) { > for( j = 0 ; j < width ; j++ ) { float *p = (float*)&img1_data[i * > step + j * sizeof(float)]; data_in[k][0] = p[0]; data_in[k][1] = > p[1]; //data_in[k][0] = ( float )img1_data[i * step + j]; > //data_in[k][1] = 0.0; k++; } } > > t2[0] = Microseconds(); fftwf_execute( plan_f ); t2[1] = Also you will eventually want to move the planning and destroy plan outside the main FFT routine since you will presumably be transforming a lot of images of exactly the same size. Hope this helps. -- Regards, Martin Brown