コード例 #1
0
                              processor.upper_thresh[0])
    smart_dashboard.putNumber('Vision/Threshhold/Upper/saturation',
                              processor.upper_thresh[1])
    smart_dashboard.putNumber('Vision/Threshhold/Upper/value',
                              processor.upper_thresh[2])
    smart_dashboard.putNumber('Vision/Threshhold/Lower/hue',
                              processor.lower_thresh[0])
    smart_dashboard.putNumber('Vision/Threshhold/Lower/saturation',
                              processor.lower_thresh[1])
    smart_dashboard.putNumber('Vision/Threshhold/Lower/value',
                              processor.lower_thresh[2])

    while True:
        timestamp, img = cvsink.grabFrame(img)
        if timestamp == 0:
            error_msg = 'Error: ' + str(cvsink.getError())
            print(error_msg)
            if USE_SMART_DASHBOARD:
                smart_dashboard.putString('Vision/errors', error_msg)
            continue

        # The elapsed time is really only for testing to determine the
        #  optimal image resolution and speed.
        start_time = time.time()
        try:
            result, img = processor.process_image(img)
        except:
            continue
        if USE_MODIFIED_IMAGE:
            cvsource.putFrame(img)
        end_time = time.time()
コード例 #2
0
    ntinst.startClientTeam(7539)

    SmartDashBoardValues = ntinst.getTable('SmartDashboard')

    #Start camera
    print("Connecting to camera")
    cs = CameraServer.getInstance()
    cs.enableLogging()
    Camera = UsbCamera('Cam 0', 0)
    Camera.setExposureManual(5)
    Camera.setResolution(160, 120)
    cs.addCamera(Camera)

    print("connected")

    CvSink = cs.getVideo()
    outputStream = cs.putVideo("Processed Frames", 160, 120)

    #buffer to store img data
    img = np.zeros(shape=(160, 120, 3), dtype=np.uint8)
    # loop forever
    while True:

        GotFrame, img = CvSink.grabFrame(img)
        if GotFrame == 0:
            outputStream.notifyError(CvSink.getError())
            continue
        img = TrackTheTape(img, SmartDashBoardValues)

        outputStream.putFrame(img)
コード例 #3
0
        name = 'cvsource: ' + vision_camera[2]['name']
        width = vision_camera[2]['height']
        height = vision_camera[2]['width']
        fps = vision_camera[2]['fps']
        cvsource = CvSource(name, VideoMode.PixelFormat.kMJPEG, width, height,
                            fps)
        mjpeg_server.setSource(cvsource)

    processor = TargetProcessing()
    # Allways preallocate, it runs a lot faster
    img = np.zeros(shape=(config['height'], config['width'], 3),
                   dtype=np.uint8)
    while True:
        timestamp, img = cvsink.grabFrame(img)
        if timestamp == 0:
            print('Error:', cvsink.getError())
            continue

        # The elapsed time is really only for testing to determine the
        #  optimal image resolution and speed.
        start_time = time.time()
        result, img = processor.process_image(img)
        if use_modified_image:
            cvsource.putFrame(img)
        end_time = time.time()
        result = timestamp, *result, round(end_time - start_time, 5)
        # Result key:
        #  timestamp, success, distance, angle1, angle2, elapsedtime
        print(result)
        # smart_dashboard.putNumberArray('Vision/result', result)
        # ntinst.flush()