def testSVM(testDataSetpath,clf): for image in testDataSetpath: if label(image)==clf.predict(extract_feature(image)): ok+=1 else: ko+=1 print "accuracy:" + float( ok)/(ok+ko)
def read_data(path): X=[] Y=[] empty_path = path + "/empty" white_path = path + "/white" black_path = path + "/black" paths = [empty_path, white_path, black_path] for i,path in enumerate(paths): onlyfiles = [ f for f in listdir(path) if isfile(join(path,f)) ] for image in onlyfiles: image_array = cv2.imread(path + "/" + image) X.append(extract_feature(image_array)) Y.append(i) X,Y = data_shuffle(X,Y) return (np.asarray(X),np.asarray(Y))