Esempio n. 1
0
def convertRawToBGR(pgm):
    global image_width, image_height
    raw = pgm.array
    print 'mock_flea::convertRawToBGR debayer'
    bgr = numpy.zeros((image_height, image_width, 3), dtype='uint8')
    scanner.debayer(raw, bgr)
    return bgr
Esempio n. 2
0
def convertRawToBGR(pgm):
    global image_width, image_height
    raw = pgm.array
    print 'mock_flea::convertRawToBGR debayer'
    bgr = numpy.zeros((image_height, image_width, 3), dtype='uint8')
    scanner.debayer(raw, bgr)
    return bgr
Esempio n. 3
0
File: flea.py Progetto: jaxiano/cuav
def convertRawToBGR(raw):
	global image_width, image_height
	print 'flea::convertRawToBGR debayer'
    	bgr = numpy.zeros((image_height, image_width, 3), dtype='uint8')
	try:
		scanner.debayer(raw, bgr)
	except Exception, msg:
		print 'Exception: %s' % msg
Esempio n. 4
0
def convertRawToBGR(raw):
    global image_width, image_height
    print 'flea::convertRawToBGR debayer'
    bgr = numpy.zeros((image_height, image_width, 3), dtype='uint8')
    try:
        scanner.debayer(raw, bgr)
    except Exception, msg:
        print 'Exception: %s' % msg
Esempio n. 5
0
def bayer_thread():
  '''thread for debayering images'''
  while True:
    frame_time, im = state.bayer_queue.get()
    im_colour = numpy.zeros((960,1280,3),dtype='uint8')
    scanner.debayer(im, im_colour)
    if opts.compress:
      state.compress_queue.put((frame_time, im_colour))
    if opts.scan:
      im_640 = numpy.zeros((480,640,3),dtype='uint8')
      scanner.downsample(im_colour, im_640)
      state.scan_queue.put((frame_time, im_640))
Esempio n. 6
0
def bayer_thread():
  '''thread for debayering images'''
  while True:
    frame_time, im = state.bayer_queue.get()
    im_colour = numpy.zeros((960,1280,3),dtype='uint8')
    scanner.debayer(im, im_colour)
    if opts.compress:
      state.compress_queue.put((frame_time, im_colour))
    if opts.scan:
      im_640 = numpy.zeros((480,640,3),dtype='uint8')
      scanner.downsample(im_colour, im_640)
      state.scan_queue.put((frame_time, im_640))
Esempio n. 7
0
def scan_thread():
    '''image scanning thread'''
    state = mpstate.camera_state

    while not state.unload.wait(0.02):
        try:
            # keep the queue size below 100, so we don't run out of memory
            if state.scan_queue.qsize() > 100:
                (frame_time,im) = state.scan_queue.get(timeout=0.2)
            (frame_time,im) = state.scan_queue.get(timeout=0.2)
        except Queue.Empty:
            continue

        t1 = time.time()
        im_full = numpy.zeros((960,1280,3),dtype='uint8')
        im_640 = numpy.zeros((480,640,3),dtype='uint8')
        scanner.debayer(im, im_full)
        scanner.downsample(im_full, im_640)
        if state.settings.fullres:
            img_scan = im_full
        else:
            img_scan = im_640
        regions = scanner.scan(img_scan)
        if state.settings.filter_type=='compactness':
            calculate_compactness = True
        else:
            calculate_compactness = False
        regions = cuav_region.RegionsConvert(regions,
                                             cuav_util.image_shape(img_scan),
                                             cuav_util.image_shape(im_full),
                                             calculate_compactness)
        t2 = time.time()
        state.scan_fps = 1.0 / (t2-t1)
        state.scan_count += 1

        regions = cuav_region.filter_regions(im_full, regions, min_score=min(state.settings.minscore,state.settings.minscore2),
                                             filter_type=state.settings.filter_type)

        state.region_count += len(regions)
        if state.transmit_queue.qsize() < 100:
            state.transmit_queue.put((frame_time, regions, im_full, im_640))
Esempio n. 8
0
File: debayer.py Progetto: 1ee7/cuav
def debayer(filename, show=True):
    '''debayer an image'''
    pgm = cuav_util.PGM(filename)
    img = numpy.zeros((960,1280,3),dtype='uint8')
    if opts.gamma != 0:
        img8 = numpy.zeros((960,1280,1),dtype='uint8')
        scanner.gamma_correct(pgm.array, img8, opts.gamma)
    else:
        img8 = pgm.array
    scanner.debayer(img8, img)
    color_img = cv.CreateImageHeader((1280, 960), 8, 3)
    cv.SetData(color_img, img)
    if opts.half:
        half_img = cv.CreateImage((640,480), 8, 3)
        cv.Resize(color_img, half_img)
        color_img = half_img        

    cv.ConvertScale(color_img, color_img, scale=opts.brightness)
    if show:
        cv.ShowImage('Bayer', color_img)
    return (color_img, pgm)
