def get_base_time(): '''we need to get a baseline time from the camera. To do that we trigger in single shot mode until we get a good image, and use the time we triggered as the base time''' frame_time = None error_count = 0 print('Opening camera') h = chameleon.open(not opts.mono, opts.depth, opts.brightness) print('camera is open') if opts.framerate != 0: chameleon.set_framerate(h, opts.framerate) while frame_time is None: try: base_time = time.time() im = numpy.zeros((960,1280),dtype='uint8' if opts.depth==8 else 'uint16') chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) base_time -= frame_time except chameleon.error: print('failed to capture') error_count += 1 if error_count > 3: error_count = 0 print('re-opening camera') chameleon.close(h) h = chameleon.open(not opts.mono, opts.depth, opts.brightness) return h, base_time, frame_time
def get_base_time(): '''we need to get a baseline time from the camera. To do that we trigger in single shot mode until we get a good image, and use the time we triggered as the base time''' frame_time = None error_count = 0 print('Opening camera') h = chameleon.open(not opts.mono, opts.depth, opts.brightness) print('camera is open') if opts.framerate != 0: chameleon.set_framerate(h, opts.framerate) while frame_time is None: try: base_time = time.time() im = numpy.zeros((960,1280),dtype='uint8' if opts.depth==8 else 'uint16') chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) base_time -= frame_time except chameleon.error: print('failed to capture') error_count += 1 if error_count > 3: error_count = 0 print('re-opening camera') chameleon.close(h) h = chameleon.open(not opts.mono, opts.depth, opts.brightness) if opts.framerate != 0: chameleon.set_framerate(h, opts.framerate) return h, base_time, frame_time
def get_base_time(depth=8, colour=1, capture_brightness=150): '''we need to get a baseline time from the camera. To do that we trigger in single shot mode until we get a good image, and use the time we triggered as the base time''' frame_time = None error_count = 0 print('Opening camera') h = chameleon.open(colour, depth, capture_brightness) print('Getting camare base_time') while frame_time is None: try: im = numpy.zeros((960,1280),dtype='uint8' if depth==8 else 'uint16') base_time = time.time() chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) base_time -= frame_time except chameleon.error: print('failed to capture') error_count += 1 if error_count > 3: error_count = 0 print('re-opening camera') chameleon.close(h) h = chameleon.open(colour, depth, capture_brightness) print('base_time=%f' % base_time) return h, base_time, frame_time
def get_base_time(depth=8, colour=1, capture_brightness=150): '''we need to get a baseline time from the camera. To do that we trigger in single shot mode until we get a good image, and use the time we triggered as the base time''' frame_time = None error_count = 0 print('Opening camera') h = chameleon.open(colour, depth, capture_brightness) print('Getting camare base_time') while frame_time is None: try: im = numpy.zeros((960, 1280), dtype='uint8' if depth == 8 else 'uint16') base_time = time.time() chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) base_time -= frame_time except chameleon.error: print('failed to capture') error_count += 1 if error_count > 3: error_count = 0 print('re-opening camera') chameleon.close(h) h = chameleon.open(colour, depth, capture_brightness) print('base_time=%f' % base_time) return h, base_time, frame_time
def run_capture(): '''the main capture loop''' print("Getting base frame time") h, base_time, last_frame_time = get_base_time() if not opts.trigger: print('Starting continuous trigger') chameleon.trigger(h, True) frame_loss = 0 num_captured = 0 last_frame_counter = 0 print('Starting main capture loop') while True: im = numpy.zeros((960,1280),dtype='uint8' if opts.depth==8 else 'uint16') try: if opts.trigger: chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) except chameleon.error: print('failed to capture') continue if frame_time < last_frame_time: base_time += 128 if last_frame_counter != 0: frame_loss += frame_counter - (last_frame_counter+1) if opts.compress or opts.scan: state.bayer_queue.put((base_time+frame_time, im)) if opts.save and not opts.compress: if opts.reduction == 0 or num_captured % opts.reduction == 0: state.save_queue.put((base_time+frame_time, im, False)) print("Captured %s shutter=%f tdelta=%f(%.2f) ft=%f loss=%u qsave=%u qbayer=%u qcompress=%u scan=%u" % ( cuav_util.frame_time(base_time+frame_time), shutter, frame_time - last_frame_time, 1.0/(frame_time - last_frame_time), frame_time, frame_loss, state.save_queue.qsize(), state.bayer_queue.qsize(), state.compress_queue.qsize(), state.scan_queue.qsize())) last_frame_time = frame_time last_frame_counter = frame_counter num_captured += 1 if num_captured == opts.num_frames: break print('Closing camera') time.sleep(2) chameleon.close(h)
def run_capture(): '''the main capture loop''' print("Getting base frame time") h, base_time, last_frame_time = get_base_time() if not opts.trigger: print('Starting continuous trigger') chameleon.trigger(h, True) frame_loss = 0 num_captured = 0 last_frame_counter = 0 print('Starting main capture loop') while True: im = numpy.zeros((960, 1280), dtype='uint8' if opts.depth == 8 else 'uint16') try: if opts.trigger: chameleon.trigger(h, False) frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im) except chameleon.error: print('failed to capture') continue if frame_time < last_frame_time: base_time += 128 if last_frame_counter != 0: frame_loss += frame_counter - (last_frame_counter + 1) if opts.compress or opts.scan: state.bayer_queue.put((base_time + frame_time, im)) if opts.save and not opts.compress: state.save_queue.put((base_time + frame_time, im, False)) print( "Captured %s shutter=%f tdelta=%f(%.2f) ft=%f loss=%u qsave=%u qbayer=%u qcompress=%u scan=%u" % (cuav_util.frame_time(base_time + frame_time), shutter, frame_time - last_frame_time, 1.0 / (frame_time - last_frame_time), frame_time, frame_loss, state.save_queue.qsize(), state.bayer_queue.qsize(), state.compress_queue.qsize(), state.scan_queue.qsize())) last_frame_time = frame_time last_frame_counter = frame_counter num_captured += 1 if num_captured == opts.num_frames: break print('Closing camera') time.sleep(2) chameleon.close(h)
chameleon.save_pgm(filename, im) colour = 1 h, base_time, last_frame_time = get_base_time(opts.depth, colour=colour, capture_brightness=opts.capbrightness) print("Found camera: colour=%u GUID=%x" % (colour, chameleon.guid(h))) if opts.depth == 8: dtype = 'uint8' else: dtype = 'uint16' im = numpy.zeros((960,1280),dtype=dtype) cv.NamedWindow('Viewer') tstart = time.time() chameleon.trigger(h, True) chameleon.set_gamma(h, opts.gamma) cuav_util.mkdir_p(opts.output) start_thread(save_thread) i=0 lost = 0 while True: try: frame_time, frame_counter, shutter = chameleon.capture(h, 300, im) except chameleon.error, msg: lost += 1 continue if frame_time < last_frame_time:
colour = 1 h, base_time, last_frame_time = get_base_time( opts.depth, colour=colour, capture_brightness=opts.capbrightness) print("Found camera: colour=%u GUID=%x" % (colour, chameleon.guid(h))) if opts.depth == 8: dtype = 'uint8' else: dtype = 'uint16' im = numpy.zeros((960, 1280), dtype=dtype) cv.NamedWindow('Viewer') tstart = time.time() chameleon.trigger(h, True) chameleon.set_gamma(h, opts.gamma) cuav_util.mkdir_p(opts.output) start_thread(save_thread) i = 0 lost = 0 while True: try: frame_time, frame_counter, shutter = chameleon.capture(h, 300, im) except chameleon.error, msg: lost += 1 continue if frame_time < last_frame_time: