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") 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(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(): '''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
#!/usr/bin/python from numpy import array,zeros from matplotlib import pyplot import chameleon colour = 0 depth = 8 h = chameleon.open(colour, depth) im = zeros((960,1280),dtype='uint8') f = pyplot.figure(1) for i in range(0,10): try: sts = chameleon.trigger(h) if (sts == 0): (shutter, ftime) = chameleon.capture(h, im) except chameleon.error: print('failed to capture') pyplot.imshow(im) f.show() chameleon.close(h) k = raw_input()
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 error_count = 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') 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) if not opts.trigger: print('Starting continuous trigger') chameleon.trigger(h, True) 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.format != 'pgm': state.bayer_queue.put((base_time+frame_time, im)) if opts.save and opts.format == 'pgm': if opts.reduction == 0 or num_captured % opts.reduction == 0: state.save_queue.put((base_time+frame_time, im)) print("Captured %s shutter=%f tdelta=%f(%.2f) ft=%f loss=%u qsave=%u qbayer=%u" % ( get_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())) error_count = 0 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)
#!/usr/bin/python import chameleon, cv, time, sys, numpy, os sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "image")) import scanner colour = 0 depth = 8 try: h = chameleon.open(1, depth, 100) colour = 1 except chameleon.error: h = chameleon.open(0, depth, 100) colour = 0 print("Found camera: colour=%u GUID=%x" % (colour, chameleon.guid(h))) im = numpy.zeros((960, 1280), dtype="uint8") im_640 = numpy.zeros((480, 640, 3), dtype="uint8") cv.NamedWindow("Viewer") tstart = time.time() try: os.mkdir("tmp") except os.error: pass i = 0 while True: