def buildHistogram(path, trainData, voc, training, level, sift): if training is False: trainData = utils.readImages(folderPath + path, sift)[0] # Transform each feature into histogram featureHistogram = [] labels = [] index = 0 for oneImage in trainData: featureHistogram.append(voc.buildHistogramForEachImageAtDifferentLevels(oneImage, level)) labels.append(oneImage.label) index += 1 return [featureHistogram, labels]
def buildHistogram(path, level): # Read in vocabulary & data voc = utils.loadDataFromFile("Data/voc.pkl") Data = utils.readImages(path) # Transform each feature into histogram featureHistogram = [] labels = [] index = 0 for oneImage in Data: featureHistogram.append( voc.buildHistogramForEachImageAtDifferentLevels(oneImage, level)) return featureHistogram
def buildHistogram(path, level): # Read in vocabulary & data voc = utils.loadDataFromFile("Data/voc.pkl") trainData = utils.readImages("images/"+path) # Transform each feature into histogram featureHistogram = [] labels = [] index = 0 for oneImage in trainData: featureHistogram.append(voc.buildHistogramForEachImageAtDifferentLevels(oneImage, level)) labels.append(oneImage.label) index += 1 utils.writeDataToFile("Data/"+path+"HistogramLevel" +str(level)+ ".pkl", featureHistogram) utils.writeDataToFile("Data/"+path+"labels.pkl", labels)
def main(): level = 2 sift = False training_path = "c1_test" testing_path = "c1_train" # training_path = "training" # testing_path = "testing" # training_path = "caltech_train" # testing_path = "caltech_test" # read train data [train_data, train_features] = utils.readImages(folderPath + training_path, sift) # create vocabulary training_voc = Vocabulary(train_features, 200) [test_hist, test_label] = buildHistogram(testing_path, None, training_voc, False, level, sift) [train_hist, train_label] = buildHistogram(training_path, train_data, training_voc, True, level, sift) classification.SVM_Classify(train_hist, train_label, test_hist, test_label, "HI")