def estoTeSacaUnaListaDeSlides(slides): picsVerticales = [] for line in fileinput.input(): if not fileinput.isfirstline(): #a tomar viento la primera linea separada = line[:len(line) - 1].split(' ') # Separamos por ' ' fila = fileinput.lineno() # n de fila picLeido = Pic(fila - 2, separada) # construyo el leido... if (picLeido.orientation()): picsVerticales.append(picLeido) else: slides.append(Slide(picLeido)) # y lo anado a la lista unirVerticales(slides, picsVerticales)
def estoTeSacaUnaListaDeSlides(slides): picsVerticales = [] for line in fileinput.input(): if not fileinput.isfirstline(): #a tomar viento la primera linea separada = line[:len(line) - 1].split(' ') # Separamos por ' ' fila = fileinput.lineno() # n de fila picLeido = Pic(fila - 2, separada) # construyo el leido... if (picLeido.orientation() ): # es vertical, pa la lista de verticales picsVerticales.append(picLeido) else: # no lo es, a los slides directo slides.append(Slide(picLeido)) # unimos lo verticales a los slides, maximizando tags unirVerticales(slides, picsVerticales)
def crop_to_avg_proportion(cls, limit): directory = "./data/train" _, _, _, _, avg_height, avg_width = Pic.size_ranges(limit) avg_proportion = avg_height / avg_width pics = [] names = [] for image in os.listdir(directory)[:limit]: filepath = directory + "/" + image pic = Image.open(filepath) numpy_pic = numpy.asarray(pic) height, width, _ = numpy_pic.shape new_height = width * avg_proportion new_width = height * (avg_width / avg_height) height_on_both_sides = int(round((height - new_height) / 2)) width_on_both_sides = int(round((width - new_width) / 2)) name = re.findall('/.*/.*(/.*)', pic.filename)[0] names.append(name) if new_height < height: pic = Resize.crop(pic, 0, height_on_both_sides, width, height - (2 * height_on_both_sides)) elif new_width < width: pic = Resize.crop(pic, width_on_both_sides, 0, width - (2 * width_on_both_sides), height) else: print 'error' pics.append(pic) return pics, names
def crop_to_avg_proportion(cls, limit): directory = "./data/train" _, _, _, _, avg_height, avg_width = Pic.size_ranges(limit) avg_proportion = avg_height/avg_width pics = [] names = [] for image in os.listdir(directory)[:limit]: filepath = directory + "/" + image pic = Image.open(filepath) numpy_pic = numpy.asarray(pic) height, width, _ = numpy_pic.shape new_height = width * avg_proportion new_width = height * (avg_width/avg_height) height_on_both_sides = int(round((height - new_height)/2)) width_on_both_sides = int(round((width - new_width)/2)) name = re.findall('/.*/.*(/.*)', pic.filename)[0] names.append(name) if new_height < height: pic = Resize.crop(pic, 0, height_on_both_sides, width, height-(2*height_on_both_sides)) elif new_width < width: pic = Resize.crop(pic, width_on_both_sides, 0, width-(2*width_on_both_sides), height) else: print 'error' pics.append(pic) return pics, names
def a_ver_esa_lectura(pics): for line in fileinput.input(): if not fileinput.isfirstline(): #a tomar viento la primera linea # print(line) separada = line[:len(line) - 1].split(' ') # Separamos por ' ' # print(separada) fila = fileinput.lineno() # n de fila picLeido = Pic(fila - 1, separada) # construyo el leido... pics.append(picLeido) # y lo anado a la lista
def maximizarTags(elto1: Pic, verticales: list) -> Pic: # ESTO ESTA MU FEO minIntersec = 10000 encontrado = False elto2 = verticales[0] longLista = len(verticales) i = 0 while (not encontrado) and ( i < longLista): #esto no es muy pythonesco pero vamos elto2 = verticales[i] long = len(elto1.tags() & elto2.tags()) if long < minIntersec: minIntersec = long if long == 0: encontrado = True i += 1 return verticales.pop(i - 1)
def maximizarTags(elto1: Pic, verticales: list) -> Pic: # ESTO ESTA MU FEO minIntersec = 10000 # vergonzoso encontrado = False elto2 = verticales[0] # asignacion de mas longLista = len(verticales) i = 0 # uf while (not encontrado) and ( i < longLista): #esto no es muy pythonesco pero vamos elto2 = verticales[i] lIntersec = len( elto1.tags() & elto2.tags()) # nÂș de tags compartidos (interseccion) if lIntersec < minIntersec: minIntersec = lIntersec if lIntersec == 0: # es el minimo posible, dejamos de buscar encontrado = True i += 1 # cries in python return verticales.pop( i - 1) # devolvemos el elto (y lo quitamos de verticales)
import sys from pic import Pic from classifier import Classifier from score import error limit = int(sys.argv[1]) half = limit/2 data, targets = Pic.data(limit) data = Pic.flatten(data) data, cv_data = data[:half], data[half:] targets, cv_targets = targets[:half], targets[half:] preds = Classifier.predict(data, targets, data) print error(preds, cv_targets) #print preds #print cv_targets
def site_ico_bind(user_id, pic_id, site_id): p = Pic.get(pic_id) if p and p.user_id == user_id: ico96.set(site_id, pic_id)
# The hex filename is just the passed filename hfilename = filename # If it's not HEX or ASM, what is it? else: raise Exception("Unknown file extension") # If a serial port has not been passed, use the first available one if len(sys.argv) < 3: sport = glob.glob('/dev/ttyUSB*')[0] # Otherwise used the passed one else: sport = sys.argv[2] # Init new HexFile and PIC instances hf = HexFile(hfilename) prog = Pic(sport, 9600, 0x03FF) # Write and verify the hex file to the pic prog.write_file(hf) prog.verify_file(hf) # Write and verify the config word from the hex file to the pic prog.write_verify_config_file(hf) # Run the program on the pic prog.execute() # Close the connection with the pic prog.close()
def pic_to_review_count_by_cid(cid): return Pic.where(cid=cid, state=1, admin_id=0).count()
def test_segments(): data = Pic.images(1) face = Face() print type(data[0]) inners, outers = face.segments(data[0]) print len(inners), len(outers)
import sys from pic import Pic from classifier import Classifier from score import error limit = int(sys.argv[1]) half = limit / 2 data, targets = Pic.data(limit) data = Pic.flatten(data) data, cv_data = data[:half], data[half:] targets, cv_targets = targets[:half], targets[half:] preds = Classifier.predict(data, targets, data) print error(preds, cv_targets) #print preds #print cv_targets
def _pic_list_to_review_by_cid(cid, start_id, limit): return Pic.where(cid=cid, state=1, admin_id=0).where('id>%s' % start_id).order_by('id')[:limit]
def pic_reviewed_count_by_cid_state(cid, state): return Pic.where(cid=cid, state=state).where('admin_id>0').count()
def pic_list_reviewed_by_cid_state(cid, state, limit, offset): return Pic.where(cid=cid, state=state).where('admin_id>0').order_by('id desc')[offset: offset + limit]
# We don't need to compile if it's already a HEX file elif extension == "hex": # The hex filename is just the passed filename hfilename = filename # If it's not HEX or ASM, what is it? else: raise Exception("Unknown file extension") # If a serial port has not been passed, use the first available one if len(sys.argv) < 3: sport = glob.glob('/dev/ttyUSB*')[0] # Otherwise used the passed one else: sport = sys.argv[2] # Init new HexFile and PIC instances hf = HexFile(hfilename) prog = Pic(sport, 9600, 0x03FF) # Write and verify the hex file to the pic prog.write_file(hf) prog.verify_file(hf) # Write and verify the config word from the hex file to the pic prog.write_verify_config_file(hf) # Run the program on the pic prog.execute() # Close the connection with the pic prog.close()
def create_pic(filenames): for filename in filenames: pic = Pic(filename) yield pic