WPILibC++  2020.3.2-60-g3011ebe
CameraServer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <string>
14 
15 #include <wpi/ArrayRef.h>
16 #include <wpi/Twine.h>
17 
18 #include "cscore.h"
19 #include "cscore_cv.h"
20 
21 namespace frc {
22 
28 class CameraServer {
29  public:
30  static constexpr uint16_t kBasePort = 1181;
31  static constexpr int kSize640x480 = 0;
32  static constexpr int kSize320x240 = 1;
33  static constexpr int kSize160x120 = 2;
34 
38  static CameraServer* GetInstance();
39 
52 
62 
69  cs::UsbCamera StartAutomaticCapture(const wpi::Twine& name, int dev);
70 
78  const wpi::Twine& path);
79 
87 
96 
104  cs::AxisCamera AddAxisCamera(const char* host);
105 
113  cs::AxisCamera AddAxisCamera(const std::string& host);
114 
123 
131  template <typename T>
132  cs::AxisCamera AddAxisCamera(std::initializer_list<T> hosts);
133 
140  cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const wpi::Twine& host);
141 
148  cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const char* host);
149 
156  cs::AxisCamera AddAxisCamera(const wpi::Twine& name, const std::string& host);
157 
166 
173  template <typename T>
175  std::initializer_list<T> hosts);
176 
184 
192  cs::CvSink GetVideo();
193 
200  cs::CvSink GetVideo(const cs::VideoSource& camera);
201 
208  cs::CvSink GetVideo(const wpi::Twine& name);
209 
218  cs::CvSource PutVideo(const wpi::Twine& name, int width, int height);
219 
225  cs::MjpegServer AddServer(const wpi::Twine& name);
226 
232  cs::MjpegServer AddServer(const wpi::Twine& name, int port);
233 
239  void AddServer(const cs::VideoSink& server);
240 
246  void RemoveServer(const wpi::Twine& name);
247 
255 
261  cs::VideoSink GetServer(const wpi::Twine& name);
262 
268  void AddCamera(const cs::VideoSource& camera);
269 
275  void RemoveCamera(const wpi::Twine& name);
276 
286  void SetSize(int size);
287 
288  private:
289  CameraServer();
290  ~CameraServer();
291 
292  struct Impl;
293  std::unique_ptr<Impl> m_impl;
294 };
295 
296 } // namespace frc
297 
298 #include "cameraserver/CameraServer.inc"
frc::CameraServer::AddSwitchedCamera
cs::MjpegServer AddSwitchedCamera(const wpi::Twine &name)
Adds a virtual camera for switching between two streams.
frc::CameraServer::AddServer
cs::MjpegServer AddServer(const wpi::Twine &name)
Adds a MJPEG server at the next available port.
cs::VideoSink
A sink for video that accepts a sequence of frames.
Definition: cscore_oo.h:723
cs::AxisCamera
A source that represents an Axis IP camera.
Definition: cscore_oo.h:556
frc::CameraServer::PutVideo
cs::CvSource PutVideo(const wpi::Twine &name, int width, int height)
Create a MJPEG stream with OpenCV input.
cs::UsbCamera
A source that represents a USB camera.
Definition: cscore_oo.h:420
frc::CameraServer::GetServer
cs::VideoSink GetServer()
Get server for the primary camera feed.
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
cs::MjpegServer
A sink that acts as a MJPEG-over-HTTP network server.
Definition: cscore_oo.h:873
frc::CameraServer::SetSize
void SetSize(int size)
Sets the size of the image to use.
frc::CameraServer::RemoveCamera
void RemoveCamera(const wpi::Twine &name)
Removes a camera by name.
frc::CameraServer::AddAxisCamera
cs::AxisCamera AddAxisCamera(const wpi::Twine &host)
Adds an Axis IP camera.
frc::CameraServer::AddCamera
void AddCamera(const cs::VideoSource &camera)
Adds an already created camera.
frc::CameraServer
Singleton class for creating and keeping camera servers.
Definition: CameraServer.h:28
frc::CameraServer::GetInstance
static CameraServer * GetInstance()
Get the CameraServer instance.
frc::CameraServer::StartAutomaticCapture
cs::UsbCamera StartAutomaticCapture()
Start automatically capturing images to send to the dashboard.
frc::CameraServer::RemoveServer
void RemoveServer(const wpi::Twine &name)
Removes a server by name.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
cs::VideoSource
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
frc::CameraServer::GetVideo
cs::CvSink GetVideo()
Get OpenCV access to the primary camera feed.