Esempio n. 9
0
def debayer(filename, show=True):
    '''debayer an image'''
    pgm = cuav_util.PGM(filename)
    img = numpy.zeros((960, 1280, 3), dtype='uint8')
    if opts.gamma != 0:
        img8 = numpy.zeros((960, 1280, 1), dtype='uint8')
        scanner.gamma_correct(pgm.array, img8, opts.gamma)
    else:
        img8 = pgm.array
    scanner.debayer(img8, img)
    color_img = cv.CreateImageHeader((1280, 960), 8, 3)
    cv.SetData(color_img, img)
    if opts.half:
        half_img = cv.CreateImage((640, 480), 8, 3)
        cv.Resize(color_img, half_img)
        color_img = half_img

    cv.ConvertScale(color_img, color_img, scale=opts.brightness)
    if show:
        cv.ShowImage('Bayer', color_img)
    return (color_img, pgm)
Esempio n. 10
0
def scan_thread():
    '''image scanning thread'''
    state = mpstate.camera_state

    while not state.unload.wait(0.02):
        try:
            # keep the queue size below 100, so we don't run out of memory
            if state.scan_queue.qsize() > 100:
                (frame_time, im) = state.scan_queue.get(timeout=0.2)
            (frame_time, im) = state.scan_queue.get(timeout=0.2)
        except Queue.Empty:
            continue

        t1 = time.time()
        im_full = numpy.zeros((960, 1280, 3), dtype='uint8')
        im_640 = numpy.zeros((480, 640, 3), dtype='uint8')
        scanner.debayer(im, im_full)
        scanner.downsample(im_full, im_640)
        if state.settings.fullres:
            img_scan = im_full
        else:
            img_scan = im_640
        regions = scanner.scan(img_scan)
        regions = cuav_region.RegionsConvert(regions,
                                             cuav_util.image_shape(img_scan),
                                             cuav_util.image_shape(im_full))
        t2 = time.time()
        state.scan_fps = 1.0 / (t2 - t1)
        state.scan_count += 1

        regions = cuav_region.filter_regions(
            im_full,
            regions,
            min_score=min(state.settings.minscore, state.settings.minscore2),
            filter_type=state.settings.filter_type)

        state.region_count += len(regions)
        if state.transmit_queue.qsize() < 100:
            state.transmit_queue.put((frame_time, regions, im_full, im_640))
