예제 #1
0
def grab(fname):
    print "Getting pyfly2 context ..."
    context = pyfly2.Context()
    print "Done."

    if context.num_cameras:

        print "Getting camera ...",
        camera = context.get_camera(0)
        print "Done."

        print "Connecting to camera ...",
        camera.Connect()
        print "Done."

        print "Querying camera information ..."
        for k, v in camera.info.iteritems():
            print k, v
        print "Done."

        print "Starting capture mode ...",
        camera.StartCapture()
        print "Done."

        print "Grabbing single image ...",
        camera.GrabImageToDisk(fname)
        print "Done."

        print "Stopping capture mode ...",
        camera.StopCapture()
        print "Done."

        print "Image saved as", fname
    else:
        raise ValueError("No cameras found\n")
예제 #2
0
def grab(fname):
    print("Getting pyfly2 context ...")
    context = pyfly2.Context()
    print("Done.")

    if context.num_cameras:

        print("Getting camera ...", end=' ')
        camera = context.get_camera(0)
        print("Done.")

        print("Connecting to camera ...", end=' ')
        camera.connect()
        print("Done.")

        print("Querying camera information ...")
        for k, v in camera.info.items():
            print(k, v)
        print("Done.")

        print("Starting capture mode ...", end=' ')
        camera.start_capture()
        print("Done.")

        print("Grabbing single image ...", end=' ')
        camera.grab_image_to_disk(fname)
        print("Done.")

        print("Stopping capture mode ...", end=' ')
        camera.stop_capture()
        print("Done.")

        print("Image saved as", fname)
    else:
        raise ValueError("No cameras found\n")
예제 #3
0
def main(cameraIndex=0, format='bgr', scale=1.0, windowName='Live Video'):
    context = pyfly2.Context()
    if context.num_cameras < 1:
        raise ValueError('No cameras found')
    camera = context.get_camera(cameraIndex)
    camera.connect()
    camera.start_capture()
    while cv2.waitKey(1) == -1:
        image = camera.grab_numpy_image(format)
        if scale != 1.0:
            image = cv2.resize(image, (0, 0), fx=scale, fy=scale)
        cv2.imshow(windowName, image)
    camera.stop_capture()
예제 #4
0
def main():
    print "Getting pyfly2 context ..."
    context = pyfly2.Context()
    print "Done."

    # assert(not (context.num_cameras == 0))
    print "Getting camera ...",
    camera = context.get_camera(0)
    print "Done."

    print "Connecting to camera ...",
    camera.Connect()
    print "Done."

    print "Querying camera information ..."
    for k, v in camera.info.iteritems():
        print k, v
    print "Done."

    print "Starting capture mode ...",
    camera.StartCapture()
    print "Done."

    counter = 0
    N = 40
    while (True):
        if (counter % N == 0):
            frame = camera.GrabNumPyImage('bgr')
            imagename = './obstacle-detection/floor-video/images/' + str(
                counter / N).zfill(4)
            cv2.imwrite(imagename + ".jpg", frame)
        counter += 1

    print "Stopping capture mode ...",
    camera.StopCapture()
    print "Done."
예제 #5
0
        caffe.set_mode_gpu()
        caffe.set_device(args.gpu_id)
        cfg.GPU_ID = args.gpu_id

    prototxt = '/home/goring/Documents/py-faster-rcnn/models/pascal_voc/VGG16/faster_rcnn_end2end/25/test.prototxt'
    caffemodel = '/home/goring/Documents/py-faster-rcnn/output/faster_rcnn_end2end/voc_2007_trainval/vgg16_faster_rcnn_iter_100000.caffemodel'
    if not os.path.isfile(caffemodel):
        raise IOError(('{:s} not found.\nDid you run ./data/script/'
                       'fetch_faster_rcnn_models.sh?').format(caffemodel))
    net = caffe.Net(prototxt, caffemodel, caffe.TEST)

    print '\n\nLoaded network {:s}'.format(caffemodel)

    if INPUT_MODE == 1:
        import pyfly2
        context = pyfly2.Context()
        if context.num_cameras < 1:
            raise ValueError('No cameras found')
        camera = context.get_camera(0)
        camera.Connect()
        camera.StartCapture()
        while True:
            image = getImage(camera)
            demo_video(net, image)
    elif INPUT_MODE == 0:
        for imageName in imageFiles:
            image = cv2.imread(os.path.join(imagePath, imageName))
            demo_video(net, image)
    elif INPUT_MODE == 2:
        videoFilePath = '/home/goring/Documents/DataSets/RobotX/Daytona/avis/'
        videoFileName = 'CAM 1 - lighttower1'
예제 #6
0
def main():
    context = pyfly2.Context()
    camera = context.get_camera(0)

    test = SpeedTest(camera)
    test.Start()
예제 #7
0
def main():
    global calibrateMode
    global turnMode

    lc = lcm.LCM()  # Create object of lcm library
    subscription = lc.subscribe("PROCESSING_RECEIVE", msg_handler)

    print "Getting pyfly2 context ..."
    context = pyfly2.Context()
    print "Done."

    # assert(not (context.num_cameras == 0))
    print "Getting camera ...",
    camera = context.get_camera(0)
    print "Done."

    print "Connecting to camera ...",
    camera.Connect()
    print "Done."

    print "Querying camera information ..."
    for k, v in camera.info.iteritems():
        print k, v
    print "Done."

    print "Starting capture mode ...",
    camera.StartCapture()
    print "Done."

    start_time = time.time()
    counter = 0

    turnAngle_Ref = mc.getYaw()
    print "Reference angle:", turnAngle_Ref

    while (True):
        end_time = time.time()
        if (end_time - start_time > PROCESSING_INTERVAL):
            stopBot()  # Stop the bot during processing
            frame = camera.GrabNumPyImage('bgr')
            # TODO: Undistort frame
            cv2.imwrite("share/" + str(counter) + ".jpg", frame)
            print "Written to share/" + str(counter) + ".jpg"
            msg = example_t()
            msg.currImage = counter
            # TODO add focal length to message / result
            lc.publish("PROCESSING_SEND", msg.encode())
            print "published by gc.py"
            # TODO Delete previous image
            lc.handle()  # Recieve angle
            start_time = time.time()  # Restart count

        counter += 1
        global turnAngle
        ANGLE_THRES = 0.13
        angle_to_rotate = turnAngle
        print "Angle to rotate:", angle_to_rotate
        if (abs(angle_to_rotate) >
                ANGLE_THRES):  # Turn bot (sharply) in given direction
            rotate(angle_to_rotate * 180 / math.pi)
        else:
            moveForward()

        # TODO handle bot movement
        time.sleep(SLEEP_TIME)