Exemplo n.º 1
0
def start_camera():
    inst = CameraServer.getInstance()
    camera = UsbCamera('Hatch Panels', '/dev/video0')

    # with open("cam.json", encoding='utf-8') as cam_config:
    #     camera.setConfigJson(json.dumps(cam_config.read()))
    camera.setResolution(VERTICAL_RES, HORIZONTAL_RES)
    camera.setFPS(FPS)
    camera.setBrightness(10)
    camera.setConfigJson("""
{
    "fps": """ + str(FPS) + """,
    "height": """ + str(HORIZONTAL_RES) + """,
    "pixel format": "mjpeg",
    "properties": [
        {
            "name": "brightness",
            "value": 0
        },
        {
            "name": "contrast",
            "value": 100
        },
        {
            "name": "saturation",
            "value": 40
        }
    ],
    "width": """ + str(VERTICAL_RES) + """
}
    """)

    camera.setConnectionStrategy(VideoSource.ConnectionStrategy.kKeepOpen)

    return inst, camera
Exemplo n.º 2
0
def main():
    cs = CameraServer.getInstance()
    cs.enableLogging()

    usb0 = UsbCamera('Camera 0', 0)
    usb0.setFPS(10)
    usb0.setResolution(176, 144)
    usb1 = UsbCamera('Camera 1', 1)
    usb1.setFPS(10)
    usb1.setResolution(176, 144)

    # We "bounce" between these two camera objects using a Command on
    # the robot.
    cams = [usb0, usb1]

    # Add a "Switched" camera opject to Network Tables,
    # and set the source to the first camera (usb0).
    server = cs.addSwitchedCamera('Switched')
    server.setSource(cams[0])
    server.setFPS(10)
    server.setCompression(80)
    server.setResolution(176, 144)


    def _listener(source, key, value, isNew):
        '''Use networktables to switch the camera source.
        We set the camera source to the camera object in the "cams"
        dictionary. We use the bitwise Exclusive Or of "value" to index
        the array (see https://wiki.python.org/moin/BitwiseOperators for
        bit operators).

        "value" MUST be 0 (zero) or 1 (one) in order for this to work
        '''
        # print("cams[int(value)]: value: {} cams: {}".format(int(value), cams[int(value)]))
        # print("usb0: {}   usb1: {}".format(usb0, usb1))
        server.setSource(cams[int(value)])

    table = networktables.NetworkTables.getTable('/CameraPublisher')
    table.putNumber('selected', 0)
    table.addEntryListener(_listener, key='selected')

    cs.waitForever()
Exemplo n.º 3
0
    #Start first camera
    print("Connecting to camera 0")
    cs = CameraServer.getInstance()
    cs.enableLogging()
    Camera = UsbCamera('Cam 0', 0)
    #exp = 2
    #Camera.setExposureManual(exp)
    Camera.setResolution(160,120)
    cs.addCamera(Camera)
    #SmartDashBoardValues.putNumber('ExpAuto', 0)

    print("connected")

    Camera1 = UsbCamera('Cam 1', 1)
    Camera1.setResolution(640, 480)
    Camera1.setFPS(25)
    mjpegServer = MjpegServer("serve_Cam 1", 1182)
    mjpegServer.setResolution(480, 360)
    mjpegServer.setSource(Camera1)

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

    #buffers to store img data
    img = np.zeros(shape=(160,120,3), dtype=np.uint8)
    #ExpStatus = SmartDashBoardValues.getNumber('ExpAuto', 0)
    # loop forever
    loopCount = 0
    #while True:
        # output = ""
        # ExpAuto = SmartDashBoardValues.getNumber('ExpAuto', 0)
