def main():
    p = optparse.OptionParser(usage="Usage: %prog [ options ] <xres> <yres>\n"
      "This program displays a live image of your camera")

    add_common_options(p)

    p.add_option("-o", "--offset", default = "0x0", dest="offset",
            help="Offset in pixels [%default]")
    p.add_option("-b", "--color-coding", default="Y8", dest="cc",
            help="Color coding for acquistion [%default]")
    options, args = p.parse_args()

    if len(args) != 2:
        p.error("Need x and y resolution!")

    l = DC1394Library()
    cam = handle_common_options(options,l)

    m, = filter(lambda m: m.name == "FORMAT7_0", cam.modes)
    cam.mode = m

    size = map(int, args)
    offset = map(int, options.offset.split('x'))
    cc = options.cc

    m.setup(size, offset, cc)

    if cam:
        app = QApplication(args)
        w1 = LiveCameraWin(cam); w1.show(); w1.raise_()
        sys.exit(app.exec_())
def main():
    p = optparse.OptionParser(usage="Usage: %prog [ options ]\n"
      "Acquires 25 pictures and exits.")

    add_common_options(p)

    options, args = p.parse_args()

    l = DC1394Library()
    cam = handle_common_options(options,l)

    if cam:
        print "Starting camera in normal mode. We need to process all pictures!"
        cam.start(interactive=False)

        print "Better be quick now! All images are saved in a Queue object, if we"
        print "are not fast enough in acquisition, the queue will overrun and"
        print "the program will crash."

        print "Acquiring 25 images"
        for idx in range(1,26):
            i = cam.shot()
            print "The last picture %i was acquired at: " % idx, i.timestamp

        cam.stop()

        print "All done."
Exemplo n.º 3
0
def main():
    p = optparse.OptionParser(
        usage="Usage: %prog [ options ]\n" "This program lets the camera run in free running mode."
    )

    add_common_options(p)

    options, args = p.parse_args()

    l = DC1394Library()
    cam = handle_common_options(options, l)

    if cam:
        print "Starting camera in free running mode!"
        cam.start(interactive=True)

        print "We can now do whatever we want, the camera is acquiring"
        print "frames in the background in another thread. Let's sleep a while"
        for i in range(10, -1, -1):
            print i
            time.sleep(1)
            print "The last picture was acquired at: ", cam.current_image.timestamp

        cam.stop()

        print "All done."
Exemplo n.º 4
0
def main():
    """ 
    Parses arguments; initialises logger; initialises camera driver if
    necessary; loads single image from disk if necessary; and runs desired parts
    of pipeline, or loads output from previous execution for printout.
    
    """

    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    logger.info(' '.join(sys.argv[1:]))

    if options.simulate == 0:
        options.simulate = None
        l = DC1394Library()
    elif options.simulate > 0:
        options.simulate -= 1
    elif options.simtime is None:
        options.simtime = 36000

    global pipeline
    pipeline = Pipeline(options)

    if options.disk:
        logger.info('using poses from disk')
        pipe = Pipeline()
        pipe.options = options
        printer = Printer(pipe=pipe)
        printer.final()
        logger.info('done. exiting')
        sys.exit(0)

    if args:
        try:
            image = cv2.imread('images/' + args[0],
                               cv2.CV_LOAD_IMAGE_GRAYSCALE)
            pipeline.set_image(image)
            logger.info('opening image file %s from disk' % args[0])
        except IOError:
            logger.error('image file not found: %s' % args[0])
            exit(1)
    elif options.simulate is not None:
        logger.info('running in simulation mode')
    else:
        try:
            fwcam = handle_common_options(options, l)
            pipeline.set_fwcam(fwcam)
            logger.info('init. pydc1394 camera object')
            logger.info('camera: %s' % fwcam.model)
            logger.info('mode: %s' % fwcam.mode)
            logger.info('framerate: %d' % fwcam.framerate.val)
        except:
            logger.error('unable to open camera capture')
            exit(1)

    pipeline.run()
