def trainClassifier(foldername,classifierName):
model = cv2.ml.KNearest_create()
features = []
labels = []
os.chdir(foldername)
for filename in glob.iglob('*.png'):
features.append(cv2.imread((filename),-1))
labels.append(filename[0])
list_hog_fd = []
for feature in features:
fd = hog(feature.reshape((27, 35)), orientations=9, pixels_per_cell=(9, 7), cells_per_block=(1, 1), visualise=False)
list_hog_fd.append(fd)
hog_features = np.array(list_hog_fd, 'float64')
os.chdir("..")
clf = LinearSVC()
clf.fit(hog_features, labels)
joblib.dump(clf,classifierName, compress=3)
os.chdir("..")
评论列表
文章目录