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 
49  cs::USBCamera StartAutomaticCapture();
50 
56  cs::USBCamera StartAutomaticCapture(int dev);
57 
64  cs::USBCamera StartAutomaticCapture(llvm::StringRef name, int dev);
65 
72  cs::USBCamera StartAutomaticCapture(llvm::StringRef name,
73  llvm::StringRef path);
74 
81  void StartAutomaticCapture(const cs::VideoSource& camera);
82 
90  cs::CvSink GetVideo();
91 
98  cs::CvSink GetVideo(const cs::VideoSource& camera);
99 
108  cs::CvSource PutVideo(llvm::StringRef name, int width, int height);
109 
115  cs::MJPEGServer AddServer(llvm::StringRef name);
116 
122  cs::MJPEGServer AddServer(llvm::StringRef name, int port);
123 
129  void AddServer(const cs::VideoSink& server);
130 
136  void RemoveServer(llvm::StringRef name);
137 
143  void AddCamera(const cs::VideoSource& camera);
144 
150  void RemoveCamera(llvm::StringRef name);
151 
161  void SetSize(int size);
162 
163  private:
164  CameraServer();
165 
166  std::shared_ptr<ITable> GetSourceTable(CS_Source source);
167  void UpdateStreamValues();
168 
169  static constexpr char const* kPublishName = "/CameraPublisher";
170 
171  std::mutex m_mutex;
172  std::string m_primarySourceName;
173  llvm::StringMap<cs::VideoSource> m_sources;
174  llvm::StringMap<cs::VideoSink> m_sinks;
175  llvm::DenseMap<CS_Source, std::shared_ptr<ITable>> m_tables;
176  std::shared_ptr<NetworkTable> m_publishTable;
177  cs::VideoListener m_videoListener;
178  int m_tableListener;
179  int m_nextPort;
180  std::vector<std::string> m_addresses;
181 };
182 
183 } // namespace frc
cs::MJPEGServer AddServer(llvm::StringRef name)
Adds a MJPEG server at the next available port.
Definition: CameraServer.cpp:288
void SetSize(int size)
Sets the size of the image to use.
Definition: CameraServer.cpp:325
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:281
Base class for most objects.
Definition: ErrorBase.h:72
void RemoveCamera(llvm::StringRef name)
Removes a camera by name.
Definition: CameraServer.cpp:320
cs::USBCamera StartAutomaticCapture()
Start automatically capturing images to send to the dashboard.
Definition: CameraServer.cpp:200
void AddCamera(const cs::VideoSource &camera)
Adds an already created camera.
Definition: CameraServer.cpp:313
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:308
cs::CvSink GetVideo()
Get OpenCV access to the primary camera feed.
Definition: CameraServer.cpp:237