Пример #1
0
def alt(bin_lid):
    tmp = mkdirs(scratch(bin_lid))
    csv_filename = os.path.join(tmp,bin_lid+'_alt.csv')
    logging.info('listing images for %s' % bin_lid)
    imagenames = [remove_extension(i) for i in list_images(bin_lid)]
    logging.info('looking for existing altitude data...')
    already_done = []
    if os.path.exists(csv_filename):
        for row in read_csv(LocalFileSource(csv_filename)):
            already_done += [remove_extension(row[0])]
    logging.info('found %d existing altitude records' % len(already_done))
    if len(already_done) == -1:
        logging.info('emptying CSV file ...')
        with open(csv_filename,'w') as csv_out:
            pass
    pids = []
    for n in range(NUM_PROCS):
        pid = os.fork()
        if pid == 0:
            for imagename in imagenames[n::NUM_PROCS]:
                if imagename not in already_done:
                    tif = img_as_float(read_image(imagename+'.tif'))
                    logging.info('[%d] START aligning %s' % (n, imagename))
                    x,y,m = stereo2altitude(tif)
                    line = '%s,%d,%d,%.2f' % (imagename,x,y,m) 
                    logging.info('[%d] DONE aligned %s' % (n, line))
                    with open(csv_filename,'a') as csv_out:
                        print >>csv_out, line
                        csv_out.flush()
            os._exit(0)
        else:
            logging.info('spawned process %d' % pid)
            pids += [pid]
    for pid in pids:
        logging.info('waiting for process %d' % pid)
        os.waitpid(pid,0)
        logging.info('joined alignment process %d' % pid)
    # now sort file
    logging.info('sorting CSV data...')
    rows = list(read_csv(LocalFileSource(csv_filename)))
    rows = sorted(rows, key=lambda r: r[0])
    csv_out = csv_filename # same as in
    with open(csv_out,'w') as co:
        for row in rows:
            print >>co, ','.join([row[n] for n in range(4)])
    logging.info('wrote CSV data to %s' % csv_out)
Пример #2
0
def compute_alt(cfa_LR_path):
    """ given the path to a RAW 16-bit 1stereo pair, compute the altitude """
    cfa_LR = img_as_float(imread(cfa_LR_path,plugin='freeimage'))
    x,y,alt = stereo2altitude(cfa_LR)
    return x,y,alt
Пример #3
0
def stereo2altitude(cfa_LR,config={}):
    cfa_LR = read_image(cfa_LR,plugin='freeimage')
    (x,y,m) = altitude.stereo2altitude(cfa_LR)
    print 'altitude = (%d,%d,%.2f)' % (x,y,m) # FIXME debug
    return (x,y,m)