无法分配给函数调用

时间:2017-09-24 07:55:04

标签: python opencv

我正在编写一个python中的代码,Opencv用于在编译时实现高斯低通滤波器,它给出了错误“无法分配给函数调用'在第14行,这是我采取平方根。

`import cv2
import numpy as np
from math import sqrt
img = cv2.imread('polys.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
magnitude_spectrum = 20*np.log(np.abs(fshift))
m, n = img.shape
m2,n2 = m/2 , n/2
d=np.zeros((m,n))
for u in range(m):
for v in range(n):
    r=((u-m2)*(u-m2))+((v-n2)*(v-n2))
    d(u,v)=sqrt(r)
    d(u,v)=int(d(u,v))
    if d(u,v)>10:
       h(u,v)=0
    elif d(u,v)<=10:
       h(u,v)= math.exp(-(d(u,v)*d(u,v))/(2*10*10))

result=h*fshift    
f_ishift = np.fft.ifftshift(result)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)


cv2.imshow('dft',img_back)
cv2.waitKey(0)
cv2.destroyAllWindows()

`

1 个答案:

答案 0 :(得分:2)

替换:

d(u, v) = sqrt(r)

使用:

d[u, v] = sqrt(r)

d(u, v)表达式会抛出:

  

TypeError:&#39; numpy.ndarray&#39;对象不可调用

但在此之前,Python解释器会看到f() = x并抛出:

  

SyntaxError:无法分配给函数调用