1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | /*!
|
---|
6 | * \file V4LCamera.h
|
---|
7 | * \brief Base class for V4l camera
|
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
9 | * \date 2014/07/17
|
---|
10 | * \version 4.0
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef V4LCamera_H
|
---|
14 | #define V4LCamera_H
|
---|
15 |
|
---|
16 | #include <Thread.h>
|
---|
17 | #include "Camera.h"
|
---|
18 | //todo use pimpl and remove this
|
---|
19 | #include <linux/videodev2.h>
|
---|
20 | #include <libv4l1-videodev.h>
|
---|
21 | #define MAX_V4L_BUFFERS 10
|
---|
22 |
|
---|
23 | namespace flair {
|
---|
24 | namespace core {
|
---|
25 | class cvimage;
|
---|
26 | }
|
---|
27 | namespace gui {
|
---|
28 | class DoubleSpinBox;
|
---|
29 | class CheckBox;
|
---|
30 | class Label;
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | namespace flair {
|
---|
35 | namespace sensor {
|
---|
36 | /*! \class V4LCamera
|
---|
37 | *
|
---|
38 | * \brief Base class for V4l camera
|
---|
39 | */
|
---|
40 | class V4LCamera : public core::Thread, public Camera {
|
---|
41 | public:
|
---|
42 | /*!
|
---|
43 | * \brief Constructor
|
---|
44 | *
|
---|
45 | * Construct a Camera.
|
---|
46 | * It will be child of the FrameworkManager.
|
---|
47 | *
|
---|
48 | * \param name name
|
---|
49 | * \param camera_index camera index
|
---|
50 | * \param width width
|
---|
51 | * \param height height
|
---|
52 | * \param format image format
|
---|
53 | * \param priority priority of the Thread
|
---|
54 | */
|
---|
55 | V4LCamera(std::string name,
|
---|
56 | uint8_t camera_index, uint16_t width, uint16_t height,
|
---|
57 | core::cvimage::Type::Format format, uint8_t priority);
|
---|
58 |
|
---|
59 | /*!
|
---|
60 | * \brief Destructor
|
---|
61 | *
|
---|
62 | */
|
---|
63 | ~V4LCamera();
|
---|
64 |
|
---|
65 | //hack for ps3eye in hds uav
|
---|
66 | //TODO: put this in ps3eye class
|
---|
67 | bool HasProblems(void);
|
---|
68 |
|
---|
69 | protected:
|
---|
70 | /*!
|
---|
71 | * \brief Set Gain
|
---|
72 | *
|
---|
73 | * \param value value between 0 and 1
|
---|
74 | */
|
---|
75 | virtual void SetGain(float value);
|
---|
76 |
|
---|
77 | /*!
|
---|
78 | * \brief Set Auto Gain
|
---|
79 | *
|
---|
80 | * \param value value
|
---|
81 | */
|
---|
82 | virtual void SetAutoGain(bool value);
|
---|
83 |
|
---|
84 | /*!
|
---|
85 | * \brief Set Exposure
|
---|
86 | *
|
---|
87 | * \param value value between 0 and 1
|
---|
88 | */
|
---|
89 | virtual void SetExposure(float value);
|
---|
90 |
|
---|
91 | /*!
|
---|
92 | * \brief Set Auto Exposure
|
---|
93 | *
|
---|
94 | * \param value value
|
---|
95 | */
|
---|
96 | virtual void SetAutoExposure(bool value);
|
---|
97 |
|
---|
98 | /*!
|
---|
99 | * \brief Set Brightness
|
---|
100 | *
|
---|
101 | * \param value value between 0 and 1
|
---|
102 | */
|
---|
103 | virtual void SetBrightness(float value);
|
---|
104 |
|
---|
105 | /*!
|
---|
106 | * \brief Set Saturation
|
---|
107 | *
|
---|
108 | * \param value value between 0 and 1
|
---|
109 | */
|
---|
110 | virtual void SetSaturation(float value);
|
---|
111 |
|
---|
112 | /*!
|
---|
113 | * \brief Set Hue
|
---|
114 | *
|
---|
115 | * \param value value between 0 and 1
|
---|
116 | */
|
---|
117 | virtual void SetHue(float value);
|
---|
118 |
|
---|
119 | /*!
|
---|
120 | * \brief Set Contrast
|
---|
121 | *
|
---|
122 | * \param value value between 0 and 1
|
---|
123 | */
|
---|
124 | virtual void SetContrast(float value);
|
---|
125 |
|
---|
126 | private:
|
---|
127 | /*!
|
---|
128 | * \brief Update using provided datas
|
---|
129 | *
|
---|
130 | * Reimplemented from IODevice.
|
---|
131 | *
|
---|
132 | * \param data data from the parent to process
|
---|
133 | */
|
---|
134 | void UpdateFrom(const core::io_data *data){};
|
---|
135 |
|
---|
136 | /*!
|
---|
137 | * \brief Run function
|
---|
138 | *
|
---|
139 | * Reimplemented from Thread.
|
---|
140 | *
|
---|
141 | */
|
---|
142 | void Run(void);
|
---|
143 |
|
---|
144 | int device;
|
---|
145 | gui::Tab *sensor_tab;
|
---|
146 | gui::DoubleSpinBox *bright, *exposure, *gain, *contrast, *hue, *sharpness,*sat;
|
---|
147 | gui::CheckBox *autogain, *awb, *autoexposure;
|
---|
148 | gui::Label *fps;
|
---|
149 | bool hasProblems;
|
---|
150 | static int xioctl( int fd, int request, void *arg);
|
---|
151 | void SetProperty(int property,float value);
|
---|
152 | float GetProperty(int property);
|
---|
153 | void GrabFrame(void);
|
---|
154 | int read_frame_v4l2(void);
|
---|
155 | char *RetrieveRawFrame(void);
|
---|
156 | int AllocBuffers(void);
|
---|
157 | struct video_mmap *mmaps;
|
---|
158 | int bufferIndex;
|
---|
159 | struct v4l2_requestbuffers requestbuffers;
|
---|
160 | struct buffer {
|
---|
161 | void * start;
|
---|
162 | size_t length;
|
---|
163 | };
|
---|
164 | buffer buffers[MAX_V4L_BUFFERS + 1];
|
---|
165 | char* frame;
|
---|
166 | };
|
---|
167 | } // end namespace sensor
|
---|
168 | } // end namespace flair
|
---|
169 | #endif // V4LCamera_H
|
---|