Exemplo n.º 1
0
import pytemplate as temp
import ink2Traces
import drawTraces
import fileSeg
import drawRegions
import SClass as nsi
import symbolPreprocessing as spp
import os
import copy
from pprint import pprint

#Script per comparar les features entre 2 casos

symboldB,tagClassification,average=temp.readTemplate()
genTags={}
for character in tagClassification:
	if character[:-1] not in genTags:
		genTags[character[:-1]]=[]
	genTags[character[:-1]].append([character,len(tagClassification[character])])
for onlySym in genTags:
	for i in range(len(genTags[onlySym])):
		if genTags[onlySym][i][1]<0.05*sum([genTags[onlySym][caseID][1] for caseID in range(len(genTags[onlySym]))]):
			del tagClassification[genTags[onlySym][i][0]]
			del average[genTags[onlySym][i][0]]
filenom='algb02.inkml'
Coord=ink2Traces.i2t(filenom)		#Extreure les coordenades donades pel fitxer
img,byAxis,difs=drawTraces.draw(Coord)		#Mostrar resultat obtingut i montar imatge
Symb,groupedStrokes=fileSeg.segment(Coord,byAxis,difs)		#Agrupar traces en simbols
Symb=drawRegions.drawS(Symb)
symbol=spp.preprocessing([Symb[1]])
symbol[0].computeFeatures()
#!/usr/bin/env python

import pytemplate as temp
import operator as op
import numpy as np
from pybrain.utilities import percentError
from pybrain.datasets import ClassificationDataSet as clds
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure.modules import SoftmaxLayer
from pybrain.supervised.trainers import BackpropTrainer

symboldB,tagClassification,averages=temp.readTemplate()
genTags={}
for character in tagClassification:
	if character[:-1] not in genTags:
		genTags[character[:-1]]=[]
	genTags[character[:-1]].append([character,len(tagClassification[character])])
for onlySym in genTags:
	for i in range(len(genTags[onlySym])):
		if genTags[onlySym][i][1]<0.05*sum([genTags[onlySym][caseID][1] for caseID in range(len(genTags[onlySym]))]):
			del tagClassification[genTags[onlySym][i][0]]
			del averages[genTags[onlySym][i][0]]
references={}
charCo=0
dataset=clds(270,1,len(tagClassification))
for character in tagClassification:
	references[character]=charCo
	charCo+=1
	while tagClassification[character][0].tE.shape[0]<3:
		print character
		for i in range(len(tagClassification[character])):
Exemplo n.º 3
0
#Sistema sencer, llegeix nom del fitxer inkml a analitzar i retorna l'expressio (ex: overAll.py fitxerAClassificar.inkml)
filenom = sys.argv[1]  #Llegir el nom del fitxer InkML de la consola
Coord = ink2Traces.i2t(filenom)  #Extreure les coordenades donades pel fitxer
img, byAxis, difs = drawTraces.draw(
    Coord)  #Mostrar resultat obtingut i montar imatge
Symb, groupedStrokes = fileSeg.segment(Coord, byAxis,
                                       difs)  #Agrupar traces en simbols
Symb = drawRegions.drawS(
    Symb)  #Buscar la bounding box i el centre de cada simbol
Symb = spp.preprocessing(Symb)  #Preprocessar tots els simbols
print 'Computing features..........'
for i in range(len(Symb)):
    Symb[i].computeFeatures()  #Calcular les features de cada simbol
print 'Features extracted.'
symboldB, tagClassification, averages = temp.readTemplate(
)  #Llegeix la base de dades per extreure tots els simbols etiquetats, totes les mostres ordenades per caracter(etiqueta) i el template de cada caracter
genTags = {
}  #Busca el significat independent de cada caracter i si la proporcio del caracter respecte el significat independent es molt baixa ho considera soroll i elimina el caracter
#Elimina components sorollosos de la base de dades
for character in tagClassification:
    if character[:-1] not in genTags:
        genTags[character[:-1]] = []
    genTags[character[:-1]].append(
        [character, len(tagClassification[character])])
for onlySym in genTags:
    for i in range(len(genTags[onlySym])):
        if genTags[onlySym][i][1] < 0.06 * sum([
                genTags[onlySym][caseID][1]
                for caseID in range(len(genTags[onlySym]))
        ]):
            del tagClassification[genTags[onlySym][i][0]]