gpt4 book ai didi

python - 类型错误 : src data type = 15 is not supported

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:51 32 4
gpt4 key购买 nike

我想使用快速傅里叶变换,但已经尝试简单的来回变换不起作用。代码是

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])

错误是

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

如何解决这个问题?

最佳答案

我想我明白了。 cv2.idft() 想要不同格式的复数。我不得不分别提取实部和虚部并将它们写在三维空间中:

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])

关于python - 类型错误 : src data type = 15 is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30989915/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com