def main(): import argparse parser = argparse.ArgumentParser(description='Replay captured USB packets') parser.add_argument('--kvp', default=35, type=int) parser.add_argument('--port', default="/dev/ttyUSB0") parser.add_argument('--verbose', action="store_true") parser.add_argument('--dir', default=None, help='Output dir') # Quick test shows that pretty significant improvement until about 4, then drops off # seems pretty diminished beyond around 8 parser.add_argument('-n', default=8, type=int, help='Number images per burst') parser.add_argument('-m', default=1, type=int, help='Number image bursts') parser.add_argument('-t', default=60, type=int, help='Burst period') parser.add_argument('--exp', default=2000, type=int, help='Exposure ms') parser.add_argument('--postfix', default=None, help='') # Generally the center is the most interesting add_bool_arg(parser, "--raw", default=False) parser.add_argument('fn_out', default=None, nargs='?', help='') args = parser.parse_args() outdir = args.dir if outdir is None: outdir = default_date_dir("out", "", args.postfix) if args.kvp: xr = xray.XRay(port=args.port, verbose=args.verbose) mkdir_p(outdir) xr.write_json(outdir) xr.set_kvp(args.kvp) # FIXME: do something more intelligment xr.set_time(300) else: xr = None tnext = time.time() for capm in range(args.m): print("Waiting %u sec until next burst" % (time.time() - tnext, )) while time.time() < tnext: time.sleep(0.1) print("") print("Burst %s" % capm) print("Burst %s" % capm) prefix = "cap_%02u_" % capm fire_verbose = True xr and xr.fire_begin(verbose=fire_verbose) try: run_cap(outdir=outdir, prefix=prefix, postfix=args.postfix, imgn=args.n, exp=args.exp) # notably ^C can cause this finally: xr and xr.fire_abort(verbose=fire_verbose) tnext += args.t print("done")
def run_cap(outdir, prefix, postfix, imgn, bin_out=False, png_out=True, exp=2000, verbose=False): if not outdir: outdir = default_date_dir("out", "", postfix) def cap_cb(n, buff): binfn = os.path.join(outdir, "%s%02u.bin" % (prefix, n)) pngfn = os.path.join(outdir, "%s%02u.png" % (prefix, n)) if bin_out: print("Saving %s" % binfn) open(binfn, 'w').write(buff) if png_out: print("Saving %s" % pngfn) h.decode(buff).save(pngfn) h = ham.Hamamatsu(verbose=verbose) mkdir_p(outdir) h.write_json(outdir) print("Setting exposure %u ms" % exp) h.set_exp(exp) if h.verbose: print('') print('') print('') h.cap(cap_cb, n=imgn)
def main(): import argparse parser = argparse.ArgumentParser(description='') parser.add_argument('--images', type=int, default=0, help='Only take first n images, for debugging') parser.add_argument('--ff-thresh', default=0.25, type=float, help='') parser.add_argument('--df-thresh', default=0.25, type=float, help='') parser.add_argument('ff_dir', help='') parser.add_argument('df_dir', help='') parser.add_argument('cal_dir', nargs='?', default=None, help='') args = parser.parse_args() cal_dir = args.cal_dir if not cal_dir: cal_dir_ff = im_util.default_cal_dir(im_dir=args.ff_dir) cal_dir_df = im_util.default_cal_dir(im_dir=args.df_dir) assert cal_dir_ff == cal_dir_df, "Files are from different sensors" cal_dir = cal_dir_ff mkdir_p(cal_dir) fff, ffi = im_util.average_dir(args.ff_dir, images=args.images) width, height = ffi.size badimg = Image.new("1", (width, height), "Black") ffi.save(cal_dir + '/ff.png') im_util.histeq_im(ffi).save(cal_dir + '/ffe.png') for x, y in bad_pixs_ff(fff, ffi, thresh_scalar=args.ff_thresh): badimg.putpixel((x, y), 1) dff, dfi = im_util.average_dir(args.df_dir, images=args.images) dfi.save(cal_dir + '/df.png') im_util.histeq_im(dfi).save(cal_dir + '/dfe.png') for x, y in bad_pixs_df(dff, dfi, thresh_scalar=args.df_thresh): badimg.putpixel((x, y), 1) badimg.save(cal_dir + '/bad.png') print("done")
def main(): import argparse parser = argparse.ArgumentParser(description='Replay captured USB packets') parser.add_argument('--kvp', default=35, type=int) parser.add_argument('--port', default="/dev/ttyUSB0") parser.add_argument('--verbose', action="store_true") add_bool_arg(parser, '--bin', default=False, help='Write .bin raw data capture') add_bool_arg(parser, '--png', default=True, help='Write normal .png image file') parser.add_argument('--dir', default=None, help='Output dir') # Quick test shows that pretty significant improvement until about 4, then drops off # seems pretty diminished beyond around 8 parser.add_argument('-n', default=8, type=int, help='Number images') parser.add_argument('--exp', default=2000, type=int, help='Exposure ms') parser.add_argument('--postfix', default=None, help='') parser.add_argument('--cal-dir', default=None, help='') # Generally the center is the most interesting parser.add_argument('--hist-eq-roi', default="258,258,516,516", help='hist eq x1,y1,x2,y2') add_bool_arg(parser, "--hist-eq", default=True) add_bool_arg(parser, "--raw", default=False) parser.add_argument('fn_out', default=None, nargs='?', help='') args = parser.parse_args() outdir = args.dir if outdir is None: outdir = default_date_dir("out", "", args.postfix) if args.kvp: xr = xray.XRay(port=args.port, verbose=args.verbose) mkdir_p(outdir) xr.write_json(outdir) xr.set_kvp(args.kvp) # FIXME: do something more intelligment xr.set_time(300) else: xr = None fire_verbose = True xr and xr.fire_begin(verbose=fire_verbose) try: ham_raw.run(outdir=outdir, postfix=args.postfix, imgn=args.n, exp=args.exp) # notably ^C can cause this finally: xr and xr.fire_abort(verbose=fire_verbose) ham_process.run(outdir, args.fn_out, cal_dir=args.cal_dir, hist_eq=args.hist_eq, raw=args.raw, hist_eq_roi=im_util.parse_roi(args.hist_eq_roi)) print("done")