WPILibC++  unspecified
CvSourceImpl.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 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 #ifndef CSCORE_CVSOURCEIMPL_H_
9 #define CSCORE_CVSOURCEIMPL_H_
10 
11 #include <atomic>
12 #include <functional>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "SourceImpl.h"
18 
19 namespace cs {
20 
21 class CvSourceImpl : public SourceImpl {
22  public:
23  CvSourceImpl(llvm::StringRef name, const VideoMode& mode);
24  ~CvSourceImpl() override;
25 
26  void Start();
27 
28  // Property functions
29  void SetProperty(int property, int value, CS_Status* status) override;
30  void SetStringProperty(int property, llvm::StringRef value,
31  CS_Status* status) override;
32 
33  // Standard common camera properties
34  void SetBrightness(int brightness, CS_Status* status) override;
35  int GetBrightness(CS_Status* status) const override;
36  void SetWhiteBalanceAuto(CS_Status* status) override;
37  void SetWhiteBalanceHoldCurrent(CS_Status* status) override;
38  void SetWhiteBalanceManual(int value, CS_Status* status) override;
39  void SetExposureAuto(CS_Status* status) override;
40  void SetExposureHoldCurrent(CS_Status* status) override;
41  void SetExposureManual(int value, CS_Status* status) override;
42 
43  bool SetVideoMode(const VideoMode& mode, CS_Status* status) override;
44 
45  void NumSinksChanged() override;
46  void NumSinksEnabledChanged() override;
47 
48  // OpenCV-specific functions
49  void PutFrame(cv::Mat& image);
50  void NotifyError(llvm::StringRef msg);
51  int CreateProperty(llvm::StringRef name, CS_PropertyKind kind, int minimum,
52  int maximum, int step, int defaultValue, int value);
53  int CreateProperty(llvm::StringRef name, CS_PropertyKind kind, int minimum,
54  int maximum, int step, int defaultValue, int value,
55  std::function<void(CS_Property property)> onChange);
56  void SetEnumPropertyChoices(int property, llvm::ArrayRef<std::string> choices,
57  CS_Status* status);
58 
59  // Property data
60  class PropertyData : public PropertyImpl {
61  public:
62  PropertyData() = default;
63  explicit PropertyData(llvm::StringRef name_) : PropertyImpl{name_} {}
64  PropertyData(llvm::StringRef name_, CS_PropertyKind kind_, int minimum_,
65  int maximum_, int step_, int defaultValue_, int value_)
66  : PropertyImpl{name_, kind_, step_, defaultValue_, value_} {
67  hasMinimum = true;
68  minimum = minimum_;
69  hasMaximum = true;
70  maximum = maximum_;
71  }
72  ~PropertyData() override = default;
73 
74  std::function<void(CS_Property property)> onChange;
75  };
76 
77  protected:
78  std::unique_ptr<PropertyImpl> CreateEmptyProperty(
79  llvm::StringRef name) const override;
80 
81  bool CacheProperties(CS_Status* status) const override;
82 
83  private:
84  std::atomic_bool m_connected{true};
85 };
86 
87 } // namespace cs
88 
89 #endif // CSCORE_CVSOURCEIMPL_H_
Definition: SinkImpl.h:19
Definition: CvSourceImpl.h:60
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
Definition: SourceImpl.h:30
Definition: PropertyImpl.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
Definition: CvSourceImpl.h:21
Video mode.
Definition: cscore_cpp.h:46