[英]Can't assign to function call
I am writing a code in python,Opencv for implementing a Gaussian low pass filter on compiling it gives the error 'can't assign to function call' at line 14 which is where I take square root . 我在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()
` `
Replace: 更换:
d(u, v) = sqrt(r)
With: 带有:
d[u, v] = sqrt(r)
d(u, v)
expression would throw: d(u, v)
表达式将抛出:
TypeError: 'numpy.ndarray' object is not callable TypeError:“ numpy.ndarray”对象不可调用
But before that Python interpreter sees f() = x
and throws: 但在此之前,Python解释器看到f() = x
并抛出:
SyntaxError: can't assign to function call SyntaxError:无法分配给函数调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.