예제 #1
0
파일: camera.py 프로젝트: Digital8/mavelous
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
파일: camera.py 프로젝트: wuyou33/MAVProxy
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
파일: camera.py 프로젝트: wuyou33/MAVProxy
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
파일: camera.py 프로젝트: ulise75/MAVProxy
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