source: flair-src/trunk/lib/FlairSensorActuator/src/V4LCamera.cpp@ 352

Last change on this file since 352 was 352, checked in by Sanahuja Guillaume, 4 years ago

v4lcamera: use pimpl

File size: 4.4 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// created: 2014/07/17
6// filename: V4LCamera.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: base class for V4l camera
14//
15//
16/*********************************************************************/
17
18#include "V4LCamera.h"
[352]19#include "V4LCamera_impl.h"
[338]20#include <Image.h>
[3]21#include <FrameworkManager.h>
[330]22
[3]23using std::string;
24using namespace flair::core;
25
[15]26namespace flair {
27namespace sensor {
[340]28
[346]29V4LCamera::V4LCamera(string name,uint8_t camera_index, uint16_t width, uint16_t height,
[340]30 Image::Type::Format format, uint8_t priority)
[351]31 : Thread(getFrameworkManager(), name, priority),
[340]32 Camera(name, width, height, format) {
33
[352]34 pimpl_=new V4LCamera_impl(this,name,camera_index,width,height,format);
[340]35}
36
37V4LCamera::~V4LCamera() {
[346]38 SafeStop();
39 Join();
[352]40 delete pimpl_;
[340]41}
42
43void V4LCamera::Run(void) {
[352]44 pimpl_->Run();
45 /*
[340]46 Time cam_time, new_time, fpsNow, fpsPrev;
47 int fpsCounter = 0;
48
49 cam_time = GetTime();
50 fpsPrev = cam_time;
51
52 while (!ToBeStopped()) {
53 // fps counter
54 fpsCounter++;
55 if (fpsCounter == 100) {
56 fpsNow = GetTime();
57 fps->SetText("fps: %.1f",
58 fpsCounter / ((float)(fpsNow - fpsPrev) / 1000000000.));
59 fpsCounter = 0;
60 fpsPrev = fpsNow;
61 }
62
63 // cam properties
64 if (gain->ValueChanged() == true && autogain->Value() == false)
65 SetGain(gain->Value());
66 if (exposure->ValueChanged() == true && autoexposure->Value() == false)
67 SetExposure(exposure->Value());
68 if (bright->ValueChanged() == true)
69 SetBrightness(bright->Value());
70 if (sat->ValueChanged() == true)
71 SetSaturation(sat->Value());
72 if (contrast->ValueChanged() == true)
73 SetContrast(contrast->Value());
74 if (hue->ValueChanged() == true)
75 SetHue(hue->Value());
76 //if (sharpness->ValueChanged() == true)
77 // cvSetCaptureProperty(capture, CV_CAP_PROP_SHARPNESS, sharpness->Value());
78 if (autogain->ValueChanged() == true) {
79 if (autogain->Value() == true) {
80 gain->setEnabled(false);
81 } else {
82 gain->setEnabled(true);
83 SetGain(gain->Value());
84 }
85 SetAutoGain(autogain->Value());
86 }
87 if (autoexposure->ValueChanged() == true) {
88 if (autoexposure->Value() == true) {
89 exposure->setEnabled(false);
90 } else {
91 exposure->setEnabled(true);
92 SetExposure(exposure->Value());
93 }
94 SetAutoExposure(autoexposure->Value());
95 }
96 //if (awb->ValueChanged() == true)
97 // cvSetCaptureProperty(capture, CV_CAP_PROP_AWB, awb->Value());
98
99 // cam pictures
[351]100 if (!GrabFrame()) {
[340]101 Printf("Could not grab a frame\n");
102 }
103
104 //check for ps3eye deconnection in hds uav
[350]105 new_time = GetTime();
[340]106 if(new_time-cam_time>100*1000*1000) {
[350]107 Thread::Warn("delta t trop grand\n");
[340]108 hasProblems=true;
[352]109 }
[340]110
[351]111 //select buffer
112 if(useMemoryUsrPtr) {//buffers are already in CMEM
113 imageData=(char*)buffers[dQueuedBuffer.index];
114 //dequeue it latter (buffer used by ProcessUpdate)
115 } else {//copy to CMEM allocated buffer
116 memcpy(imageData,(char *)buffers[dQueuedBuffer.index],output->GetDataType().GetSize());
117 QueueBuffer(&dQueuedBuffer);//we can do it right now
118 }
119
[340]120 output->GetMutex();
[348]121 output->buffer=imageData;
[340]122 output->ReleaseMutex();
123
124 output->SetDataTime(cam_time);
125 ProcessUpdate(output);
126 cam_time = new_time;
[351]127
128 if(useMemoryUsrPtr) {
129 QueueBuffer(&dQueuedBuffer);//now it is possible to dequeue
130 }
[340]131 }
[352]132 */
[348]133}
[340]134
[165]135bool V4LCamera::HasProblems(void) {
[352]136 return pimpl_->hasProblems;
[165]137}
138
[15]139void V4LCamera::SetAutoGain(bool value) {
[352]140 pimpl_->SetAutoGain(value);
[3]141}
142
[15]143void V4LCamera::SetAutoExposure(bool value) {
[338]144 Thread::Warn("not implemented\n");
[3]145}
146
[15]147void V4LCamera::SetGain(float value) {
[352]148 pimpl_->SetGain(value);
[3]149}
150
[15]151void V4LCamera::SetExposure(float value) {
[352]152 pimpl_->SetExposure(value);
[3]153}
154
[15]155void V4LCamera::SetBrightness(float value) {
[352]156 pimpl_->SetBrightness(value);
[3]157}
158
[15]159void V4LCamera::SetSaturation(float value) {
[352]160 pimpl_->SetSaturation(value);
[3]161}
162
[15]163void V4LCamera::SetHue(float value) {
[352]164 pimpl_->SetHue(value);
[3]165}
166
[15]167void V4LCamera::SetContrast(float value) {
[352]168 pimpl_->SetContrast(value);
[3]169}
170
171} // end namespace sensor
172} // end namespace flair
Note: See TracBrowser for help on using the repository browser.