【发布时间】:2019-05-10 07:49:08
【问题描述】:
我正在尝试测试一个返回 CLD 功能的函数..
它只需要使用 numpy 库。我正在测试它,但它总是说需要一个 self 参数。我不知道为什么会这样,因为该函数只接收一张我用 opencv 加载的图像。
这是我尝试使用的类: colorlayoutdescriptor.py
import numpy as np
class ColorLayoutDescriptor:
def __init__(self):
self.rows = 8
self.cols = 8
self.prefix = "CLD"
def compute(self, img):
averages = np.zeros((self.rows,self.cols,3))
我希望将一张图像发送到名为compute 的方法并获得一个特征向量,现在我遇到了这个问题::
image = cv2.imread("test.jpg")
vector = ColorLayoutDescriptor.compute(image)
TypeError:compute() 缺少 1 个必需的位置参数:'img'
非常感谢。
【问题讨论】:
-
你想要
ColorLayoutDescriptor().compute(image)。 -
谢谢人..我可以用这种方式访问类的方法..但现在我收到这条消息: slice = img[imgH/self.rows * row: imgH/self .rows * (row+1), imgW/self.cols*col : imgW/self.cols*(col+1)] TypeError: slice indices must be integers or None or have an index method
-
请改为编辑您的问题。 cmets中的代码很难阅读。
-
@Vincent 如果您还有其他问题,请发布另一个问题。
-
没关系,亲爱的..
标签: python function parameters self