Exemplo n.º 5
0
def main():
    """ 
    Parses arguments; initialises logger; initialises camera driver if
    necessary; loads single image from disk if necessary; and runs desired parts
    of pipeline, or loads output from previous execution for printout.
    
    """

    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    logger.info(' '.join(sys.argv[1:]))

    if options.simulate == 0:
        options.simulate = None
        l = DC1394Library()
    elif options.simulate > 0:
        options.simulate -= 1
    elif options.simtime is None:
        options.simtime = 36000

    global pipeline
    pipeline = Pipeline(options)

    if options.disk:
        logger.info('using poses from disk')
        pipe = Pipeline()
        pipe.options = options
        printer = Printer(pipe=pipe)
        printer.final()
        logger.info('done. exiting')
        sys.exit(0)

    if args:
        try:
            image = cv2.imread('images/'+args[0], cv2.CV_LOAD_IMAGE_GRAYSCALE)
            pipeline.set_image(image)
            logger.info('opening image file %s from disk' % args[0])
        except IOError:
            logger.error('image file not found: %s' % args[0])
            exit(1)
    elif options.simulate is not None:
        logger.info('running in simulation mode')
    else:
        try:
            fwcam = handle_common_options(options, l)
            pipeline.set_fwcam(fwcam)
            logger.info('init. pydc1394 camera object')
            logger.info('camera: %s' % fwcam.model)
            logger.info('mode: %s' % fwcam.mode)
            logger.info('framerate: %d' % fwcam.framerate.val)
        except:
            logger.error('unable to open camera capture')
            exit(1)

    pipeline.run()
def main():
    p = optparse.OptionParser(usage="Usage: %prog [ options ]\n"
      "This program displays a live image of your camera")

    add_common_options(p)

    options, args = p.parse_args()

    l = DC1394Library()
    cam = handle_common_options(options,l)

    if cam:
        app = QApplication(args)
        w1 = LiveCameraWin(cam); w1.show(); w1.raise_()
        sys.exit(app.exec_())
def main():
    p = optparse.OptionParser(usage="Usage: %prog [ options ]\n"
      "This program displays a live image of your camera")

    add_common_options(p)

    options, args = p.parse_args()

    l = DC1394Library()
    cam = handle_common_options(options,l)

    if cam:
        app = wx.PySimpleApp()
        LiveCameraDisplay(cam)
        app.MainLoop()
Exemplo n.º 8
0
def main():
    """ 
    See module synopsis. Passes image stream from camera driver to OpenCV's
    chessboard corner finder until a threshold number of point correspondence
    sets are achieved. Passes these sets to OpenCV/CalibrateCamera2, and writes
    the resulting estimate for the camera intrinsics to file using Numpy's save
    function.
    
    """

    #p = optparse.OptionParser(usage="Usage: %prog [ options ]\n"
    #  "This program lets the camera run in free running mode.")
    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    #add_common_options(p)

    l = DC1394Library()
    global cam
    cam = handle_common_options(options, l)

    try:
        cam.start(interactive = True)
    except IOError:
        print 'error: cannot open stream' 
        exit(1)

    dims = (9,6)
    pts_per_board = dims[0] * dims[1]
    nr_samples = 20

    pt_counts = np.zeros((nr_samples, 1), dtype = int)                   #pts per image

    frame = np.asarray(cam.current_image)
    model_pts = np.zeros((nr_samples * pts_per_board, 3), dtype = float)
    model_pts = model_pts.astype('float32')
    image_pts = np.zeros((nr_samples * pts_per_board, 2), dtype = float)
    image_pts = image_pts.astype('float32')
    i = 0

    while i < nr_samples:
        frame = np.asarray(cam.current_image)
        found, points = cv2.findChessboardCorners(frame, dims, flags=cv2.CALIB_CB_FAST_CHECK)
        if found and ((points.shape)[0] == pts_per_board):
            cv2.drawChessboardCorners(frame, (6,9), points, found)
            cv2.imshow("win2", frame)
            cv2.waitKey(2)
            step = i * pts_per_board
            j = 0

            while j < pts_per_board:
                image_pts[step, 0] = points[j, 0, 0]
                image_pts[step, 1] = points[j, 0, 1]
                model_pts[step, 0] = float(j) / float(dims[0])
                model_pts[step, 1] = float(j) % float(dims[0])
                model_pts[step, 2] = 0.0
                step += 1
                j += 1

            pt_counts[i, 0] = pts_per_board
            cv2.waitKey(2)
            i += 1
            time.sleep(1)

        else:
            cv2.imshow("win2", frame)
            cv2.waitKey(2)

    camera_matrix = np.array([
        [2.23802515e+03, 0.0, 5.89782959e+02], 
        [0.0, 2.07124146e+03, 4.55921570e+02], 
        [0.0, 0.0, 1.]
        ])
    dist_coeffs = np.zeros(4)

    np.save("image_pts.npy", image_pts)
    np.save("model_pts.npy", model_pts)

    success, intrinsic, distortion_coeffs, rot_est_vecs, transl_est_vecs = cv2.calibrateCamera(model_pts, image_pts, frame.shape, camera_matrix, dist_coeffs, flags=cv2.CALIB_USE_INTRINSIC_GUESS)

    np.save("intrinsic.npy", intrinsic)
    np.save("distortion_coeffs.npy", distortion_coeffs)
    np.save("calibration_rotation_vectors.npy", rot_est_vecs)
    np.save("calibration_translation_vectors.npy", transl_est_vecs)
