// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} /*! * \file V4LCamera.h * \brief Base class for V4l camera * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253 * \date 2014/07/17 * \version 4.0 */ #ifndef V4LCamera_H #define V4LCamera_H #include #include "Camera.h" //todo use pimpl and remove this #include #include #define MAX_V4L_BUFFERS 10 namespace flair { namespace core { class Image; } namespace gui { class DoubleSpinBox; class CheckBox; class Label; } } namespace flair { namespace sensor { /*! \class V4LCamera * * \brief Base class for V4l camera */ class V4LCamera : public core::Thread, public Camera { public: /*! * \brief Constructor * * Construct a Camera. * It will be child of the FrameworkManager. * * \param name name * \param camera_index camera index * \param width width * \param height height * \param format image format * \param priority priority of the Thread */ V4LCamera(std::string name, uint8_t camera_index, uint16_t width, uint16_t height, core::Image::Type::Format format, uint8_t priority); /*! * \brief Destructor * */ ~V4LCamera(); //hack for ps3eye in hds uav //TODO: put this in ps3eye class bool HasProblems(void); protected: /*! * \brief Set Gain * * \param value value between 0 and 1 */ virtual void SetGain(float value); /*! * \brief Set Auto Gain * * \param value value */ virtual void SetAutoGain(bool value); /*! * \brief Set Exposure * * \param value value between 0 and 1 */ virtual void SetExposure(float value); /*! * \brief Set Auto Exposure * * \param value value */ virtual void SetAutoExposure(bool value); /*! * \brief Set Brightness * * \param value value between 0 and 1 */ virtual void SetBrightness(float value); /*! * \brief Set Saturation * * \param value value between 0 and 1 */ virtual void SetSaturation(float value); /*! * \brief Set Hue * * \param value value between 0 and 1 */ virtual void SetHue(float value); /*! * \brief Set Contrast * * \param value value between 0 and 1 */ virtual void SetContrast(float value); private: /*! * \brief Update using provided datas * * Reimplemented from IODevice. * * \param data data from the parent to process */ void UpdateFrom(const core::io_data *data){}; /*! * \brief Run function * * Reimplemented from Thread. * */ void Run(void); int device; gui::Tab *sensor_tab; gui::DoubleSpinBox *bright, *exposure, *gain, *contrast, *hue, *sharpness,*sat; gui::CheckBox *autogain, *awb, *autoexposure; gui::Label *fps; bool hasProblems; static int xioctl( int fd, int request, void *arg); void SetProperty(int property,float value); float GetProperty(int property); int GrabFrame(void); int AllocBuffers(void); int QueueBuffer(int index); struct video_mmap *mmaps; int bufferIndex; struct buffer { void * start; size_t length; }; buffer buffers[MAX_V4L_BUFFERS]; char* frame; int nbBuffers; typedef struct CvCaptureCAM_V4L { int deviceHandle; int bufferIndex; int FirstCapture; struct video_capability capability; struct video_window captureWindow; struct video_picture imageProperties; struct video_mbuf memoryBuffer; struct video_mmap *mmaps; char *memoryMap; //IplImage frame; char *imageData; int imageSize; /* V4L2 variables */ buffer buffers[MAX_V4L_BUFFERS + 1]; struct v4l2_capability cap; struct v4l2_input inp; struct v4l2_format form; struct v4l2_crop crop; struct v4l2_cropcap cropcap; struct v4l2_requestbuffers req; struct v4l2_jpegcompression compr; struct v4l2_control control; enum v4l2_buf_type type; struct v4l2_queryctrl queryctrl; struct v4l2_querymenu querymenu; /* V4L2 control variables */ int v4l2_brightness, v4l2_brightness_min, v4l2_brightness_max; int v4l2_contrast, v4l2_contrast_min, v4l2_contrast_max; int v4l2_saturation, v4l2_saturation_min, v4l2_saturation_max; int v4l2_sharpness, v4l2_sharpness_min, v4l2_sharpness_max; int v4l2_exposure, v4l2_exposure_min, v4l2_exposure_max; int v4l2_hue, v4l2_hue_min, v4l2_hue_max; int v4l2_gain, v4l2_gain_min, v4l2_gain_max; int v4l2_autogain, v4l2_autogain_min, v4l2_autogain_max; int v4l2_awb, v4l2_awb_min, v4l2_awb_max; } CvCaptureCAM_V4L; CvCaptureCAM_V4L capture; int _capture_V4L2 (CvCaptureCAM_V4L *capture); int try_init_v4l2(CvCaptureCAM_V4L* capture); int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture); int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h); int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace); int PALETTE_YUYV,PALETTE_UYVY; int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,int property_id, double value ); int icvSetControl (CvCaptureCAM_V4L* capture,int property_id, double value) ; int cvGrabFrame(CvCaptureCAM_V4L* capture); int v4l2_alloc_buffers (CvCaptureCAM_V4L *capture, char *deviceName); void mainloop_v4l2(CvCaptureCAM_V4L* capture); int read_frame_v4l2(CvCaptureCAM_V4L* capture); void cvRetrieveRawFrame( CvCaptureCAM_V4L* capture); unsigned int n_buffers ; }; } // end namespace sensor } // end namespace flair #endif // V4LCamera_H