WPILibC++ 2023.4.3-108-ge5452e3
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 name Camera name
199 */
201
202 /**
203 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
204 * annotated images to the dashboard.
205 *
206 * @param name Name to give the stream
207 * @param width Width of the image being sent
208 * @param height Height of the image being sent
209 */
210 static cs::CvSource PutVideo(std::string_view name, int width, int height);
211
212 /**
213 * Adds a MJPEG server at the next available port.
214 *
215 * @param name Server name
216 */
218
219 /**
220 * Adds a MJPEG server.
221 *
222 * @param name Server name
223 * @param port Port number
224 */
226
227 /**
228 * Adds an already created server.
229 *
230 * @param server Server
231 */
232 static void AddServer(const cs::VideoSink& server);
233
234 /**
235 * Removes a server by name.
236 *
237 * @param name Server name
238 */
240
241 /**
242 * Get server for the primary camera feed.
243 *
244 * This is only valid to call after a camera feed has been added with
245 * StartAutomaticCapture() or AddServer().
246 */
248
249 /**
250 * Gets a server by name.
251 *
252 * @param name Server name
253 */
255
256 /**
257 * Adds an already created camera.
258 *
259 * @param camera Camera
260 */
261 static void AddCamera(const cs::VideoSource& camera);
262
263 /**
264 * Removes a camera by name.
265 *
266 * @param name Camera name
267 */
269
270 /**
271 * Sets the size of the image to use. Use the public kSize constants to set
272 * the correct mode, or set it directly on a camera and call the appropriate
273 * StartAutomaticCapture method.
274 *
275 * @deprecated Use SetResolution on the UsbCamera returned by
276 * StartAutomaticCapture() instead.
277 * @param size The size to use
278 */
279 static void SetSize(int size);
280
281 private:
282 CameraServer() = default;
283};
284
285} // namespace frc
286
A source that represents an Axis IP camera.
Definition: cscore_oo.h:558
A sink for user code to accept video frames as OpenCV images.
Definition: cscore_cv.h:117
A source for user code to provide OpenCV images as video frames.
Definition: cscore_cv.h:75
A sink that acts as a MJPEG-over-HTTP network server.
Definition: cscore_oo.h:860
A source that represents a USB camera.
Definition: cscore_oo.h:417
A sink for video that accepts a sequence of frames.
Definition: cscore_oo.h:712
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:96
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 void SetSize(int size)
Sets the size of the image to use.
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::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:520
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
::uint16_t uint16_t
Definition: Meta.h:54
Definition: AprilTagPoseEstimator.h:15