简体   繁体   English

如何调用需要自我参数的函数

[英]how to call this function which requires self parameter

I'm trying to test one function which returns the CLD features.. it only requires use numpy library.. I'm testing it but it always says that requires a self parameter. 我正在尝试测试一个返回CLD功能的函数..它只需要使用numpy库..我正在测试它,但它总是说需要一个self参数。 I don't know why it is happening because the function only is receiving one image which I'm loading with opencv. 我不知道为什么会这样,因为该功能仅接收我正在用opencv加载的一张图像。

Here is the class that I'm trying to use: colorlayoutdescriptor.py 这是我要使用的类: 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))

I expect to send one image to the method called compute and get one feature vector, now I'm getting this problem:: 我希望将一幅图像发送到称为compute的方法并获得一个特征向量,现在我遇到了这个问题:

image = cv2.imread("test.jpg")
vector = ColorLayoutDescriptor.compute(image)

TypeError: compute() missing 1 required positional argument: 'img' TypeError:compute()缺少1个必需的位置参数:'img'

thanks so much. 非常感谢。

ColorLayoutDescriptor is a class, so you first have to create an instance of the class: ColorLayoutDescriptor是一个类,因此您首先必须创建该类的实例:

cld = ColorLayoutDescriptor()
cld.compute(image)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM