blob: 9252442c1ddacf0ae72120890f97cc0407ab24e5 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
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
19/**
20 * Axis M1011 network camera
21 */
22class 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};