Exemplo n.º 4
0
def mainMain():
    #   network tables initialization
    NetworkTables.initialize(server=__IP)
    print("nt initialized")
    smartdash = NetworkTables.getTable("SmartDashboard")
    #    table = NetworkTables.getTable(__SENT_TABLE_NAME)
    #    subtable = smartdash.getSubTable(__ORIENTATION_TABLE_NAME)

    #   initialize cameras
    # CAMERA 1
    cam = UsbCamera('Cam 1 Front', 1)
    cam.setResolution(160, 120)
    cam.setExposureManual(0)
    cam.setBrightness(0)
    cam.setFPS(30)
    print("cam1 initialized")
    # CAMERA 2
    cam2 = UsbCamera('Cam 2 Back', 0)
    cam2.setResolution(160, 120)
    cam2.setExposureManual(0)
    cam2.setBrightness(0)
    cam2.setFPS(30)
    print("cam2 initialized")

    # EACH CAMERA STARTS CAPTURING VIDEO
    cs.startAutomaticCapture(camera=cam)
    cs.startAutomaticCapture(camera=cam2)

    # GETTING THE VIDEO STREAM OF EACH CAMERA
    vid = cs.getVideo(camera=cam)
    vid2 = cs.getVideo(camera=cam2)

    #   initialize outputstream, this is the place where we send frames to shuffleboard.
    output_stream = cs.putVideo('TOP CAMERAS', 160, 120)

    print("Running while loop")
    counter = 0
    while True:
        # get front or back value
        camera_value = subtable.getString("value", "FRONT")

        img = np.zeros(shape=(160, 120, 3), dtype=np.uint8)
        #   get video
        time, frame = video.grabFrame(img, 0.5)

        #   This condition sends video from different cameras based on the robots orientation.
        if camera_value == 'BACK':
            print("BACK")
            video = vid
        elif camera_value == 'FRONT':
            print("FRONT")
            video = vid2
        else:
            print('error, no camera value detected')

        print("sending frame")
        # send frame to shuffleboard
        output_stream.putFrame(frame)

        print('Done.')
        sys.stdout.flush()
        # just counting how fast it is running and if it is running at all
        counter += 1
        print(counter)
Exemplo n.º 5
0
    SmartDashBoardValues.setPersistent("VU")

    #Start camera
    print("Connecting to camera 1SSSS")
    cs = CameraServer.getInstance()
    cs.enableLogging()
    Camera = UsbCamera('Cam 0', 0)
    cs.addCamera(Camera)

    print("connected")

    fps = 60
    width, height = 480, 270

    Camera.setResolution(width, height)
    Camera.setFPS(fps)
    # Camera.getProperty("exposure_auto").set(1)
    Camera.getProperty("brightness").set(5)
    Camera.getProperty("gain").set(0)
    Camera.getProperty("contrast").set(5)
    if camera_number == 1:
        Camera.getProperty("saturation").set(7)
    elif camera_number == 2:
        Camera.getProperty("saturation").set(69)
    Camera.getProperty("exposure_absolute").set(6)

    mjpegServer = MjpegServer("serve_Cam 1", 1182)
    mjpegServer.setResolution(width, height)
    mjpegServer.setSource(Camera)

    CvSink = cs.getVideo()
Exemplo n.º 6
0
        cameras = j["cameras"]
    except KeyError:
        parseError("could not read cameras")
        return False
    for camera in cameras:
        if not readCameraConfig(camera):
            return False

    return True

readConfig()
#Set up the camera
camServer = CameraServer.getInstance()
camServer.enableLogging()
camera = UsbCamera("rPi Camera 0", 0)
camera.setFPS(30)
camera.setResolution(cameraWidth, cameraHeight)
camServer.addCamera(camera)

cvSink = camServer.getVideo()
outputStream = camServer.putVideo("Processed Frames", cameraWidth, cameraHeight)

ntinst = NetworkTablesInstance.getDefault()

print("Setting up NetworkTables client for team {}".format(team))
ntinst.startClientTeam(team)
dashboard = ntinst.getTable('SmartDashboard')

#outputStream = camServer.putVideo("Vision", cameraWidth, cameraHeight)