WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
CameraServer.hpp
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 <string_view>
10
11#include "wpi/cs/CvSink.hpp"
12#include "wpi/cs/CvSource.hpp"
14#include "wpi/cs/UsbCamera.hpp"
16
17namespace wpi {
18
19/**
20 * Singleton class for creating and keeping camera servers.
21 *
22 * Also publishes camera information to NetworkTables.
23 */
24class CameraServer {
25 public:
26 /// CameraServer base port.
27 static constexpr uint16_t kBasePort = 1181;
28
29 /**
30 * Start automatically capturing images to send to the dashboard.
31 *
32 * You should call this method to see a camera feed on the dashboard. If you
33 * also want to perform vision processing on the roboRIO, use getVideo() to
34 * get access to the camera images.
35 *
36 * The first time this overload is called, it calls StartAutomaticCapture()
37 * with device 0, creating a camera named "USB Camera 0". Subsequent calls
38 * increment the device number (e.g. 1, 2, etc).
39 */
41
42 /**
43 * Start automatically capturing images to send to the dashboard.
44 *
45 * This overload calls StartAutomaticCapture() with a name of "USB Camera
46 * {dev}".
47 *
48 * @param dev The device number of the camera interface
49 */
51
52 /**
53 * Start automatically capturing images to send to the dashboard.
54 *
55 * @param name The name to give the camera
56 * @param dev The device number of the camera interface
57 */
58 static cs::UsbCamera StartAutomaticCapture(std::string_view name, int dev);
59
60 /**
61 * Start automatically capturing images to send to the dashboard.
62 *
63 * @param name The name to give the camera
64 * @param path The device path (e.g. "/dev/video0") of the camera
65 */
66 static cs::UsbCamera StartAutomaticCapture(std::string_view name,
67 std::string_view path);
68
69 /**
70 * Start automatically capturing images to send to the dashboard from
71 * an existing camera.
72 *
73 * @param camera Camera
74 */
76
77 /**
78 * Adds a virtual camera for switching between two streams. Unlike the
79 * other addCamera methods, this returns a VideoSink rather than a
80 * VideoSource. Calling SetSource() on the returned object can be used
81 * to switch the actual source of the stream.
82 */
83 static cs::MjpegServer AddSwitchedCamera(std::string_view name);
84
85 /**
86 * Get OpenCV access to the primary camera feed. This allows you to
87 * get images from the camera for image processing on the roboRIO.
88 *
89 * <p>This is only valid to call after a camera feed has been added
90 * with startAutomaticCapture() or addServer().
91 */
93
94 /**
95 * Get OpenCV access to the specified camera. This allows you to get
96 * images from the camera for image processing on the roboRIO.
97 *
98 * @param camera Camera (e.g. as returned by startAutomaticCapture).
99 */
100 static cs::CvSink GetVideo(const cs::VideoSource& camera);
101
102 /**
103 * Get OpenCV access to the specified camera. This allows you to get
104 * images from the camera for image processing on the roboRIO.
105 *
106 * @param camera Camera (e.g. as returned by startAutomaticCapture).
107 * @param pixelFormat The desired pixelFormat of captured frames from the
108 * camera
109 */
110 static cs::CvSink GetVideo(const cs::VideoSource& camera,
111 wpi::util::PixelFormat pixelFormat);
112
113 /**
114 * Get OpenCV access to the specified camera. This allows you to get
115 * images from the camera for image processing on the roboRIO.
116 *
117 * @param name Camera name
118 */
119 static cs::CvSink GetVideo(std::string_view name);
120
121 /**
122 * Get OpenCV access to the specified camera. This allows you to get
123 * images from the camera for image processing on the roboRIO.
124 *
125 * @param name Camera name
126 * @param pixelFormat The desired pixelFormat of captured frames from the
127 * camera
128 */
129 static cs::CvSink GetVideo(std::string_view name,
130 wpi::util::PixelFormat pixelFormat);
131
132 /**
133 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
134 * annotated images to the dashboard.
135 *
136 * @param name Name to give the stream
137 * @param width Width of the image being sent
138 * @param height Height of the image being sent
139 */
140 static cs::CvSource PutVideo(std::string_view name, int width, int height);
141
142 /**
143 * Adds a MJPEG server at the next available port.
144 *
145 * @param name Server name
146 */
147 static cs::MjpegServer AddServer(std::string_view name);
148
149 /**
150 * Adds a MJPEG server.
151 *
152 * @param name Server name
153 * @param port Port number
154 */
155 static cs::MjpegServer AddServer(std::string_view name, int port);
156
157 /**
158 * Adds an already created server.
159 *
160 * @param server Server
161 */
162 static void AddServer(const cs::VideoSink& server);
163
164 /**
165 * Removes a server by name.
166 *
167 * @param name Server name
168 */
169 static void RemoveServer(std::string_view name);
170
171 /**
172 * Get server for the primary camera feed.
173 *
174 * This is only valid to call after a camera feed has been added with
175 * StartAutomaticCapture() or AddServer().
176 */
178
179 /**
180 * Gets a server by name.
181 *
182 * @param name Server name
183 */
184 static cs::VideoSink GetServer(std::string_view name);
185
186 /**
187 * Adds an already created camera.
188 *
189 * @param camera Camera
190 */
191 static void AddCamera(const cs::VideoSource& camera);
192
193 /**
194 * Removes a camera by name.
195 *
196 * @param name Camera name
197 */
198 static void RemoveCamera(std::string_view name);
199
200 private:
201 CameraServer() = default;
202};
203
204} // namespace wpi
@ name
Definition base.h:690
static cs::MjpegServer StartAutomaticCapture(const cs::VideoSource &camera)
Start automatically capturing images to send to the dashboard from an existing camera.
static cs::CvSource PutVideo(std::string_view name, int width, int height)
Create a MJPEG stream with OpenCV input.
static cs::CvSink GetVideo(std::string_view name)
Get OpenCV access to the specified camera.
static cs::VideoSink GetServer()
Get server for the primary camera feed.
static void RemoveCamera(std::string_view name)
Removes a camera by name.
static cs::UsbCamera StartAutomaticCapture(int dev)
Start automatically capturing images to send to the dashboard.
static cs::CvSink GetVideo(std::string_view name, wpi::util::PixelFormat pixelFormat)
Get OpenCV access to the specified camera.
static cs::CvSink GetVideo()
Get OpenCV access to the primary camera feed.
static cs::UsbCamera StartAutomaticCapture()
Start automatically capturing images to send to the dashboard.
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::CvSink GetVideo(const cs::VideoSource &camera, wpi::util::PixelFormat pixelFormat)
Get OpenCV access to the specified 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 constexpr uint16_t kBasePort
CameraServer base port.
Definition CameraServer.hpp:27
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::UsbCamera StartAutomaticCapture(std::string_view name, std::string_view path)
Start automatically capturing images to send to the dashboard.
static cs::UsbCamera StartAutomaticCapture(std::string_view name, int dev)
Start automatically capturing images to send to the dashboard.
static cs::MjpegServer AddServer(std::string_view name, int port)
Adds a MJPEG server.
static cs::CvSink GetVideo(const cs::VideoSource &camera)
Get OpenCV access to the specified camera.
A sink for user code to accept video frames as OpenCV images.
Definition CvSink.hpp:26
A source for user code to provide OpenCV images as video frames.
Definition CvSource.hpp:23
A sink that acts as a MJPEG-over-HTTP network server.
Definition MjpegServer.hpp:18
A source that represents a USB camera.
Definition UsbCamera.hpp:19
A sink for video that accepts a sequence of frames.
Definition VideoSink.hpp:24
A source for video that provides a sequence of frames.
Definition VideoSource.hpp:25
PixelFormat
Pixel formats.
Definition PixelFormat.hpp:14
Definition CvSource.hpp:15