i have a dataset of images and i want to do clustering on it. I have read the openCV documentations of kmeans but i just do not get it properly. Below is my code and i have no idea how can i pass images to the kmeans() and how to send all the clusters into different folders.
import cv2, sys, numpy, os
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn.cluster import KMeans
fn_dir2 = 'unknown'
path2='/home/irum/Desktop/Face-Recognition/thakarrecog/unknown/UNKNOWNS'
# Create a list of images and a list of corresponding names
(images, lables, names, id) = ([], [], {}, 0)
#reading images from dataset
for (subdirs, dirs, files) in os.walk(fn_dir2):
for subdir in dirs:
names[id] = subdir
subjectpath = os.path.join(fn_dir2, subdir)
for filename in os.listdir(subjectpath):
path = subjectpath + '/' + filename
lable = id
images.append(cv2.imread(path, 0))
lables.append(int(lable))
id += 1
#converting images and lables to numpy arrays
(images, lables) = [numpy.array(lis) for lis in [images, lables]]
print "length images", len(images)
print type(images)
print "length lables", len(lables)
now i have numpy array of images and lables but i do not know what to do next.