WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
AxisCamera.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 <thread>
11 #include <string>
12 #include "HAL/cpp/priority_mutex.h"
13 
14 #include "ErrorBase.h"
15 #include "Vision/ColorImage.h"
16 #include "Vision/HSLImage.h"
17 #include "nivision.h"
18 
22 class AxisCamera : public ErrorBase {
23  public:
24  enum WhiteBalance {
25  kWhiteBalance_Automatic,
26  kWhiteBalance_Hold,
27  kWhiteBalance_FixedOutdoor1,
28  kWhiteBalance_FixedOutdoor2,
29  kWhiteBalance_FixedIndoor,
30  kWhiteBalance_FixedFluorescent1,
31  kWhiteBalance_FixedFluorescent2
32  };
33 
34  enum ExposureControl {
35  kExposureControl_Automatic,
36  kExposureControl_Hold,
37  kExposureControl_FlickerFree50Hz,
38  kExposureControl_FlickerFree60Hz
39  };
40 
41  enum Resolution {
42  kResolution_640x480,
43  kResolution_480x360,
44  kResolution_320x240,
45  kResolution_240x180,
46  kResolution_176x144,
47  kResolution_160x120,
48  };
49 
50  enum Rotation { kRotation_0, kRotation_180 };
51 
52  explicit AxisCamera(std::string const &cameraHost);
53  virtual ~AxisCamera();
54 
55  AxisCamera(const AxisCamera&) = delete;
56  AxisCamera& operator=(const AxisCamera&) = delete;
57 
58  bool IsFreshImage() const;
59 
60  int GetImage(Image *image);
61  int GetImage(ColorImage *image);
62  HSLImage *GetImage();
63  int CopyJPEG(char **destImage, unsigned int &destImageSize,
64  unsigned int &destImageBufferSize);
65 
66  void WriteBrightness(int brightness);
67  int GetBrightness();
68 
69  void WriteWhiteBalance(WhiteBalance whiteBalance);
70  WhiteBalance GetWhiteBalance();
71 
72  void WriteColorLevel(int colorLevel);
73  int GetColorLevel();
74 
75  void WriteExposureControl(ExposureControl exposureControl);
76  ExposureControl GetExposureControl();
77 
78  void WriteExposurePriority(int exposurePriority);
79  int GetExposurePriority();
80 
81  void WriteMaxFPS(int maxFPS);
82  int GetMaxFPS();
83 
84  void WriteResolution(Resolution resolution);
85  Resolution GetResolution();
86 
87  void WriteCompression(int compression);
88  int GetCompression();
89 
90  void WriteRotation(Rotation rotation);
91  Rotation GetRotation();
92 
93  private:
94  std::thread m_captureThread;
95  std::string m_cameraHost;
96  int m_cameraSocket = -1;
97  priority_mutex m_captureMutex;
98 
99  priority_mutex m_imageDataMutex;
100  std::vector<uint8_t> m_imageData;
101  bool m_freshImage = false;
102 
103  int m_brightness = 50;
104  WhiteBalance m_whiteBalance = kWhiteBalance_Automatic;
105  int m_colorLevel = 50;
106  ExposureControl m_exposureControl = kExposureControl_Automatic;
107  int m_exposurePriority = 50;
108  int m_maxFPS = 0;
109  Resolution m_resolution = kResolution_640x480;
110  int m_compression = 50;
111  Rotation m_rotation = kRotation_0;
112  bool m_parametersDirty = true;
113  bool m_streamDirty = true;
114  priority_mutex m_parametersMutex;
115 
116  bool m_done = false;
117 
118  void Capture();
119  void ReadImagesFromCamera();
120  bool WriteParameters();
121 
122  int CreateCameraSocket(std::string const &requestString, bool setError);
123 };
A color image represented in HSL color space at 3 bytes per pixel.
Definition: HSLImage.h:15
WhiteBalance GetWhiteBalance()
Definition: AxisCamera.cpp:190
void WriteExposurePriority(int exposurePriority)
Request a change in the exposure priority of the camera.
Definition: AxisCamera.cpp:251
void WriteWhiteBalance(WhiteBalance whiteBalance)
Request a change in the white balance on the camera.
Definition: AxisCamera.cpp:178
int GetMaxFPS()
Definition: AxisCamera.cpp:294
int GetBrightness()
Definition: AxisCamera.cpp:169
int GetExposurePriority()
Definition: AxisCamera.cpp:270
int GetCompression()
Definition: AxisCamera.cpp:370
void WriteCompression(int compression)
Write the compression value to the camera.
Definition: AxisCamera.cpp:351
void WriteMaxFPS(int maxFPS)
Write the maximum frames per second that the camera should send Write 0 to send as many as possible...
Definition: AxisCamera.cpp:281
AxisCamera(std::string const &cameraHost)
AxisCamera constructor.
Definition: AxisCamera.cpp:46
Base class for most objects.
Definition: ErrorBase.h:66
void WriteExposureControl(ExposureControl exposureControl)
Request a change in the camera's exposure mode.
Definition: AxisCamera.cpp:226
Definition: ColorImage.h:14
Axis M1011 network camera.
Definition: AxisCamera.h:22
Definition: priority_mutex.h:53
HSLImage * GetImage()
Instantiate a new image object and fill it with the latest image from the camera. ...
Definition: AxisCamera.cpp:101
void WriteColorLevel(int colorLevel)
Request a change in the color level of the camera images.
Definition: AxisCamera.cpp:199
int CopyJPEG(char **destImage, unsigned int &destImageSize, unsigned int &destImageBufferSize)
Copy an image into an existing buffer.
Definition: AxisCamera.cpp:118
Resolution GetResolution()
Definition: AxisCamera.cpp:317
void WriteRotation(Rotation rotation)
Write the rotation value to the camera.
Definition: AxisCamera.cpp:329
void WriteBrightness(int brightness)
Request a change in the brightness of the camera images.
Definition: AxisCamera.cpp:151
void WriteResolution(Resolution resolution)
Write resolution value to camera.
Definition: AxisCamera.cpp:303
int GetColorLevel()
Definition: AxisCamera.cpp:217
ExposureControl GetExposureControl()
Definition: AxisCamera.cpp:239
Rotation GetRotation()
Definition: AxisCamera.cpp:342