WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
CameraServer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2014-2016. 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 <memory>
11 #include <mutex>
12 #include <string>
13 #include <vector>
14 
15 #include "ErrorBase.h"
16 #include "cscore.h"
17 #include "llvm/DenseMap.h"
18 #include "llvm/StringMap.h"
19 #include "llvm/StringRef.h"
20 #include "networktables/NetworkTable.h"
21 
22 namespace frc {
23 
28 class CameraServer : public ErrorBase {
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 
50  cs::UsbCamera StartAutomaticCapture();
51 
60  cs::UsbCamera StartAutomaticCapture(int dev);
61 
68  cs::UsbCamera StartAutomaticCapture(llvm::StringRef name, int dev);
69 
76  cs::UsbCamera StartAutomaticCapture(llvm::StringRef name,
77  llvm::StringRef path);
78 
85  void StartAutomaticCapture(const cs::VideoSource& camera);
86 
94  cs::CvSink GetVideo();
95 
102  cs::CvSink GetVideo(const cs::VideoSource& camera);
103 
110  cs::CvSink GetVideo(llvm::StringRef name);
111 
120  cs::CvSource PutVideo(llvm::StringRef name, int width, int height);
121 
127  cs::MjpegServer AddServer(llvm::StringRef name);
128 
134  cs::MjpegServer AddServer(llvm::StringRef name, int port);
135 
141  void AddServer(const cs::VideoSink& server);
142 
148  void RemoveServer(llvm::StringRef name);
149 
155  void AddCamera(const cs::VideoSource& camera);
156 
162  void RemoveCamera(llvm::StringRef name);
163 
173  void SetSize(int size);
174 
175  private:
176  CameraServer();
177 
178  std::shared_ptr<ITable> GetSourceTable(CS_Source source);
179  void UpdateStreamValues();
180 
181  static constexpr char const* kPublishName = "/CameraPublisher";
182 
183  std::mutex m_mutex;
184  std::string m_primarySourceName;
185  llvm::StringMap<cs::VideoSource> m_sources;
186  llvm::StringMap<cs::VideoSink> m_sinks;
187  llvm::DenseMap<CS_Source, std::shared_ptr<ITable>> m_tables;
188  std::shared_ptr<NetworkTable> m_publishTable;
189  cs::VideoListener m_videoListener;
190  int m_tableListener;
191  int m_nextPort;
192  std::vector<std::string> m_addresses;
193 };
194 
195 } // namespace frc
void SetSize(int size)
Sets the size of the image to use.
Definition: CameraServer.cpp:342
cs::UsbCamera StartAutomaticCapture()
Start automatically capturing images to send to the dashboard.
Definition: CameraServer.cpp:200
static CameraServer * GetInstance()
Get the CameraServer instance.
Definition: CameraServer.cpp:17
cs::CvSource PutVideo(llvm::StringRef name, int width, int height)
Create a MJPEG stream with OpenCV input.
Definition: CameraServer.cpp:298
Base class for most objects.
Definition: ErrorBase.h:72
void RemoveCamera(llvm::StringRef name)
Removes a camera by name.
Definition: CameraServer.cpp:337
cs::MjpegServer AddServer(llvm::StringRef name)
Adds a MJPEG server at the next available port.
Definition: CameraServer.cpp:305
void AddCamera(const cs::VideoSource &camera)
Adds an already created camera.
Definition: CameraServer.cpp:330
Singleton class for creating and keeping camera servers.
Definition: CameraServer.h:28
void RemoveServer(llvm::StringRef name)
Removes a server by name.
Definition: CameraServer.cpp:325
cs::CvSink GetVideo()
Get OpenCV access to the primary camera feed.
Definition: CameraServer.cpp:237