Ejemplo n.º 1
0
def feature_extractor():

    #Abrir arquivo que vai receber as features dos arquivos de imagens
    file = "image_features_train_20_10_1_Novo4.arff"
    text_file = open(file, "a")
    trainPath = "C:/Python27/ARP/Dataset/train5"
    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(10)
            hue_vecs = hue.extract(img)
            hue_fields = hue.getFieldNames()
            for i in range(0, hue.getNumFields()):
                #		#print hue_fields[i], '=', hue_vecs[i]
                text_file.write(str(hue_vecs[i]) + ",")
            Morph1 = MorphologyFeatureExtractor()
            Morph2 = Morph1.extract(img)
            text_file.write(str(Morph2) + ",")
            text_file.write(dirName + "\n")
    text_file.close()
Ejemplo n.º 2
0
def morph():
    mf = MorphologyFeatureExtractor()
    mf.setThresholdOperation(myBinaryFunc)
    a = np.array(mf.extract(watchman.imgbank[0]))

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

    AandB = np.sum(np.square(a - b))
    return AandB
Ejemplo n.º 3
0
def morph():
    mf = MorphologyFeatureExtractor() 
    mf.setThresholdOperation(myBinaryFunc)
    a = np.array(mf.extract(watchman.imgbank[0])) 

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

    AandB = np.sum(np.square(a-b)) 
    return AandB
Ejemplo n.º 4
0
			for i in range(0, hue.getNumFields()):
				print hue_fields[i], '=', hue_vecs[i]
				text_file.write(str(hue_vecs[i]) + ",")
    #Feature - Haar
    #haar = HaarLikeFeatureExtractor(fname='haar.txt')
    #haar_vecs = haar.extract(img)
    #haar_fields = haar.getFieldNames()
    #for i in range(0, len(haar_fields)):
    #    print haar_fields[i], '=', haar_vecs[i]
    #    text_file.write(str(haar_vecs[i]) + ",")
    text_file.write("revolver")
    text_file.close()
"""
#Criando o header do arquivo ARFF de features	
#var1 = gerador_Header()

#Gerando e gravando as features no arquivo ARFF
#var2 = feature_extractor()

"""	
#classes = ['pistola_gray','revolver_gray',]
"""
img = Image('revolver.jpg')
feature = MorphologyFeatureExtractor()
array = feature.extract(img)
print (array)


	
#text_file.write("revolver")
#text_file.close()
Ejemplo n.º 5
0
from SimpleCV import *
from numpy import *
from SimpleCV.Display import Display, pg
from SimpleCV import MorphologyFeatureExtractor


#we pass this methods as our threshold operation
def thresholdOp(in_image):
    return in_image.binarize(thresh=70).invert().dilate(2)


# extract only morphology
morph_extractor = MorphologyFeatureExtractor()
morph_extractor.setThresholdOperation(thresholdOp)
extractors = [morph_extractor]
#setup the paths to our data
nuts_path = "./data/nuts/"
bolts_path = "./data/bolts/"
path = [nuts_path, bolts_path]
classes = ['washer', 'bolt']
props = {
    'KernelType': 'Linear',  #default is a RBF Kernel
    'SVMType': 'C',  #default is C 
    'nu': None,  # NU for SVM NU
    'c': None,  #C for SVM C - the slack variable
    'degree': None,  #degree for poly kernels - defaults to 3
    'coef': None,  #coef for Poly/Sigmoid defaults to 0
    'gamma':
    None,  #kernel param for poly/rbf/sigma - default is 1/#samples       
}
# flag if we need to train the SVM