为什么Matlab fft2比OpenCV dft快得多 [英] why Matlab fft2 is much faster than OpenCV dft

查看:337
本文介绍了为什么Matlab fft2比OpenCV dft快得多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Matlab中测试了OpenCV和ftft2的dft函数之间的速度.我加载相同的图像,使用fft2()和dft()进行转换并测量它们消耗的时间.我发现对于图像,dft()在win32发行版中花费了2秒钟以上,而fft2()仅花费了约0.2s.怎么会?我使用的OpenCV版本是2.4.8,而Matlab版本是2013 a.这是我的测试代码

I just did test to compare the speed bewteen the dft function of OpenCV and fft2 in Matlab. I load the same image, use fft2() and dft() to do the transform and measure the time they consumed. I found that for the image the dft() costed over 2 second in the win32 release version while the fft2() only took round 0.2s. How come? The OpenCV version I used is 2.4.8 while the Matlab version is 2013 a. Here is my codes for testing

Matlab:

tic
X1 = fft2(im);
toc

C ++中的OpenCV:

OpenCV in C++:

start1 = clock();
dft(src,src,DFT_COMPLEX_OUTPUT);
end1 = clock();
cout<<(double)(end1 - start1)/CLOCKS_PER_SEC<<endl;

推荐答案

我已经问了很长时间这个问题和类似的问题 Matlab与c ++ .我找到的答案是

I've asked this and similar questions for very long time fft vs dft and Matlab vs c++. The answer I found is,

  1. Matlab具有一些内置软件,例如MKL,Lapack和BLAS.
  2. 他们在后台使用c或Fortran库.
  3. 他们使用最佳的实现.例如,Matlab中的fft2是基于FFTW的. (西方最快的傅立叶变换)
  4. 他们一直在进步.在某些功能上,新版本明显比旧版本快.

另一方面

  1. 您没有使用OpenCV的最新版本,这应该会对性能产生一些影响.
  2. 您没有按照建议使用DFT,可以通过获取最佳尺寸.如果图像尺寸不是最佳尺寸,则可能会大大增加运行时间.
  1. You are not using the latest version of OpenCV which should have some effect on the performance.
  2. You are not using the DFT as suggested, you can improve the speed by getting the optimal dimensions. If your image dimensions are not optimal, it may significantly increase the running time.

最后一点:不建议使用tic, toc,而应使用timeit.

Final note: it is not recommended to use tic, toc, instead use timeit.

这篇关于为什么Matlab fft2比OpenCV dft快得多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