画像を分類したりするときに主流のCNNを使えばいいのですが、基礎に立ち返るのも大事なのであえてBag of wordsを実行。
テンプレート
# -*- coding: utf-8 -*- import cv2 import numpy as np clusternum = 5 BOW, shift = cv2.BOWKMeansTrainer(clusternum), cv2.SIFT() for filename in imagefile: img_rgb = cv2.imread(filename) img_gray = cv2.cvtColor(img_rgb, cv2.CV_LOAD_IMAGE_GRAYSCALE) keypoint, descriptor= sift.detectAndCompute(img_gray, None) BOW.add(descriptor) dictionary = BOW.cluster()
...書きかけです。