CameraServer¶
- class cscore.CameraServer[source]¶
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 namesname (
str
) – The name to give the camera (optional)
- Return type
- Returns
Axis camera object
- addCamera(camera)[source]¶
Adds an already created camera.
- Parameters
camera (
VideoSource
) – Camera object- Return type
None
- addServer(*, name: str, port: Optional[int] = 'None') cscore.MjpegServer [source]¶
- addServer(*, server: cscore.VideoSink) cscore.MjpegServer
Adds a MJPEG server
- Parameters
name – Server name
port (
Optional
[int
]) – Port of server (if None, use next available port)server – Server
- Return type
- 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
- Returns
Server object
- 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()
oraddServer()
.- Parameters
name (
Optional
[str
]) – Server name- Return type
- Returns
server object
- getVideo() cscore.CvSink [source]¶
- getVideo(*, name: str) cscore.CvSink
- getVideo(*, camera: cscore.VideoSource) cscore.CvSink
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
- 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()
oraddCamera()
- 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 streamwidth (
int
) – Width of the image being sentheight (
int
) – Height of the image being sent
- Return type
- 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(*, return_server: bool = 'False') Union[cscore.UsbCamera, cscore.MjpegServer] [source]¶
- startAutomaticCapture(*, dev: int, name: Optional[str] = 'None', return_server: bool = 'False') Union[cscore.UsbCamera, cscore.MjpegServer]
- startAutomaticCapture(*, name: str, path: str, return_server: bool = 'False') Union[cscore.UsbCamera, cscore.MjpegServer]
- startAutomaticCapture(*, camera: cscore.VideoSource, return_server: bool = 'False') Union[cscore.VideoSource, cscore.MjpegServer]
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
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