示例#1
0
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'''
  state = mpstate.camera_state
  frame_time = None
  error_count = 0

  print('Opening camera')
  h = chameleon.open(state.colour, state.depth, state.capture_brightness)

  print('Getting camare base_time')
  while frame_time is None:
    try:
      im = numpy.zeros((960,1280),dtype='uint8' if state.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(state.colour, state.depth, state.capture_brightness)
  print('base_time=%f' % base_time)
  return h, base_time, frame_time
示例#2
0
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'''
    state = mpstate.camera_state
    frame_time = None
    error_count = 0

    print('Opening camera')
    h = chameleon.open(1, state.settings.depth,
                       state.settings.capture_brightness)

    print('Getting camare base_time')
    while frame_time is None:
        try:
            im = numpy.zeros(
                (960, 1280),
                dtype='uint8' if state.settings.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(1, state.settings.depth,
                                   state.settings.capture_brightness)
    print('base_time=%f' % base_time)
    return h, base_time, frame_time
示例#3
0
def capture_thread():
    '''camera capture thread'''
    state = mpstate.camera_state
    t1 = time.time()
    last_frame_counter = 0
    h = None
    last_gamma = 0

    raw_dir = os.path.join(state.camera_dir, "raw")
    cuav_util.mkdir_p(raw_dir)

    if mpstate.continue_mode:
        mode = 'a'
    else:
        mode = 'w'
    gammalog = open(os.path.join(state.camera_dir, "gamma.log"), mode=mode)

    while not mpstate.camera_state.unload.wait(0.02):
        if not state.running:
            if h is not None:
                chameleon.close(h)
                h = None
            continue
        try:
            if h is None:
                h, base_time, last_frame_time = get_base_time()
                # put into continuous mode
                chameleon.trigger(h, True)

            capture_time = time.time()
            if state.settings.depth == 16:
                im = numpy.zeros((960, 1280), dtype='uint16')
            else:
                im = numpy.zeros((960, 1280), dtype='uint8')
            if last_gamma != state.settings.gamma:
                chameleon.set_gamma(h, state.settings.gamma)
                last_gamma = state.settings.gamma
            frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im)
            if frame_time < last_frame_time:
                base_time += 128
            if last_frame_counter != 0:
                state.frame_loss += frame_counter - (last_frame_counter + 1)

            gammalog.write('%f %f %f %s %u %u\n' %
                           (frame_time, frame_time + base_time, capture_time,
                            cuav_util.frame_time(frame_time + base_time),
                            frame_counter, state.settings.gamma))
            gammalog.flush()

            state.save_queue.put((base_time + frame_time, im))
            state.scan_queue.put((base_time + frame_time, im))
            state.capture_count += 1
            state.fps = 1.0 / (frame_time - last_frame_time)

            last_frame_time = frame_time
            last_frame_counter = frame_counter
        except chameleon.error, msg:
            state.error_count += 1
            state.error_msg = msg
示例#4
0
def capture_thread():
    '''camera capture thread'''
    state = mpstate.camera_state
    t1 = time.time()
    last_frame_counter = 0
    h = None
    last_gamma = 0

    raw_dir = os.path.join(state.camera_dir, "raw")
    cuav_util.mkdir_p(raw_dir)

    gammalog = open(os.path.join(state.camera_dir, "gamma.log"), "w")

    while not mpstate.camera_state.unload.wait(0.02):
        if not state.running:            
            if h is not None:
                chameleon.close(h)
                h = None
            continue
        try:
            if h is None:
                h, base_time, last_frame_time = get_base_time()
                # put into continuous mode
                chameleon.trigger(h, True)

            capture_time = time.time()
            if state.depth == 16:
                im = numpy.zeros((960,1280),dtype='uint16')
            else:
                im = numpy.zeros((960,1280),dtype='uint8')
            if last_gamma != state.gamma:
                chameleon.set_gamma(h, state.gamma)
                last_gamma = state.gamma
            frame_time, frame_counter, shutter = chameleon.capture(h, 1000, im)
            if frame_time < last_frame_time:
                base_time += 128
            if last_frame_counter != 0:
                state.frame_loss += frame_counter - (last_frame_counter+1)
                
            gammalog.write('%f %f %f %s %u %u\n' % (frame_time,
                                                    frame_time+base_time,
                                                    capture_time,
                                                    cuav_util.frame_time(frame_time+base_time),
                                                    frame_counter,
                                                    state.gamma))
            gammalog.flush()

            state.save_queue.put((base_time+frame_time,im))
            state.scan_queue.put((base_time+frame_time,im))
            state.capture_count += 1
            state.fps = 1.0/(frame_time - last_frame_time)

            last_frame_time = frame_time
            last_frame_counter = frame_counter
        except chameleon.error, msg:
            state.error_count += 1
            state.error_msg = msg
示例#5
0
                                              frame_counter,
                                              state.gamma))
            gammalog.flush()

            state.save_queue.put((base_time+frame_time,im))
            state.scan_queue.put((base_time+frame_time,im))
            state.capture_count += 1
            state.fps = 1.0/(frame_time - last_frame_time)

            last_frame_time = frame_time
            last_frame_counter = frame_counter
        except chameleon.error, msg:
            state.error_count += 1
            state.error_msg = msg
    if h is not None:
        chameleon.close(h)

def save_thread():
    '''image save thread'''
    state = mpstate.camera_state
    raw_dir = os.path.join(state.camera_dir, "raw")
    cuav_util.mkdir_p(raw_dir)
    while not state.unload.wait(0.02):
        if state.save_queue.empty():
            continue
        (frame_time,im) = state.save_queue.get()
        rawname = "raw%s" % cuav_util.frame_time(frame_time)
        if state.save_pgm:
            chameleon.save_pgm('%s/%s.pgm' % (raw_dir, rawname), im)

def scan_thread():
示例#6
0
                            cuav_util.frame_time(frame_time + base_time),
                            frame_counter, state.settings.gamma))
            gammalog.flush()

            state.save_queue.put((base_time + frame_time, im))
            state.scan_queue.put((base_time + frame_time, im))
            state.capture_count += 1
            state.fps = 1.0 / (frame_time - last_frame_time)

            last_frame_time = frame_time
            last_frame_counter = frame_counter
        except chameleon.error, msg:
            state.error_count += 1
            state.error_msg = msg
    if h is not None:
        chameleon.close(h)


def save_thread():
    '''image save thread'''
    state = mpstate.camera_state
    raw_dir = os.path.join(state.camera_dir, "raw")
    cuav_util.mkdir_p(raw_dir)
    frame_count = 0
    while not state.unload.wait(0.02):
        if state.save_queue.empty():
            continue
        (frame_time, im) = state.save_queue.get()
        rawname = "raw%s" % cuav_util.frame_time(frame_time)
        frame_count += 1
        if state.settings.save_pgm != 0: