TypeError: src data type = 15 is not supported

孤人 提交于 2019-12-31 01:56:32

问题


I want to use Fast Fourier Transform but already trying a simple back and forth transformation doesn't work. The code is

import cv2
import numpy as np

img = cv2.imread('Picture.bmp',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
f_ishift = np.fft.ifftshift(fshift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])

and the error is

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    img_back = cv2.idft(f_ishift)
TypeError: src data type = 15 is not supported

How can this be fixed?


回答1:


I think I figured it out. cv2.idft() wants the complex numbers in a different format. I had to extract the real and imaginary part separately and write them in the third dimension:

import cv2
import numpy as np

img = cv2.imread('Bild.bmp',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
f_ishift = np.fft.ifftshift(fshift)
d_shift = np.array(np.dstack([f_ishift.real,f_ishift.imag]))
img_back = cv2.idft(d_shift)
img = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])


来源:https://stackoverflow.com/questions/30989915/typeerror-src-data-type-15-is-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!