Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.image.processing > #4205

Re: problem about replace opencv dft() function with fftw api

From Martin Brown <|||newspam|||@nezumi.demon.co.uk>
Newsgroups sci.image.processing
Subject Re: problem about replace opencv dft() function with fftw api
Date 2017-01-12 08:22 +0000
Organization Aioe.org NNTP Server
Message-ID <o57ech$kc4$1@gioia.aioe.org> (permalink)
References <ab987f47-8082-4bda-bbc7-16f31948d4d8@googlegroups.com>

Show all headers | View raw


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

Back to sci.image.processing | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

problem about replace opencv dft() function with fftw api Zhi Sun <sunzhimailbox@gmail.com> - 2017-01-10 05:39 -0800
  Re: problem about replace opencv dft() function with fftw api Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2017-01-12 08:22 +0000

csiph-web