WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
USBCamera.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 "ErrorBase.h"
11 #include "nivision.h"
12 #include "NIIMAQdx.h"
13 #include "HAL/cpp/priority_mutex.h"
14 
15 #include <string>
16 
17 typedef enum whiteBalance_enum {
18  kFixedIndoor = 3000,
19  kFixedOutdoor1 = 4000,
20  kFixedOutdoor2 = 5000,
21  kFixedFluorescent1 = 5100,
22  kFixedFlourescent2 = 5200
23 } whiteBalance;
24 
25 class USBCamera : public ErrorBase {
26  private:
27  static constexpr char const *ATTR_WB_MODE =
28  "CameraAttributes::WhiteBalance::Mode";
29  static constexpr char const *ATTR_WB_VALUE =
30  "CameraAttributes::WhiteBalance::Value";
31  static constexpr char const *ATTR_EX_MODE =
32  "CameraAttributes::Exposure::Mode";
33  static constexpr char const *ATTR_EX_VALUE =
34  "CameraAttributes::Exposure::Value";
35  static constexpr char const *ATTR_BR_MODE =
36  "CameraAttributes::Brightness::Mode";
37  static constexpr char const *ATTR_BR_VALUE =
38  "CameraAttributes::Brightness::Value";
39 
40  // Constants for the manual and auto types
41  static constexpr char const* AUTO = "Auto";
42  static constexpr char const* MANUAL = "Manual";
43 
44  protected:
45  IMAQdxSession m_id = 0;
46  std::string m_name;
47  bool m_useJpeg;
48  bool m_active = false;
49  bool m_open = false;
50 
52 
53  unsigned int m_width = 320;
54  unsigned int m_height = 240;
55  double m_fps = 30;
56  std::string m_whiteBalance = AUTO;
57  unsigned int m_whiteBalanceValue = 0;
58  bool m_whiteBalanceValuePresent = false;
59  std::string m_exposure = MANUAL;
60  unsigned int m_exposureValue = 50;
61  bool m_exposureValuePresent = false;
62  unsigned int m_brightness = 80;
63  bool m_needSettingsUpdate = true;
64 
65  unsigned int GetJpegSize(void *buffer, unsigned int buffSize);
66 
67  public:
68  static constexpr char const *kDefaultCameraName = "cam0";
69 
70  USBCamera(std::string name, bool useJpeg);
71 
72  void OpenCamera();
73  void CloseCamera();
74  void StartCapture();
75  void StopCapture();
76  void SetFPS(double fps);
77  void SetSize(unsigned int width, unsigned int height);
78 
79  void UpdateSettings();
83  void SetBrightness(unsigned int brightness);
84 
88  unsigned int GetBrightness();
89 
93  void SetWhiteBalanceAuto();
94 
99 
103  void SetWhiteBalanceManual(unsigned int wbValue);
104 
108  void SetExposureAuto();
109 
113  void SetExposureHoldCurrent();
114 
118  void SetExposureManual(unsigned int expValue);
119 
120  void GetImage(Image *image);
121  unsigned int GetImageData(void *buffer, unsigned int bufferSize);
122 };
void SetExposureAuto()
Set the exposure to auto exposure.
Definition: USBCamera.cpp:278
void SetExposureHoldCurrent()
Set the exposure to hold current.
Definition: USBCamera.cpp:286
void SetWhiteBalanceHoldCurrent()
Set the white balance to hold current.
Definition: USBCamera.cpp:262
void SetBrightness(unsigned int brightness)
Set the brightness, as a percentage (0-100).
Definition: USBCamera.cpp:241
unsigned int GetJpegSize(void *buffer, unsigned int buffSize)
Helper function to determine the size of a jpeg.
Definition: USBCamera.cpp:36
void SetWhiteBalanceManual(unsigned int wbValue)
Set the white balance to manual, with specified color temperature.
Definition: USBCamera.cpp:270
Definition: priority_mutex.h:22
Base class for most objects.
Definition: ErrorBase.h:66
void SetWhiteBalanceAuto()
Set the white balance to auto.
Definition: USBCamera.cpp:254
unsigned int GetBrightness()
Get the brightness, as a percentage (0-100).
Definition: USBCamera.cpp:249
Definition: USBCamera.h:25
void SetExposureManual(unsigned int expValue)
Set the exposure to manual, with a given percentage (0-100)
Definition: USBCamera.cpp:294