Ejemplo n.º 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'''
  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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
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"""
    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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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 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,
                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)
Ejemplo n.º 6
0
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 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,
        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)
Ejemplo n.º 7
0
    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:
Ejemplo n.º 8
0
#!/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()

Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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:
    try:
        chameleon.trigger(h)
        frame_time = time.time()
        shutter = chameleon.capture(h, 1000, im)
    except chameleon.error, msg:
        print("failed to capture", msg)
        continue
    scanner.debayer(im, im_640)
    regions = scanner.scan(im_640)
    if len(regions) > 0:
        print("Found %u regions" % len(regions))
        for r in regions:
            (minx, miny, maxx, maxy) = r
            print(minx, miny, maxx, maxy)

    mat = cv.fromarray(im_640)
    for (x1, y1, x2, y2) in regions:
Ejemplo n.º 11
0
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: