WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
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#include <vector>
13
14#include <wpi/deprecated.h>
15
16#include "cscore_cv.h"
17
18namespace frc {
19
20/**
21 * Singleton class for creating and keeping camera servers.
22 *
23 * Also publishes camera information to NetworkTables.
24 */
26 public:
27 /// CameraServer base port.
28 static constexpr uint16_t kBasePort = 1181;
29
30 /**
31 * Start automatically capturing images to send to the dashboard.
32 *
33 * You should call this method to see a camera feed on the dashboard. If you
34 * also want to perform vision processing on the roboRIO, use getVideo() to
35 * get access to the camera images.
36 *
37 * The first time this overload is called, it calls StartAutomaticCapture()
38 * with device 0, creating a camera named "USB Camera 0". Subsequent calls
39 * increment the device number (e.g. 1, 2, etc).
40 */
42
43 /**
44 * Start automatically capturing images to send to the dashboard.
45 *
46 * This overload calls StartAutomaticCapture() with a name of "USB Camera
47 * {dev}".
48 *
49 * @param dev The device number of the camera interface
50 */
52
53 /**
54 * Start automatically capturing images to send to the dashboard.
55 *
56 * @param name The name to give the camera
57 * @param dev The device number of the camera interface
58 */
59 static cs::UsbCamera StartAutomaticCapture(std::string_view name, int dev);
60
61 /**
62 * Start automatically capturing images to send to the dashboard.
63 *
64 * @param name The name to give the camera
65 * @param path The device path (e.g. "/dev/video0") of the camera
66 */
67 static cs::UsbCamera StartAutomaticCapture(std::string_view name,
68 std::string_view path);
69
70 /**
71 * Start automatically capturing images to send to the dashboard from
72 * an existing camera.
73 *
74 * @param camera Camera
75 */
77
79 /**
80 * Adds an Axis IP camera.
81 *
82 * This overload calls AddAxisCamera() with name "Axis Camera".
83 *
84 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
85 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
86 */
87 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
88 static cs::AxisCamera AddAxisCamera(std::string_view host);
89
90 /**
91 * Adds an Axis IP camera.
92 *
93 * This overload calls AddAxisCamera() with name "Axis Camera".
94 *
95 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
96 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
97 */
98 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
99 static cs::AxisCamera AddAxisCamera(const char* host);
100
101 /**
102 * Adds an Axis IP camera.
103 *
104 * This overload calls AddAxisCamera() with name "Axis Camera".
105 *
106 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
107 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
108 */
109 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
110 static cs::AxisCamera AddAxisCamera(const std::string& host);
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 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
119 */
120 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
121 static cs::AxisCamera AddAxisCamera(std::span<const std::string> hosts);
122
123 /**
124 * Adds an Axis IP camera.
125 *
126 * This overload calls AddAxisCamera() with name "Axis Camera".
127 *
128 * @param hosts Array of Camera host IPs/DNS names
129 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
130 */
131 template <typename T>
132 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
133 static cs::AxisCamera AddAxisCamera(std::initializer_list<T> hosts) {
134 return AddAxisCamera("Axis Camera", hosts);
135 }
136
137 /**
138 * Adds an Axis IP camera.
139 *
140 * @param name The name to give the camera
141 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
142 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
143 */
144 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
145 static cs::AxisCamera AddAxisCamera(std::string_view name,
146 std::string_view host);
147
148 /**
149 * Adds an Axis IP camera.
150 *
151 * @param name The name to give the camera
152 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
153 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
154 */
155 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
156 static cs::AxisCamera AddAxisCamera(std::string_view name, const char* host);
157
158 /**
159 * Adds an Axis IP camera.
160 *
161 * @param name The name to give the camera
162 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
163 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
164 */
165 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
166 static cs::AxisCamera AddAxisCamera(std::string_view name,
167 const std::string& host);
168
169 /**
170 * Adds an Axis IP camera.
171 *
172 * @param name The name to give the camera
173 * @param hosts Array of Camera host IPs/DNS names
174 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
175 */
176 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
177 static cs::AxisCamera AddAxisCamera(std::string_view name,
178 std::span<const std::string> hosts);
179
180 /**
181 * Adds an Axis IP camera.
182 *
183 * @param name The name to give the camera
184 * @param hosts Array of Camera host IPs/DNS names
185 * @deprecated Call StartAutomaticCapture with a HttpCamera instead.
186 */
187 template <typename T>
188 [[deprecated("Call StartAutomaticCapture with a HttpCamera instead.")]]
189 static cs::AxisCamera AddAxisCamera(std::string_view name,
190 std::initializer_list<T> hosts) {
191 std::vector<std::string> vec;
192 vec.reserve(hosts.size());
193 for (const auto& host : hosts) {
194 vec.emplace_back(host);
195 }
196 return AddAxisCamera(name, vec);
197 }
199
200 /**
201 * Adds a virtual camera for switching between two streams. Unlike the
202 * other addCamera methods, this returns a VideoSink rather than a
203 * VideoSource. Calling SetSource() on the returned object can be used
204 * to switch the actual source of the stream.
205 */
206 static cs::MjpegServer AddSwitchedCamera(std::string_view name);
207
208 /**
209 * Get OpenCV access to the primary camera feed. This allows you to
210 * get images from the camera for image processing on the roboRIO.
211 *
212 * <p>This is only valid to call after a camera feed has been added
213 * with startAutomaticCapture() or addServer().
214 */
216
217 /**
218 * Get OpenCV access to the specified camera. This allows you to get
219 * images from the camera for image processing on the roboRIO.
220 *
221 * @param camera Camera (e.g. as returned by startAutomaticCapture).
222 */
223 static cs::CvSink GetVideo(const cs::VideoSource& camera);
224
225 /**
226 * Get OpenCV access to the specified camera. This allows you to get
227 * images from the camera for image processing on the roboRIO.
228 *
229 * @param camera Camera (e.g. as returned by startAutomaticCapture).
230 * @param pixelFormat The desired pixelFormat of captured frames from the
231 * camera
232 */
233 static cs::CvSink GetVideo(const cs::VideoSource& camera,
234 cs::VideoMode::PixelFormat pixelFormat);
235
236 /**
237 * Get OpenCV access to the specified camera. This allows you to get
238 * images from the camera for image processing on the roboRIO.
239 *
240 * @param name Camera name
241 */
242 static cs::CvSink GetVideo(std::string_view name);
243
244 /**
245 * Get OpenCV access to the specified camera. This allows you to get
246 * images from the camera for image processing on the roboRIO.
247 *
248 * @param name Camera name
249 * @param pixelFormat The desired pixelFormat of captured frames from the
250 * camera
251 */
252 static cs::CvSink GetVideo(std::string_view name,
253 cs::VideoMode::PixelFormat pixelFormat);
254
255 /**
256 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
257 * annotated images to the dashboard.
258 *
259 * @param name Name to give the stream
260 * @param width Width of the image being sent
261 * @param height Height of the image being sent
262 */
263 static cs::CvSource PutVideo(std::string_view name, int width, int height);
264
265 /**
266 * Adds a MJPEG server at the next available port.
267 *
268 * @param name Server name
269 */
270 static cs::MjpegServer AddServer(std::string_view name);
271
272 /**
273 * Adds a MJPEG server.
274 *
275 * @param name Server name
276 * @param port Port number
277 */
278 static cs::MjpegServer AddServer(std::string_view name, int port);
279
280 /**
281 * Adds an already created server.
282 *
283 * @param server Server
284 */
285 static void AddServer(const cs::VideoSink& server);
286
287 /**
288 * Removes a server by name.
289 *
290 * @param name Server name
291 */
292 static void RemoveServer(std::string_view name);
293
294 /**
295 * Get server for the primary camera feed.
296 *
297 * This is only valid to call after a camera feed has been added with
298 * StartAutomaticCapture() or AddServer().
299 */
301
302 /**
303 * Gets a server by name.
304 *
305 * @param name Server name
306 */
307 static cs::VideoSink GetServer(std::string_view name);
308
309 /**
310 * Adds an already created camera.
311 *
312 * @param camera Camera
313 */
314 static void AddCamera(const cs::VideoSource& camera);
315
316 /**
317 * Removes a camera by name.
318 *
319 * @param name Camera name
320 */
321 static void RemoveCamera(std::string_view name);
322
323 private:
324 CameraServer() = default;
325};
326
327} // namespace frc
A source that represents an Axis IP camera.
Definition cscore_oo.h:910
A source for user code to accept video frames as OpenCV images.
Definition cscore_cv.h:86
A source for user code to provide OpenCV images as video frames.
Definition cscore_cv.h:23
A sink that acts as a MJPEG-over-HTTP network server.
Definition cscore_oo.h:1346
A source that represents a USB camera.
Definition cscore_oo.h:700
A sink for video that accepts a sequence of frames.
Definition cscore_oo.h:1135
A source for video that provides a sequence of frames.
Definition cscore_oo.h:253
Singleton class for creating and keeping camera servers.
Definition CameraServer.h:25
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 WPI_UNIGNORE_DEPRECATED 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 WPI_IGNORE_DEPRECATED cs::AxisCamera AddAxisCamera(std::string_view 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 cs::AxisCamera AddAxisCamera(std::string_view name, std::initializer_list< T > hosts)
Adds an Axis IP camera.
Definition CameraServer.h:189
static constexpr uint16_t kBasePort
CameraServer base port.
Definition CameraServer.h:28
static cs::AxisCamera AddAxisCamera(std::initializer_list< T > hosts)
Adds an Axis IP camera.
Definition CameraServer.h:133
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::CvSink GetVideo(std::string_view name)
Get OpenCV access to the specified camera.
#define WPI_IGNORE_DEPRECATED
Definition deprecated.h:16
#define WPI_UNIGNORE_DEPRECATED
Definition deprecated.h:27
Definition CAN.h:11
PixelFormat
Definition cscore_cpp.h:63