Search code examples
pythonfunctionparametersself

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. I don't know why it is happening because the function only is receiving one image which I'm loading with opencv.

Here is the class that I'm trying to use: 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::

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

TypeError: compute() missing 1 required positional argument: 'img'

thanks so much.


Solution

  • ColorLayoutDescriptor is a class, so you first have to create an instance of the class:

    cld = ColorLayoutDescriptor()
    cld.compute(image)