我想用kmeans来计算lbp的簇。 首先,我计算每个图像的大小为8 * 8的lbp值。 然后我使用cv2.kmeans,但它无法正常工作 错误:找不到必需参数'flags'(pos 6) 代码:
# -*- coding: utf-8 -*-
"""
Spyder Editor
This temporary script file is located here:
/home/nel/.spyder2/.temp.py
"""
from skimage.feature import local_binary_pattern
from skimage import io
from skimage.color import rgb2gray
import numpy as np
import cv2
def loadImages(path):
import os
imagePaths = map(lambda a:os.path.join(path,a),os.listdir(path))
images = map(io.imread,imagePaths)
return imagePaths,images
def lbpdesc(imagename):
radius = 1
n_points = 8
METHOD = 'nri_uniform'
imagename = io.imread('/home/nel/project/pictest/1.jpg')
gray_image = rgb2gray(imagename)
lbp_height,lbp_width = gray_image.shape
grid_rows = 8
grid_cols = 8
py = int(np.floor(lbp_height/grid_rows))
px = int(np.floor(lbp_width/grid_cols))
E = np.zeros((py*px,64))
i = 0
for row in range(0,py):
for col in range(0,px):
block =gray_image[row*grid_rows:(row+1)*grid_rows,col*grid_cols:(col+1)*grid_cols]
H = local_binary_pattern(block,n_points,radius,METHOD)
E[i,:] = H.ravel()
i+=1
return E
if __name__ =="__main__":
images = {}
imagePath,imagesed = loadImages("/home/nel/project/pictest")
for i in range(len(imagePath)):
images[imagePath[i]] = imagesed[i]
features = {}
for d,x in images.items():
features[d] = lbpdesc(x)
featureall = np.float32(np.vstack(features.values()))
codebookSize = 40
iterMax = 100
term_crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT,10,1)
retval,bestLabels,codebook = cv2.kmeans(featureall,codebookSize,term_crit,iterMax,cv2.KMEANS_RANDOM_CENTERS)
错误:找不到必需的参数'flags'(pos 6)。为什么,我需要你的建议。