WPILibC++ 2027.0.0-alpha-2
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 "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 */
57 static cs::UsbCamera StartAutomaticCapture(std::string_view name, int dev);
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 */
65 static cs::UsbCamera StartAutomaticCapture(std::string_view name,
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 a virtual camera for switching between two streams. Unlike the
78 * other addCamera methods, this returns a VideoSink rather than a
79 * VideoSource. Calling SetSource() on the returned object can be used
80 * to switch the actual source of the stream.
81 */
82 static cs::MjpegServer AddSwitchedCamera(std::string_view name);
83
84 /**
85 * Get OpenCV access to the primary camera feed. This allows you to
86 * get images from the camera for image processing on the roboRIO.
87 *
88 * <p>This is only valid to call after a camera feed has been added
89 * with startAutomaticCapture() or addServer().
90 */
92
93 /**
94 * Get OpenCV access to the specified camera. This allows you to get
95 * images from the camera for image processing on the roboRIO.
96 *
97 * @param camera Camera (e.g. as returned by startAutomaticCapture).
98 */
99 static cs::CvSink GetVideo(const cs::VideoSource& camera);
100
101 /**
102 * Get OpenCV access to the specified camera. This allows you to get
103 * images from the camera for image processing on the roboRIO.
104 *
105 * @param camera Camera (e.g. as returned by startAutomaticCapture).
106 * @param pixelFormat The desired pixelFormat of captured frames from the
107 * camera
108 */
109 static cs::CvSink GetVideo(const cs::VideoSource& camera,
110 cs::VideoMode::PixelFormat pixelFormat);
111
112 /**
113 * Get OpenCV access to the specified camera. This allows you to get
114 * images from the camera for image processing on the roboRIO.
115 *
116 * @param name Camera name
117 */
118 static cs::CvSink GetVideo(std::string_view name);
119
120 /**
121 * Get OpenCV access to the specified camera. This allows you to get
122 * images from the camera for image processing on the roboRIO.
123 *
124 * @param name Camera name
125 * @param pixelFormat The desired pixelFormat of captured frames from the
126 * camera
127 */
128 static cs::CvSink GetVideo(std::string_view name,
129 cs::VideoMode::PixelFormat pixelFormat);
130
131 /**
132 * Create a MJPEG stream with OpenCV input. This can be called to pass custom
133 * annotated images to the dashboard.
134 *
135 * @param name Name to give the stream
136 * @param width Width of the image being sent
137 * @param height Height of the image being sent
138 */
139 static cs::CvSource PutVideo(std::string_view name, int width, int height);
140
141 /**
142 * Adds a MJPEG server at the next available port.
143 *
144 * @param name Server name
145 */
146 static cs::MjpegServer AddServer(std::string_view name);
147
148 /**
149 * Adds a MJPEG server.
150 *
151 * @param name Server name
152 * @param port Port number
153 */
154 static cs::MjpegServer AddServer(std::string_view name, int port);
155
156 /**
157 * Adds an already created server.
158 *
159 * @param server Server
160 */
161 static void AddServer(const cs::VideoSink& server);
162
163 /**
164 * Removes a server by name.
165 *
166 * @param name Server name
167 */
168 static void RemoveServer(std::string_view name);
169
170 /**
171 * Get server for the primary camera feed.
172 *
173 * This is only valid to call after a camera feed has been added with
174 * StartAutomaticCapture() or AddServer().
175 */
177
178 /**
179 * Gets a server by name.
180 *
181 * @param name Server name
182 */
183 static cs::VideoSink GetServer(std::string_view name);
184
185 /**
186 * Adds an already created camera.
187 *
188 * @param camera Camera
189 */
190 static void AddCamera(const cs::VideoSource& camera);
191
192 /**
193 * Removes a camera by name.
194 *
195 * @param name Camera name
196 */
197 static void RemoveCamera(std::string_view name);
198
199 private:
200 CameraServer() = default;
201};
202
203} // namespace frc
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: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::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::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 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 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, 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::VideoSink GetServer()
Get server for the primary camera feed.
static cs::CvSink GetVideo(std::string_view name)
Get OpenCV access to the specified camera.
Definition SystemServer.h:9
PixelFormat
Definition cscore_cpp.h:63