WPILibC++ 2024.1.1-beta-4
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 static constexpr uint16_t kBasePort = 1181;
26 static constexpr int kSize640x480 = 0;
27 static constexpr int kSize320x240 = 1;
28 static constexpr int kSize160x120 = 2;
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 */
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 */
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
78 /**
79 * Adds an Axis IP camera.
80 *
81 * This overload calls AddAxisCamera() with name "Axis Camera".
82 *
83 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
84 */
86
87 /**
88 * Adds an Axis IP camera.
89 *
90 * This overload calls AddAxisCamera() with name "Axis Camera".
91 *
92 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
93 */
94 static cs::AxisCamera AddAxisCamera(const char* host);
95
96 /**
97 * Adds an Axis IP camera.
98 *
99 * This overload calls AddAxisCamera() with name "Axis Camera".
100 *
101 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
102 */
103 static cs::AxisCamera AddAxisCamera(const std::string& host);
104
105 /**
106 * Adds an Axis IP camera.
107 *
108 * This overload calls AddAxisCamera() with name "Axis Camera".
109 *
110 * @param hosts Array of Camera host IPs/DNS names
111 */
112 static cs::AxisCamera AddAxisCamera(std::span<const std::string> hosts);
113
114 /**
115 * Adds an Axis IP camera.
116 *
117 * This overload calls AddAxisCamera() with name "Axis Camera".
118 *
119 * @param hosts Array of Camera host IPs/DNS names
120 */
121 template <typename T>
122 static cs::AxisCamera AddAxisCamera(std::initializer_list<T> hosts);
123
124 /**
125 * Adds an Axis IP camera.
126 *
127 * @param name The name to give the camera
128 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
129 */
131 std::string_view host);
132
133 /**
134 * Adds an Axis IP camera.
135 *
136 * @param name The name to give the camera
137 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
138 */
139 static cs::AxisCamera AddAxisCamera(std::string_view name, const char* host);
140
141 /**
142 * Adds an Axis IP camera.
143 *
144 * @param name The name to give the camera
145 * @param host Camera host IP or DNS name (e.g. "10.x.y.11")
146 */
148 const std::string& host);
149
150 /**
151 * Adds an Axis IP camera.
152 *
153 * @param name The name to give the camera
154 * @param hosts Array of Camera host IPs/DNS names
155 */
157 std::span<const std::string> hosts);
158
159 /**
160 * Adds an Axis IP camera.
161 *
162 * @param name The name to give the camera
163 * @param hosts Array of Camera host IPs/DNS names
164 */
165 template <typename T>
167 std::initializer_list<T> hosts);
168
169 /**
170 * Adds a virtual camera for switching between two streams. Unlike the
171 * other addCamera methods, this returns a VideoSink rather than a
172 * VideoSource. Calling SetSource() on the returned object can be used
173 * to switch the actual source of the stream.
174 */
176
177 /**
178 * Get OpenCV access to the primary camera feed. This allows you to
179 * get images from the camera for image processing on the roboRIO.
180 *
181 * <p>This is only valid to call after a camera feed has been added
182 * with startAutomaticCapture() or addServer().
183 */
185
186 /**
187 * Get OpenCV access to the specified camera. This allows you to get
188 * images from the camera for image processing on the roboRIO.
189 *
190 * @param camera Camera (e.g. as returned by startAutomaticCapture).
191 */
192 static cs::CvSink GetVideo(const cs::VideoSource& camera);
193
194 /**
195 * Get OpenCV access to the specified camera. This allows you to get
196 * images from the camera for image processing on the roboRIO.
197 *
198 * @param camera Camera (e.g. as returned by startAutomaticCapture).
199 * @param pixelFormat The desired pixelFormat of captured frames from the
200 * camera
201 */
202 static cs::CvSink GetVideo(const cs::VideoSource& camera,
203 cs::VideoMode::PixelFormat pixelFormat);
204
205 /**
206 * Get OpenCV access to the specified camera. This allows you to get
207 * images from the camera for image processing on the roboRIO.
208 *
209 * @param name Camera name
210 */
212
213 /**
214 * Get OpenCV access to the specified camera. This allows you to get
215 * images from the camera for image processing on the roboRIO.
216 *
217 * @param name Camera name
218 * @param pixelFormat The desired pixelFormat of captured frames from the
219 * camera
220 */
222 cs::VideoMode::PixelFormat pixelFormat);
223
224 /**
225 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
226 * annotated images to the dashboard.
227 *
228 * @param name Name to give the stream
229 * @param width Width of the image being sent
230 * @param height Height of the image being sent
231 */
232 static cs::CvSource PutVideo(std::string_view name, int width, int height);
233
234 /**
235 * Adds a MJPEG server at the next available port.
236 *
237 * @param name Server name
238 */
240
241 /**
242 * Adds a MJPEG server.
243 *
244 * @param name Server name
245 * @param port Port number
246 */
248
249 /**
250 * Adds an already created server.
251 *
252 * @param server Server
253 */
254 static void AddServer(const cs::VideoSink& server);
255
256 /**
257 * Removes a server by name.
258 *
259 * @param name Server name
260 */
262
263 /**
264 * Get server for the primary camera feed.
265 *
266 * This is only valid to call after a camera feed has been added with
267 * StartAutomaticCapture() or AddServer().
268 */
270
271 /**
272 * Gets a server by name.
273 *
274 * @param name Server name
275 */
277
278 /**
279 * Adds an already created camera.
280 *
281 * @param camera Camera
282 */
283 static void AddCamera(const cs::VideoSource& camera);
284
285 /**
286 * Removes a camera by name.
287 *
288 * @param name Camera name
289 */
291
292 private:
293 CameraServer() = default;
294};
295
296} // namespace frc
297
A source that represents an Axis IP camera.
Definition: cscore_oo.h:559
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:861
A source that represents a USB camera.
Definition: cscore_oo.h:418
A sink for video that accepts a sequence of frames.
Definition: cscore_oo.h:713
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97
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
Definition: CameraServer.h:25
static constexpr int kSize320x240
Definition: CameraServer.h:27
static constexpr int kSize160x120
Definition: CameraServer.h:28
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 constexpr int kSize640x480
Definition: CameraServer.h:26
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