我不熟悉python中的类,编译显示错误分段()不带参数

我不熟悉python中的类,编译显示错误分段()不带参数,python,Python,这是我的密码 class segmentatiomn: CLUSTERS = None IMAGE = None COLORS = None LABELS = None def _init_(self,image,clusters=2): self.CLUSTERS = clusters self.IMAGE = image def dominantColors(self): # read image

这是我的密码

class segmentatiomn:

    CLUSTERS = None
    IMAGE = None
    COLORS = None
    LABELS = None
    def _init_(self,image,clusters=2):
     self.CLUSTERS = clusters
     self.IMAGE = image
    def dominantColors(self):
        # read image
        img = cv2.imread(self.IMAGE)

        # convert to rgb from bgr
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

        # reshaping to a list of pixels
        img = img.reshape((img.shape[0] * img.shape[1], 3))

        # save image after operations
        self.IMAGE = img

        # using k-means to cluster pixels
        kmeans = KMeans(n_clusters=self.CLUSTERS)
        kmeans.fit(img)

        # the cluster centers are our dominant colors.
        self.COLORS = kmeans.cluster_centers_
        # save labels
        self.LABELS = kmeans.labels_

        # returning after converting to integer from float
        return self.COLORS.astype(float)

img = 'img'
clusters = 2
dc = segmentatiomn(img, clusters)
colors = dominantColors()
print(colors)

问题是您没有正确定义构造函数。构造函数是
\uuuu init\uuuu
(双下划线)而不是
\uu init\uuuu
(单下划线)。只需更改它,它就会解决您的问题

\uuuu init\uuuuu
而不是
\u init\uuuu
谢谢。这就是问题所在。但是现在如何从函数主导的clors返回和prnt colors值呢