简体   繁体   中英

How to create A matrix of images in opencv with python bindings to feed Kmeans2

i am trying to cluster a set of images, my peblems resides in using Kmeans2 parameters in opencv. i dont know exactly how to form the points input for Kmeans2 for clustering.

here what i do :

samples = CreateMat ( samples_len,1,CV_32FC2)
labels = CreateMat ( samples_len,1,CV_43SC1)
index = 0
for name in imglist : 
      img = LoadImage ('someting')
      sample[index] = img
      index += 1

The error i get is : key length does not match array dimension so how to fix it ?

any help would be appreciated

Regards.

Kmeans2 only takes 2-dimensional input data, so unless your images are only 2 pixels this approach will not work. You'll either need to write your own clustering algorithm that handle higher dimensional dagta or write a function that maps your images down to only 2 points (eg mean and variance of the grayscale version of the image). In any case, "clustering" images is a very difficult problem in general.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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