def feature_extractor():

    #Abrir arquivo que vai receber as features dos arquivos de imagens
    file = "image_features_train_20_15.arff"
    text_file = open(file, "a")
    trainPath = "C:/Python27/ARP/Dataset/train2"
    dirList = os.listdir(trainPath)
    edge = EdgeHistogramFeatureExtractor(20)
    for dirName in dirList:
		fileList = os.listdir(trainPath + '/' + dirName)
		maxsize = len(fileList)
		for i in range(0, maxsize):
			#print fileList[i]
			filePATH = (trainPath + '/' + dirName + '/' + fileList[i])
			img = Image(filePATH)
			#Feature - Edge histogram
			edge_vecs = edge.extract(img)
			edge_fields = edge.getFieldNames()
			for y in range(0, edge.getNumFields()):
				#print edge_fields[y], '=', edge_vecs[y]
				text_file.write(str(edge_vecs[y]) + ",")
			#Feature - Hue	
			hue = HueHistogramFeatureExtractor(15)
			hue_vecs = hue.extract(img)
			hue_fields = hue.getFieldNames()
			for i in range(0, hue.getNumFields()):
				text_file.write(str(hue_vecs[i]) + ",")
			text_file.write(dirName + "\n")
    text_file.close()
Ejemplo n.º 2
0
def hue():
    hue = HueHistogramFeatureExtractor()
    a = np.array(hue.extract(watchman.imgbank[0])) 

    if len(watchman.imgbank) > 1:
        b = np.array(hue.extract(watchman.imgbank[1])) 
    else:
        b = np.array(hue.extract(watchman.imgbank[0]))

    AandB = np.sum(np.square(a-b)) 
    return AandB
Ejemplo n.º 3
0
def hue():
    hue = HueHistogramFeatureExtractor()
    a = np.array(hue.extract(watchman.imgbank[0]))

    if len(watchman.imgbank) > 1:
        b = np.array(hue.extract(watchman.imgbank[1]))
    else:
        b = np.array(hue.extract(watchman.imgbank[0]))

    AandB = np.sum(np.square(a - b))
    return AandB
 def getFeatureExtractors(self):
     hueHistogramFeatureExtractor = HueHistogramFeatureExtractor(10)
     edgeHistogramFeatureExtractor = EdgeHistogramFeatureExtractor(10)
     haarLikeFeatureExtractor = HaarLikeFeatureExtractor(
         fname='/Users/burton/Downloads/SimpleCV/SimpleCV/Features/haar.txt'
     )
     return [
         hueHistogramFeatureExtractor, edgeHistogramFeatureExtractor,
         haarLikeFeatureExtractor
     ]
Ejemplo n.º 5
0
 def createExtractor(self, extractorName, trainPaths=[]):
     if (extractorName == 'hue'):
         extractor = HueHistogramFeatureExtractor(10)
     elif (extractorName == 'edge'):
         extractor = EdgeHistogramFeatureExtractor(10)
     elif (extractorName == 'haar'):
         extractor = HaarLikeFeatureExtractor(fname='haar.txt')
     elif (extractorName == 'bof'):
         extractor = BOFFeatureExtractor()
         extractor.generate(trainPaths, imgs_per_dir=40)
         # need to build the vocabuary (feature words) for bag of feature
         # extractor.generate(trainPaths, imgs_per_dir=40)
     return extractor
Ejemplo n.º 6
0
 def createExtractor(self, extractorName, trainPaths=[]):
     if (extractorName == 'hue'):
         extractor = HueHistogramFeatureExtractor(10)
     elif (extractorName == 'edge'):
         extractor = EdgeHistogramFeatureExtractor(10)
     elif (extractorName == 'haar'):
         extractor = HaarLikeFeatureExtractor(fname='haar.txt')
     elif (extractorName == 'bof'):
         extractor = BOFFeatureExtractor()
         extractor.generate(trainPaths, imgs_per_dir=40)
         # need to build the vocabuary (feature words) for bag of feature
         # extractor.generate(trainPaths, imgs_per_dir=40)
     return extractor
Ejemplo n.º 7
0
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import AdaBoostClassifier
from sklearn import cross_validation

from SimpleCV import Image
from SimpleCV import HueHistogramFeatureExtractor
from SimpleCV import HaarLikeFeatureExtractor
from SimpleCV import EdgeHistogramFeatureExtractor

import numpy as np
from glob import glob
import pickle

# model to extract feature
hhfe = HueHistogramFeatureExtractor(10)
ehfe = EdgeHistogramFeatureExtractor(10)
haarfe = HaarLikeFeatureExtractor('haar.txt')

# Give path of the training folder
images = glob('./fruits/*')


# Extract features and target labels for training
def get_feature_labels():
    features = list()
    labels = list()
    for im in images:
        try:
            img = Image(im)
            labels.append(im[:-2])