Esempio n. 11
0
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:
    base_time += 128
  save_queue.put((frame_time+base_time, im))
  last_frame_time = frame_time
  img_colour = numpy.zeros((960,1280,3),dtype='uint8')
  scanner.debayer(im, img_colour)
  img_colour = cv.GetImage(cv.fromarray(img_colour))
  if opts.half:
    img_640 = cv.CreateImage((640,480), 8, 3)
    cv.Resize(img_colour, img_640)
    img_colour = img_640

  cv.ConvertScale(img_colour, img_colour, scale=opts.brightness)
  cv.ShowImage('Viewer', img_colour)
  key = cv.WaitKey(1)
  i += 1

  if i % 10 == 0:
    tdiff = time.time() - tstart
    print("captured %u  lost %u  %.1f fps shutter=%f" % (
      i, lost,
Esempio n. 12
0
def process(args):
  '''process a set of files'''

  global slipmap, mosaic
  scan_count = 0
  files = []
  for a in args:
    if os.path.isdir(a):
      files.extend(glob.glob(os.path.join(a, '*.pgm')))
    else:
      files.append(a)
  files.sort()
  num_files = len(files)
  print("num_files=%u" % num_files)
  region_count = 0
  joes = []

  if opts.mavlog:
    mpos = mav_position.MavInterpolator(gps_lag=opts.gps_lag)
    mpos.set_logfile(opts.mavlog)
  else:
    mpos = None

  if opts.boundary:
    boundary = cuav_util.polygon_load(opts.boundary)
  else:
    boundary = None

  if opts.mosaic:
    slipmap = mp_slipmap.MPSlipMap(service='GoogleSat', elevation=True, title='Map')
    icon = slipmap.icon('planetracker.png')
    slipmap.add_object(mp_slipmap.SlipIcon('plane', (0,0), icon, layer=3, rotation=0,
                                           follow=True,
                                           trail=mp_slipmap.SlipTrail()))
    C_params = cam_params.CameraParams(lens=opts.lens)
    path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..',
                        'cuav', 'data', 'chameleon1_arecont0.json')
    C_params.load(path)
    mosaic = cuav_mosaic.Mosaic(slipmap, C=C_params)
    if boundary is not None:
      mosaic.set_boundary(boundary)

  if opts.joe:
    joes = cuav_util.polygon_load(opts.joe)
    if boundary:
      for i in range(len(joes)):
        joe = joes[i]
        if cuav_util.polygon_outside(joe, boundary):
          print("Error: joe outside boundary", joe)
          return
        icon = slipmap.icon('flag.png')
        slipmap.add_object(mp_slipmap.SlipIcon('joe%u' % i, (joe[0],joe[1]), icon, layer=4))

  joelog = cuav_joe.JoeLog('joe.log')      

  if opts.view:
    viewer = mp_image.MPImage(title='Image')

  frame_time = 0

  for f in files:
    if mpos:
      frame_time = cuav_util.parse_frame_time(f)
      try:
        if opts.roll_stabilised:
          roll = 0
        else:
          roll = None
        pos = mpos.position(frame_time, opts.max_deltat,roll=roll)
        slipmap.set_position('plane', (pos.lat, pos.lon), rotation=pos.yaw)
      except mav_position.MavInterpolatorException as e:
        print e
        pos = None
    else:
      pos = None

    # check for any events from the map
    if opts.mosaic:
      slipmap.check_events()
      mosaic.check_events()

    if f.endswith('.pgm'):
      pgm = cuav_util.PGM(f)
      im = pgm.array
      if pgm.eightbit:
        im_8bit = im
      else:
        im_8bit = numpy.zeros((960,1280,1),dtype='uint8')
        if opts.gamma != 0:
          scanner.gamma_correct(im, im_8bit, opts.gamma)
        else:
          scanner.reduce_depth(im, im_8bit)
      im_full = numpy.zeros((960,1280,3),dtype='uint8')
      scanner.debayer(im_8bit, im_full)
      im_640 = numpy.zeros((480,640,3),dtype='uint8')
      scanner.downsample(im_full, im_640)
    else:
      im_orig = cv.LoadImage(f)
      (w,h) = cuav_util.image_shape(im_orig)
      im_full = im_orig
      im_640 = cv.CreateImage((640, 480), 8, 3)
      cv.Resize(im_full, im_640, cv.CV_INTER_NN)
      im_640 = numpy.ascontiguousarray(cv.GetMat(im_640))
      im_full = numpy.ascontiguousarray(cv.GetMat(im_full))

    count = 0
    total_time = 0
    img_scan = im_640

    t0=time.time()
    for i in range(opts.repeat):
      if opts.fullres:
        regions = scanner.scan(im_full)
        regions = cuav_region.RegionsConvert(regions, 1280, 960)
      else:
        regions = scanner.scan(img_scan)
        regions = cuav_region.RegionsConvert(regions)
      count += 1
    t1=time.time()

    if opts.filter:
      regions = cuav_region.filter_regions(im_full, regions, frame_time=frame_time, min_score=opts.minscore,
                                           filter_type=opts.filter_type)

    scan_count += 1

    # optionally link all the images with joe into a separate directory
    # for faster re-running of the test with just joe images
    if pos and opts.linkjoe and len(regions) > 0:
      cuav_util.mkdir_p(opts.linkjoe)
      if not cuav_util.polygon_outside((pos.lat, pos.lon), boundary):
        joepath = os.path.join(opts.linkjoe, os.path.basename(f))
        if os.path.exists(joepath):
          os.unlink(joepath)
        os.symlink(f, joepath)

    if pos and len(regions) > 0:
      joelog.add_regions(frame_time, regions, pos, f, width=1280, height=960, altitude=opts.altitude)

      if boundary:
        regions = cuav_region.filter_boundary(regions, boundary, pos)

    region_count += len(regions)

    if opts.mosaic and len(regions) > 0:
      composite = cuav_mosaic.CompositeThumbnail(cv.GetImage(cv.fromarray(im_full)), regions)
      thumbs = cuav_mosaic.ExtractThumbs(composite, len(regions))
      mosaic.add_regions(regions, thumbs, f, pos)

    if opts.compress:
      jpeg = scanner.jpeg_compress(im_full, opts.quality)
      jpeg_filename = f[:-4] + '.jpg'
      if os.path.exists(jpeg_filename):
        print('jpeg %s already exists' % jpeg_filename)
        continue
      chameleon.save_file(jpeg_filename, jpeg)

    if opts.view:
      if opts.fullres:
        img_view = im_full
      else:
        img_view = img_scan
      mat = cv.fromarray(img_view)
      for r in regions:
        (x1,y1,x2,y2) = r.tuple()
        (w,h) = cuav_util.image_shape(img_view)
        x1 = x1*w//1280
        x2 = x2*w//1280
        y1 = y1*h//960
        y2 = y2*h//960
        cv.Rectangle(mat, (max(x1-2,0),max(y1-2,0)), (x2+2,y2+2), (255,0,0), 2)
      cv.CvtColor(mat, mat, cv.CV_BGR2RGB)
      viewer.set_image(mat)

    total_time += (t1-t0)
    if t1 != t0:
      print('%s scan %.1f fps  %u regions [%u/%u]' % (
        f, count/total_time, region_count, scan_count, num_files))
Esempio n. 13
0
def process(filename):
    '''process one file'''
    pgm = cuav_util.PGM(filename)
    img_full_grey = pgm.array

    im_full = numpy.zeros((960, 1280, 3), dtype='uint8')
    im_640 = numpy.zeros((480, 640, 3), dtype='uint8')

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.debayer_half(img_full_grey, im_640)
    t1 = time.time()
    print('debayer: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.debayer(img_full_grey, im_full)
    t1 = time.time()
    print('debayer_full: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    im_full2 = cv.CreateImage((1280, 960), 8, 3)
    img_full_grey2 = cv.GetImage(cv.fromarray(img_full_grey))
    for i in range(opts.repeat):
        cv.CvtColor(img_full_grey2, im_full2, cv.CV_BayerBG2BGR)
    t1 = time.time()
    print('debayer_cv_full: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        img = cv.GetImage(cv.fromarray(im_full))
        cv.CvtColor(img, img, cv.CV_RGB2HSV)
    t1 = time.time()
    print('RGB2HSV_full: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        img = cv.GetImage(cv.fromarray(im_640))
        cv.CvtColor(img, img, cv.CV_RGB2HSV)
    t1 = time.time()
    print('RGB2HSV_640: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        thumb = numpy.empty((100, 100, 3), dtype='uint8')
        scanner.rect_extract(im_full, thumb, 120, 125)
    t1 = time.time()
    print('rect_extract: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        thumb = cuav_util.SubImage(cv.GetImage(cv.fromarray(im_full)),
                                   (120, 125, 100, 100))
    t1 = time.time()
    print('SubImage: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.downsample(im_full, im_640)
    t1 = time.time()
    print('downsample: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.scan(im_640)
    t1 = time.time()
    print('scan: %.1f fps' % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.scan(im_full)
    t1 = time.time()
    print('scan_full: %.1f fps' % (opts.repeat / (t1 - t0)))

    if not hasattr(scanner, 'jpeg_compress'):
        return

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            jpeg = cPickle.dumps(ImagePacket(
                time.time(), scanner.jpeg_compress(im_full, quality)),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
        t1 = time.time()
        print('jpeg full quality %u: %.1f fps  %u bytes' %
              (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            img2 = cv.fromarray(im_full)
            jpeg = cPickle.dumps(ImagePacket(
                time.time(),
                cv.EncodeImage(
                    '.jpeg', img2,
                    [cv.CV_IMWRITE_JPEG_QUALITY, quality]).tostring()),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
        t1 = time.time()
        print('EncodeImage full quality %u: %.1f fps  %u bytes' %
              (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            jpeg = cPickle.dumps(ImagePacket(
                time.time(), scanner.jpeg_compress(im_640, quality)),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
        t1 = time.time()
        print('jpeg 640 quality %u: %.1f fps  %u bytes' %
              (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for thumb_size in [10, 20, 40, 60, 80, 100]:
        thumb = numpy.zeros((thumb_size, thumb_size, 3), dtype='uint8')
        t0 = time.time()
        for i in range(opts.repeat):
            scanner.rect_extract(im_full, thumb, 0, 0)
            jpeg = cPickle.dumps(ImagePacket(time.time(),
                                             scanner.jpeg_compress(thumb, 85)),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
        t1 = time.time()
        print('thumb %u quality 85: %.1f fps  %u bytes' %
              (thumb_size, opts.repeat / (t1 - t0), len(bytes(jpeg))))
Esempio n. 14
0
def process(filename):
    """process one file"""
    pgm = cuav_util.PGM(filename)
    img_full_grey = pgm.array

    im_full = numpy.zeros((960, 1280, 3), dtype="uint8")
    im_640 = numpy.zeros((480, 640, 3), dtype="uint8")

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.debayer(img_full_grey, im_640)
    t1 = time.time()
    print("debayer: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.debayer_full(img_full_grey, im_full)
    t1 = time.time()
    print("debayer_full: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    im_full2 = cv.CreateImage((1280, 960), 8, 3)
    img_full_grey2 = cv.GetImage(cv.fromarray(img_full_grey))
    for i in range(opts.repeat):
        cv.CvtColor(img_full_grey2, im_full2, cv.CV_BayerBG2BGR)
    t1 = time.time()
    print("debayer_cv_full: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        img = cv.GetImage(cv.fromarray(im_full))
        cv.CvtColor(img, img, cv.CV_RGB2HSV)
    t1 = time.time()
    print("RGB2HSV_full: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        img = cv.GetImage(cv.fromarray(im_640))
        cv.CvtColor(img, img, cv.CV_RGB2HSV)
    t1 = time.time()
    print("RGB2HSV_640: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        thumb = numpy.empty((100, 100, 3), dtype="uint8")
        scanner.rect_extract(im_full, thumb, 120, 125)
    t1 = time.time()
    print("rect_extract: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        thumb = cuav_util.SubImage(cv.GetImage(cv.fromarray(im_full)), (120, 125, 100, 100))
    t1 = time.time()
    print("SubImage: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.downsample(im_full, im_640)
    t1 = time.time()
    print("downsample: %.1f fps" % (opts.repeat / (t1 - t0)))

    t0 = time.time()
    for i in range(opts.repeat):
        scanner.scan(im_640)
    t1 = time.time()
    print("scan: %.1f fps" % (opts.repeat / (t1 - t0)))

    if not hasattr(scanner, "jpeg_compress"):
        return

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            jpeg = cPickle.dumps(
                ImagePacket(time.time(), scanner.jpeg_compress(im_full, quality)), protocol=cPickle.HIGHEST_PROTOCOL
            )
        t1 = time.time()
        print("jpeg full quality %u: %.1f fps  %u bytes" % (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            img2 = cv.fromarray(im_full)
            jpeg = cPickle.dumps(
                ImagePacket(
                    time.time(), cv.EncodeImage(".jpeg", img2, [cv.CV_IMWRITE_JPEG_QUALITY, quality]).tostring()
                ),
                protocol=cPickle.HIGHEST_PROTOCOL,
            )
        t1 = time.time()
        print("EncodeImage full quality %u: %.1f fps  %u bytes" % (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for quality in [30, 40, 50, 60, 70, 80, 90, 95]:
        t0 = time.time()
        for i in range(opts.repeat):
            jpeg = cPickle.dumps(
                ImagePacket(time.time(), scanner.jpeg_compress(im_640, quality)), protocol=cPickle.HIGHEST_PROTOCOL
            )
        t1 = time.time()
        print("jpeg 640 quality %u: %.1f fps  %u bytes" % (quality, opts.repeat / (t1 - t0), len(bytes(jpeg))))

    for thumb_size in [10, 20, 40, 60, 80, 100]:
        thumb = numpy.zeros((thumb_size, thumb_size, 3), dtype="uint8")
        t0 = time.time()
        for i in range(opts.repeat):
            scanner.rect_extract(im_full, thumb, 0, 0)
            jpeg = cPickle.dumps(
                ImagePacket(time.time(), scanner.jpeg_compress(thumb, 85)), protocol=cPickle.HIGHEST_PROTOCOL
            )
        t1 = time.time()
        print("thumb %u quality 85: %.1f fps  %u bytes" % (thumb_size, opts.repeat / (t1 - t0), len(bytes(jpeg))))
Esempio n. 15
0
def convertRawToBGR(img):
	global image_height, image_width
	bgr = numpy.zeros((image_height, image_width, 3), dtype='uint8')
	print 'chameleon::convertRawToBGR debayer'
	scanner.debayer(img, bgr)
	return bgr
Esempio n. 16
0
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:
        base_time += 128
    save_queue.put((frame_time + base_time, im))
    last_frame_time = frame_time
    img_colour = numpy.zeros((960, 1280, 3), dtype='uint8')
    scanner.debayer(im, img_colour)
    img_colour = cv.GetImage(cv.fromarray(img_colour))
    if opts.half:
        img_640 = cv.CreateImage((640, 480), 8, 3)
        cv.Resize(img_colour, img_640)
        img_colour = img_640

    cv.ConvertScale(img_colour, img_colour, scale=opts.brightness)
    cv.ShowImage('Viewer', img_colour)
    key = cv.WaitKey(1)
    i += 1

    if i % 10 == 0:
        tdiff = time.time() - tstart
        print("captured %u  lost %u  %.1f fps shutter=%f" %
              (i, lost, 10 / tdiff, shutter))