cv2.km bedeutet die Verwendung in Python

Ich überlege, die Kmeans-Implementierung von OpenCV zu verwenden, da sie angeblich schneller ist ...

Jetzt benutze ich Paket cv2 und Funktion kmeans,

Ich kann die Beschreibung der Parameter in ihrer Referenz nicht verstehen:

Python: cv2.kmeans(data, K, criteria, attempts, flags[, bestLabels[, centers]]) → retval, bestLabels, centers
samples – Floating-point matrix of input samples, one row per sample.
clusterCount – Number of clusters to split the set by.
labels – Input/output integer array that stores the cluster indices for every sample.
criteria – The algorithm termination criteria, that is, the maximum number of iterations and/or the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster centers moves by less than criteria.epsilon on some iteration, the algorithm stops.
attempts – Flag to specify the number of times the algorithm is executed using different initial labelings. The algorithm returns the labels that yield the best compactness (see the last function parameter).
flags –
Flag that can take the following values:
KMEANS_RANDOM_CENTERS Select random initial centers in each attempt.
KMEANS_PP_CENTERS Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].
KMEANS_USE_INITIAL_LABELS During the first (and possibly the only) attempt, use the user-supplied labels instead of computing them from the initial centers. For the second and further attempts, use the random or semi-random centers. Use one of KMEANS_*_CENTERS flag to specify the exact method.
centers – Output matrix of the cluster centers, one row per each cluster center.

Was ist das Argumentflags[, bestLabels[, centers]]) bedeuten? und was ist mit seinem:→ retval, bestLabels, centers ?

Hier ist mein Code:

import cv, cv2
import scipy.io
import numpy

# read data from .mat file
mat = scipy.io.loadmat('...')
keys = mat.keys()
values = mat.viewvalues()

data_1 = mat[keys[0]]
nRows = data_1.shape[1] 
nCols = data_1.shape[0]
samples = cv.CreateMat(nRows, nCols, cv.CV_32FC1)
labels = cv.CreateMat(nRows, 1, cv.CV_32SC1)
centers = cv.CreateMat(nRows, 100, cv.CV_32FC1)
#centers = numpy.

for i in range(0, nCols):
    for j in range(0, nRows):
        samples[j, i] = data_1[i, j]


cv2.kmeans(data_1.transpose,
                              100,
                              criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_MAX_ITER, 0.1, 10),
                              attempts=cv2.KMEANS_PP_CENTERS,
                              flags=cv2.KMEANS_PP_CENTERS,
)

Und ich stoße auf einen solchen Fehler:

flags=cv2.KMEANS_PP_CENTERS,
TypeError: <unknown> is not a numpy array

Wie soll ich die Parameterliste und die Verwendung von cv2.kmeans verstehen? Vielen Dank

Antworten auf die Frage(2)

Ihre Antwort auf die Frage