Exemplo n.º 9
0
def main():
    """ 
    See module synopsis. Passes image stream from camera driver to OpenCV's
    chessboard corner finder until a threshold number of point correspondence
    sets are achieved. Passes these sets to OpenCV/CalibrateCamera2, and writes
    the resulting estimate for the camera intrinsics to file using Numpy's save
    function.
    
    """

    #p = optparse.OptionParser(usage="Usage: %prog [ options ]\n"
    #  "This program lets the camera run in free running mode.")
    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    #add_common_options(p)

    l = DC1394Library()
    global cam
    cam = handle_common_options(options, l)

    try:
        cam.start(interactive=True)
    except IOError:
        print 'error: cannot open stream'
        exit(1)

    dims = (9, 6)
    pts_per_board = dims[0] * dims[1]
    nr_samples = 20

    pt_counts = np.zeros((nr_samples, 1), dtype=int)  #pts per image

    frame = np.asarray(cam.current_image)
    model_pts = np.zeros((nr_samples * pts_per_board, 3), dtype=float)
    model_pts = model_pts.astype('float32')
    image_pts = np.zeros((nr_samples * pts_per_board, 2), dtype=float)
    image_pts = image_pts.astype('float32')
    i = 0

    while i < nr_samples:
        frame = np.asarray(cam.current_image)
        found, points = cv2.findChessboardCorners(
            frame, dims, flags=cv2.CALIB_CB_FAST_CHECK)
        if found and ((points.shape)[0] == pts_per_board):
            cv2.drawChessboardCorners(frame, (6, 9), points, found)
            cv2.imshow("win2", frame)
            cv2.waitKey(2)
            step = i * pts_per_board
            j = 0

            while j < pts_per_board:
                image_pts[step, 0] = points[j, 0, 0]
                image_pts[step, 1] = points[j, 0, 1]
                model_pts[step, 0] = float(j) / float(dims[0])
                model_pts[step, 1] = float(j) % float(dims[0])
                model_pts[step, 2] = 0.0
                step += 1
                j += 1

            pt_counts[i, 0] = pts_per_board
            cv2.waitKey(2)
            i += 1
            time.sleep(1)

        else:
            cv2.imshow("win2", frame)
            cv2.waitKey(2)

    camera_matrix = np.array([[2.23802515e+03, 0.0, 5.89782959e+02],
                              [0.0, 2.07124146e+03, 4.55921570e+02],
                              [0.0, 0.0, 1.]])
    dist_coeffs = np.zeros(4)

    np.save("image_pts.npy", image_pts)
    np.save("model_pts.npy", model_pts)

    success, intrinsic, distortion_coeffs, rot_est_vecs, transl_est_vecs = cv2.calibrateCamera(
        model_pts,
        image_pts,
        frame.shape,
        camera_matrix,
        dist_coeffs,
        flags=cv2.CALIB_USE_INTRINSIC_GUESS)

    np.save("intrinsic.npy", intrinsic)
    np.save("distortion_coeffs.npy", distortion_coeffs)
    np.save("calibration_rotation_vectors.npy", rot_est_vecs)
    np.save("calibration_translation_vectors.npy", transl_est_vecs)