예제 #1
0
def main():
    print("Pixy Python " + VERSION)

    # Create directory to save images
    if not os.path.exists(IMAGES_DIR):
        os.mkdir(IMAGES_DIR)

    # Create a directory for this session
    image_dir = IMAGES_DIR + "/" + str(
        datetime.now().strftime("%Y%m%d_%H%M%S"))
    os.mkdir(image_dir)
    print("Saving images to " + image_dir)
    print("Press Q to quit.")

    pixy.pixy_init()  # Initialize Pixy interface
    pixy.pixy_command("stop")  # Stop default program

    # Allocate memory to store image from camera
    data = pixy.byteArray(SUB_WIDTH * SUB_HEIGHT)

    # Allocate numpy matrix to display
    frame = np.zeros((FRAME_HEIGHT, FRAME_WIDTH, 1), dtype=np.uint8)
    frame_cnt = 0

    while True:
        get_subframe(data, frame, 0, 0)
        get_subframe(data, frame, 320, 0)
        get_subframe(data, frame, 0, 200)
        get_subframe(data, frame, 320, 200)

        # Show image
        cv2.imshow('pixy', frame)

        # Save image to file. Use bitmap format because it's lossless and easy to read back/analyze.
        if frame_cnt < MAX_SAVED_IMAGES_COUNT:
            cv2.imwrite(image_dir + '/{:06d}.bmp'.format(frame_cnt), frame)
        frame_cnt = frame_cnt + 1

        # Check user request to exit
        if cv2.waitKey(1) == ord('q'):
            break

        # Sleep 20ms. Camera can only sample at 50fps max.
        time.sleep(.02)

    cv2.destroyAllWindows()
    pixy.pixy_close()
예제 #2
0
def main(ecv):
    pixy.pixy_init()
    pixy.pixy_command("stop")

    # Get current exposure values
    print("Current exposure setting:")
    print_exposure()

    # Set exposure value
    gain = ecv & 0xFF
    comp = (ecv >> 8) & 0xFFFF
    pixy.pixy_cam_set_exposure_compensation(gain, comp)

    # Confirm exposure value
    print("")
    print("Exposure set to:")
    print_exposure()

    # Close connection
    pixy.pixy_close()
예제 #3
0
            LDrive = -MAX_MOTOR_SPEED
    else:
        LDrive = 0

    if RDrive > deadband:
        if RDrive > MAX_MOTOR_SPEED:
            RDrive = MAX_MOTOR_SPEED
    elif RDrive < -deadband:
        if RDrive < -MAX_MOTOR_SPEED:
            RDrive = -MAX_MOTOR_SPEED
    else:
        RDrive = 0

    # Actually Set the motors
    motors.setSpeeds(int(LDrive), int(RDrive))

if __name__ == '__main__':
    setup()
    while True:
        print 'we run loop'
        ok = loop()
        if not ok:
            print 'not work'
            break
    pixy.pixy_close()
    motors.setSpeeds(0, 0)
    print "Robot Shutdown Completed"