WPILibC++ 2024.3.2
CameraServer.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <span>
10#include <string>
11#include <string_view>
12
13#include "cscore.h"
14#include "cscore_cv.h"
15
16namespace frc {
17
18/**
19 * Singleton class for creating and keeping camera servers.
20 *
21 * Also publishes camera information to NetworkTables.
22 */
24 public:
25 /// CameraServer base port.
26 static constexpr uint16_t kBasePort = 1181;
27
28 /**
29 * Start automatically capturing images to send to the dashboard.
30 *
31 * You should call this method to see a camera feed on the dashboard. If you
32 * also want to perform vision processing on the roboRIO, use getVideo() to
33 * get access to the camera images.
34 *
35 * The first time this overload is called, it calls StartAutomaticCapture()
36 * with device 0, creating a camera named "USB Camera 0". Subsequent calls
37 * increment the device number (e.g. 1, 2, etc).
38 */
40
41 /**
42 * Start automatically capturing images to send to the dashboard.
43 *
44 * This overload calls StartAutomaticCapture() with a name of "USB Camera
45 * {dev}".
46 *
47 * @param dev The device number of the camera interface
48 */
50
51 /**
52 * Start automatically capturing images to send to the dashboard.
53 *
54 * @param name The name to give the camera
55 * @param dev The device number of the camera interface
56 */
58
59 /**
60 * Start automatically capturing images to send to the dashboard.
61 *
62 * @param name The name to give the camera
63 * @param path The device path (e.g. "/dev/video0") of the camera
64 */
66 std::string_view path);
67
68 /**
69 * Start automatically capturing images to send to the dashboard from
70 * an existing camera.
71 *
72 * @param camera Camera
73 */
75
76 /**
77 * Adds an Axis IP camera.
78 *
79 * This overload calls AddAxisCamera() with name "Axis Camera".
80 *
81 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
82 */
84
85 /**
86 * Adds an Axis IP camera.
87 *
88 * This overload calls AddAxisCamera() with name "Axis Camera".
89 *
90 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
91 */
92 static cs::AxisCamera AddAxisCamera(const char* host);
93
94 /**
95 * Adds an Axis IP camera.
96 *
97 * This overload calls AddAxisCamera() with name "Axis Camera".
98 *
99 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
100 */
101 static cs::AxisCamera AddAxisCamera(const std::string& host);
102
103 /**
104 * Adds an Axis IP camera.
105 *
106 * This overload calls AddAxisCamera() with name "Axis Camera".
107 *
108 * @param hosts Array of Camera host IPs/DNS names
109 */
110 static cs::AxisCamera AddAxisCamera(std::span<const std::string> hosts);
111
112 /**
113 * Adds an Axis IP camera.
114 *
115 * This overload calls AddAxisCamera() with name "Axis Camera".
116 *
117 * @param hosts Array of Camera host IPs/DNS names
118 */
119 template <typename T>
120 static cs::AxisCamera AddAxisCamera(std::initializer_list<T> hosts);
121
122 /**
123 * Adds an Axis IP camera.
124 *
125 * @param name The name to give the camera
126 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
127 */
129 std::string_view host);
130
131 /**
132 * Adds an Axis IP camera.
133 *
134 * @param name The name to give the camera
135 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
136 */
137 static cs::AxisCamera AddAxisCamera(std::string_view name, const char* host);
138
139 /**
140 * Adds an Axis IP camera.
141 *
142 * @param name The name to give the camera
143 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
144 */
146 const std::string& host);
147
148 /**
149 * Adds an Axis IP camera.
150 *
151 * @param name The name to give the camera
152 * @param hosts Array of Camera host IPs/DNS names
153 */
155 std::span<const std::string> hosts);
156
157 /**
158 * Adds an Axis IP camera.
159 *
160 * @param name The name to give the camera
161 * @param hosts Array of Camera host IPs/DNS names
162 */
163 template <typename T>
165 std::initializer_list<T> hosts);
166
167 /**
168 * Adds a virtual camera for switching between two streams. Unlike the
169 * other addCamera methods, this returns a VideoSink rather than a
170 * VideoSource. Calling SetSource() on the returned object can be used
171 * to switch the actual source of the stream.
172 */
174
175 /**
176 * Get OpenCV access to the primary camera feed. This allows you to
177 * get images from the camera for image processing on the roboRIO.
178 *
179 * <p>This is only valid to call after a camera feed has been added
180 * with startAutomaticCapture() or addServer().
181 */
183
184 /**
185 * Get OpenCV access to the specified camera. This allows you to get
186 * images from the camera for image processing on the roboRIO.
187 *
188 * @param camera Camera (e.g. as returned by startAutomaticCapture).
189 */
190 static cs::CvSink GetVideo(const cs::VideoSource& camera);
191
192 /**
193 * Get OpenCV access to the specified camera. This allows you to get
194 * images from the camera for image processing on the roboRIO.
195 *
196 * @param camera Camera (e.g. as returned by startAutomaticCapture).
197 * @param pixelFormat The desired pixelFormat of captured frames from the
198 * camera
199 */
200 static cs::CvSink GetVideo(const cs::VideoSource& camera,
201 cs::VideoMode::PixelFormat pixelFormat);
202
203 /**
204 * Get OpenCV access to the specified camera. This allows you to get
205 * images from the camera for image processing on the roboRIO.
206 *
207 * @param name Camera name
208 */
210
211 /**
212 * Get OpenCV access to the specified camera. This allows you to get
213 * images from the camera for image processing on the roboRIO.
214 *
215 * @param name Camera name
216 * @param pixelFormat The desired pixelFormat of captured frames from the
217 * camera
218 */
220 cs::VideoMode::PixelFormat pixelFormat);
221
222 /**
223 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
224 * annotated images to the dashboard.
225 *
226 * @param name Name to give the stream
227 * @param width Width of the image being sent
228 * @param height Height of the image being sent
229 */
230 static cs::CvSource PutVideo(std::string_view name, int width, int height);
231
232 /**
233 * Adds a MJPEG server at the next available port.
234 *
235 * @param name Server name
236 */
238
239 /**
240 * Adds a MJPEG server.
241 *
242 * @param name Server name
243 * @param port Port number
244 */
246
247 /**
248 * Adds an already created server.
249 *
250 * @param server Server
251 */
252 static void AddServer(const cs::VideoSink& server);
253
254 /**
255 * Removes a server by name.
256 *
257 * @param name Server name
258 */
260
261 /**
262 * Get server for the primary camera feed.
263 *
264 * This is only valid to call after a camera feed has been added with
265 * StartAutomaticCapture() or AddServer().
266 */
268
269 /**
270 * Gets a server by name.
271 *
272 * @param name Server name
273 */
275
276 /**
277 * Adds an already created camera.
278 *
279 * @param camera Camera
280 */
281 static void AddCamera(const cs::VideoSource& camera);
282
283 /**
284 * Removes a camera by name.
285 *
286 * @param name Camera name
287 */
289
290 private:
291 CameraServer() = default;
292};
293
294} // namespace frc
295
A source that represents an Axis IP camera.
Definition: cscore_oo.h:694
A sink for user code to accept video frames as OpenCV images.
Definition: cscore_cv.h:119
A source for user code to provide OpenCV images as video frames.
Definition: cscore_cv.h:77
A sink that acts as a MJPEG-over-HTTP network server.
Definition: cscore_oo.h:1009
A source that represents a USB camera.
Definition: cscore_oo.h:546
A sink for video that accepts a sequence of frames.
Definition: cscore_oo.h:848
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:208
Singleton class for creating and keeping camera servers.
Definition: CameraServer.h:23
static cs::UsbCamera StartAutomaticCapture()
Start automatically capturing images to send to the dashboard.
static cs::MjpegServer StartAutomaticCapture(const cs::VideoSource &camera)
Start automatically capturing images to send to the dashboard from an existing camera.
static cs::MjpegServer AddServer(std::string_view name, int port)
Adds a MJPEG server.
static cs::AxisCamera AddAxisCamera(std::string_view name, std::string_view host)
Adds an Axis IP camera.
static cs::CvSource PutVideo(std::string_view name, int width, int height)
Create a MJPEG stream with OpenCV input.
static void AddServer(const cs::VideoSink &server)
Adds an already created server.
static cs::MjpegServer AddServer(std::string_view name)
Adds a MJPEG server at the next available port.
static cs::AxisCamera AddAxisCamera(std::string_view name, const std::string &host)
Adds an Axis IP camera.
static cs::MjpegServer AddSwitchedCamera(std::string_view name)
Adds a virtual camera for switching between two streams.
static cs::VideoSink GetServer(std::string_view name)
Gets a server by name.
static cs::CvSink GetVideo(const cs::VideoSource &camera)
Get OpenCV access to the specified camera.
static cs::AxisCamera AddAxisCamera(std::string_view name, const char *host)
Adds an Axis IP camera.
static cs::AxisCamera AddAxisCamera(const char *host)
Adds an Axis IP camera.
static void RemoveCamera(std::string_view name)
Removes a camera by name.
static constexpr uint16_t kBasePort
CameraServer base port.
Definition: CameraServer.h:26
static cs::CvSink GetVideo(std::string_view name, cs::VideoMode::PixelFormat pixelFormat)
Get OpenCV access to the specified camera.
static cs::UsbCamera StartAutomaticCapture(int dev)
Start automatically capturing images to send to the dashboard.
static cs::UsbCamera StartAutomaticCapture(std::string_view name, std::string_view path)
Start automatically capturing images to send to the dashboard.
static cs::AxisCamera AddAxisCamera(std::span< const std::string > hosts)
Adds an Axis IP camera.
static void RemoveServer(std::string_view name)
Removes a server by name.
static void AddCamera(const cs::VideoSource &camera)
Adds an already created camera.
static cs::AxisCamera AddAxisCamera(std::string_view name, std::span< const std::string > hosts)
Adds an Axis IP camera.
static cs::CvSink GetVideo(const cs::VideoSource &camera, cs::VideoMode::PixelFormat pixelFormat)
Get OpenCV access to the specified camera.
static cs::UsbCamera StartAutomaticCapture(std::string_view name, int dev)
Start automatically capturing images to send to the dashboard.
static cs::CvSink GetVideo()
Get OpenCV access to the primary camera feed.
static cs::AxisCamera AddAxisCamera(const std::string &host)
Adds an Axis IP camera.
static cs::VideoSink GetServer()
Get server for the primary camera feed.
static cs::AxisCamera AddAxisCamera(std::string_view host)
Adds an Axis IP camera.
static cs::CvSink GetVideo(std::string_view name)
Get OpenCV access to the specified camera.
basic_string_view< char > string_view
Definition: core.h:501
Definition: AprilTagPoseEstimator.h:15
PixelFormat
Definition: cscore_cpp.h:63