source: flair-src/trunk/lib/FlairSensorActuator/src/V4LCamera.h@ 342

Last change on this file since 342 was 340, checked in by Sanahuja Guillaume, 5 years ago

add servos

File size: 5.3 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]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"
[330]18//todo use pimpl and remove this
19#include <linux/videodev2.h>
20#include <libv4l1-videodev.h>
21#define MAX_V4L_BUFFERS 10
[3]22
[15]23namespace flair {
24namespace core {
[338]25class Image;
[3]26}
[15]27namespace gui {
28class DoubleSpinBox;
29class CheckBox;
30class Label;
31}
32}
[3]33
[15]34namespace flair {
35namespace sensor {
36/*! \class V4LCamera
37*
38* \brief Base class for V4l camera
39*/
40class V4LCamera : public core::Thread, public Camera {
41public:
42 /*!
43 * \brief Constructor
44 *
45 * Construct a Camera.
[137]46 * It will be child of the FrameworkManager.
[15]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 */
[137]55 V4LCamera(std::string name,
[15]56 uint8_t camera_index, uint16_t width, uint16_t height,
[338]57 core::Image::Type::Format format, uint8_t priority);
[3]58
[15]59 /*!
60 * \brief Destructor
61 *
62 */
63 ~V4LCamera();
[165]64
65 //hack for ps3eye in hds uav
66 //TODO: put this in ps3eye class
67 bool HasProblems(void);
[3]68
[15]69protected:
70 /*!
71 * \brief Set Gain
72 *
73 * \param value value between 0 and 1
74 */
75 virtual void SetGain(float value);
[3]76
[15]77 /*!
78 * \brief Set Auto Gain
79 *
80 * \param value value
81 */
82 virtual void SetAutoGain(bool value);
[3]83
[15]84 /*!
85 * \brief Set Exposure
86 *
87 * \param value value between 0 and 1
88 */
89 virtual void SetExposure(float value);
[3]90
[15]91 /*!
92 * \brief Set Auto Exposure
93 *
94 * \param value value
95 */
96 virtual void SetAutoExposure(bool value);
[3]97
[15]98 /*!
99 * \brief Set Brightness
100 *
101 * \param value value between 0 and 1
102 */
103 virtual void SetBrightness(float value);
[3]104
[15]105 /*!
106 * \brief Set Saturation
107 *
108 * \param value value between 0 and 1
109 */
110 virtual void SetSaturation(float value);
[3]111
[15]112 /*!
113 * \brief Set Hue
114 *
115 * \param value value between 0 and 1
116 */
117 virtual void SetHue(float value);
[3]118
[15]119 /*!
120 * \brief Set Contrast
121 *
122 * \param value value between 0 and 1
123 */
124 virtual void SetContrast(float value);
[165]125
[15]126private:
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){};
[3]135
[15]136 /*!
137 * \brief Run function
138 *
139 * Reimplemented from Thread.
140 *
141 */
142 void Run(void);
[330]143
144 int device;
[15]145 gui::Tab *sensor_tab;
[165]146 gui::DoubleSpinBox *bright, *exposure, *gain, *contrast, *hue, *sharpness,*sat;
[15]147 gui::CheckBox *autogain, *awb, *autoexposure;
148 gui::Label *fps;
[165]149 bool hasProblems;
[330]150 static int xioctl( int fd, int request, void *arg);
151 void SetProperty(int property,float value);
152 float GetProperty(int property);
[338]153 int GrabFrame(void);
[330]154 int AllocBuffers(void);
[338]155 int QueueBuffer(int index);
[330]156 struct video_mmap *mmaps;
157 int bufferIndex;
158 struct buffer {
159 void * start;
160 size_t length;
161 };
[338]162 buffer buffers[MAX_V4L_BUFFERS];
[330]163 char* frame;
[338]164 int nbBuffers;
[340]165
166 typedef struct CvCaptureCAM_V4L
167{
168 int deviceHandle;
169 int bufferIndex;
170 int FirstCapture;
171 struct video_capability capability;
172 struct video_window captureWindow;
173 struct video_picture imageProperties;
174 struct video_mbuf memoryBuffer;
175 struct video_mmap *mmaps;
176 char *memoryMap;
177 //IplImage frame;
178char *imageData;
179int imageSize;
180
181 /* V4L2 variables */
182 buffer buffers[MAX_V4L_BUFFERS + 1];
183 struct v4l2_capability cap;
184 struct v4l2_input inp;
185 struct v4l2_format form;
186 struct v4l2_crop crop;
187 struct v4l2_cropcap cropcap;
188 struct v4l2_requestbuffers req;
189 struct v4l2_jpegcompression compr;
190 struct v4l2_control control;
191 enum v4l2_buf_type type;
192 struct v4l2_queryctrl queryctrl;
193 struct v4l2_querymenu querymenu;
194
195 /* V4L2 control variables */
196 int v4l2_brightness, v4l2_brightness_min, v4l2_brightness_max;
197 int v4l2_contrast, v4l2_contrast_min, v4l2_contrast_max;
198 int v4l2_saturation, v4l2_saturation_min, v4l2_saturation_max;
199 int v4l2_sharpness, v4l2_sharpness_min, v4l2_sharpness_max;
200 int v4l2_exposure, v4l2_exposure_min, v4l2_exposure_max;
201 int v4l2_hue, v4l2_hue_min, v4l2_hue_max;
202 int v4l2_gain, v4l2_gain_min, v4l2_gain_max;
203 int v4l2_autogain, v4l2_autogain_min, v4l2_autogain_max;
204 int v4l2_awb, v4l2_awb_min, v4l2_awb_max;
205
206
207
208} CvCaptureCAM_V4L;
209
210CvCaptureCAM_V4L capture;
211int _capture_V4L2 (CvCaptureCAM_V4L *capture);
212int try_init_v4l2(CvCaptureCAM_V4L* capture);
213int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture);
214int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h);
215int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace);
216int PALETTE_YUYV,PALETTE_UYVY;
217int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,int property_id, double value );
218int icvSetControl (CvCaptureCAM_V4L* capture,int property_id, double value) ;
219int cvGrabFrame(CvCaptureCAM_V4L* capture);
220int v4l2_alloc_buffers (CvCaptureCAM_V4L *capture, char *deviceName);
221void mainloop_v4l2(CvCaptureCAM_V4L* capture);
222int read_frame_v4l2(CvCaptureCAM_V4L* capture);
223void cvRetrieveRawFrame( CvCaptureCAM_V4L* capture);
224unsigned int n_buffers ;
[15]225};
[3]226} // end namespace sensor
227} // end namespace flair
228#endif // V4LCamera_H
Note: See TracBrowser for help on using the repository browser.