CameraServer

class cscore.CameraServer[source]

Bases: object

Singleton class for creating and keeping camera servers.

This is a higher level wrapper around the cscore functionality, and also publishes camera information to NetworkTables so that dashboards can easily find and display the camera streams.

addAxisCamera(host, name='Axis Camera')[source]

Adds an Axis IP camera.

Parameters
  • host (Union[str, Sequence[str]]) – Camera host IP/DNS name or list of camera host IPs/DNS names

  • name (str) – The name to give the camera (optional)

Return type

AxisCamera

Returns

Axis camera object

addCamera(camera)[source]

Adds an already created camera.

Parameters

camera (VideoSource) – Camera object

Return type

None

addServer(*, name=None, port=None, server=None)[source]

Adds a MJPEG server

Parameters
  • name – Server name

  • port (Optional[int]) – Port of server (if None, use next available port)

  • server – Server

Return type

MjpegServer

Returns

server object

All arguments must be specified as keyword arguments. The following combinations are accepted:

  • name

  • name, port

  • server

addSwitchedCamera(name)[source]

Adds a virtual camera for switching between two streams. Unlike the other addCamera methods, this returns a VideoSink rather than a VideoSource. Calling setSource() on the returned object can be used to switch the actual source of the stream.

Parameters

name (str) – Name of camera

Return type

MjpegServer

Returns

Server object

static enableLogging(level=20)[source]
classmethod getInstance()[source]

Get the CameraServer instance.

Return type

CameraServer

getServer(name=None)[source]

Get server by name, or for the primary camera feed if no name is specified.

This is only valid to call after a camera feed has been added with startAutomaticCapture() or addServer().

Parameters

name (Optional[str]) – Server name

Return type

VideoSink

Returns

server object

getVideo(*, name=None, camera=None)[source]

Get OpenCV access to specified camera. This allows you to get images from the camera for image processing.

Parameters
  • name – Name of camera to retrieve video for

  • camera – Camera object

Return type

CvSink

Returns

CvSink object corresponding to camera

All arguments must be specified as keyword arguments. The following combinations are permitted:

  • (no args)

  • name

  • camera

If there are no arguments, then this will retrieve access to the primary camera. No arguments will fail if a camera feed has not already been added via startAutomaticCapture() or addCamera()

kBasePort = 1181
kPublishName = '/CameraPublisher'
putVideo(name, width, height)[source]

Create a MJPEG stream with OpenCV input. This can be called to pass custom annotated images to the dashboard.

Parameters
  • name (str) – Name to give the stream

  • width (int) – Width of the image being sent

  • height (int) – Height of the image being sent

Return type

CvSource

Returns

CvSource object that you can publish images to

removeCamera(name)[source]

Removes a camera by name.

Parameters

name (str) – Camera name

Return type

None

removeServer(name)[source]

Removes a server by name.

Parameters

name (str) – Server name

Return type

None

startAutomaticCapture(*, dev=None, name=None, path=None, camera=None, return_server=None)[source]

Start automatically capturing images to send to the dashboard.

You should call this method to see a camera feed on the dashboard. If you also want to perform vision processing on the roboRIO, use getVideo() to get access to the camera images.

Parameters
  • dev – If specified, the device number to use

  • name – If specified, the name to use for the camera (dev must be specified)

  • path – If specified, device path (e.g. “/dev/video0”) of the camera

  • camera – If specified, an existing camera object to use

  • return_server – If specified, return the server instead of the camera

Returns

USB Camera object, or the camera argument, or the created server

Return type

VideoSource or MjpegServer

The following argument combinations are accepted – all arguments must be specified as keyword arguments:

  • (no args)

  • dev

  • dev, name

  • name, path

  • camera

The first time this is called with no arguments, a USB Camera from device 0 is created. Subsequent calls increment the device number (e.g. 1, 2, etc).

Note

USB Cameras are not available on all platforms. If it is not available on your platform, VideoException is thrown

waitForever()[source]

Infinitely loops until the process dies

class cscore.VideoException[source]