Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/V4LCamera.cpp

    r3 r15  
    3030using namespace flair::gui;
    3131
    32 namespace flair
    33 {
    34 namespace sensor
    35 {
     32namespace flair {
     33namespace sensor {
    3634
    37 V4LCamera::V4LCamera(const FrameworkManager* parent,string name,uint8_t camera_index,uint16_t width,uint16_t height,cvimage::Type::Format format,uint8_t priority) : Thread(parent,name,priority), Camera(parent,name,width,height,format)
    38 {
    39     capture = cvCaptureFromCAM(camera_index);//a mettre apres l'init dsp
     35V4LCamera::V4LCamera(const FrameworkManager *parent, string name,
     36                     uint8_t camera_index, uint16_t width, uint16_t height,
     37                     cvimage::Type::Format format, uint8_t priority)
     38    : Thread(parent, name, priority),
     39      Camera(parent, name, width, height, format) {
     40  capture = cvCaptureFromCAM(camera_index); // a mettre apres l'init dsp
    4041
    41     if(capture<0) Thread::Err("cvCaptureFromCAM error\n");
     42  if (capture < 0)
     43    Thread::Err("cvCaptureFromCAM error\n");
    4244
    43     if(cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,width)<0) Thread::Err("cvSetCaptureProperty error\n");
    44     if(cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,height)<0) Thread::Err("cvSetCaptureProperty error\n");
     45  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width) < 0)
     46    Thread::Err("cvSetCaptureProperty error\n");
     47  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height) < 0)
     48    Thread::Err("cvSetCaptureProperty error\n");
    4549
    46     if(format==cvimage::Type::Format::UYVY)
    47     {
    48         if(cvSetCaptureProperty(capture,CV_CAP_PROP_FORMAT,V4L2_PIX_FMT_UYVY)<0) Thread::Err("cvSetCaptureProperty error\n");
    49     }
    50     else if(format==cvimage::Type::Format::YUYV)
    51     {
    52         if(cvSetCaptureProperty(capture,CV_CAP_PROP_FORMAT,V4L2_PIX_FMT_YUYV)<0) Thread::Err("cvSetCaptureProperty error\n");
    53     }
    54     else
    55     {
    56         Thread::Err("format not supported\n");
     50  if (format == cvimage::Type::Format::UYVY) {
     51    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY) <
     52        0)
     53      Thread::Err("cvSetCaptureProperty error\n");
     54  } else if (format == cvimage::Type::Format::YUYV) {
     55    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_YUYV) <
     56        0)
     57      Thread::Err("cvSetCaptureProperty error\n");
     58  } else {
     59    Thread::Err("format not supported\n");
     60  }
     61
     62  // station sol
     63  gain = new DoubleSpinBox(GetGroupBox()->NewRow(), "gain:", 0, 1, 0.1);
     64  exposure = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "exposure:", 0,
     65                               1, 0.1);
     66  bright =
     67      new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "bright:", 0, 1, 0.1);
     68  contrast = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "contrast:", 0,
     69                               1, 0.1);
     70  hue = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "hue:", 0, 1, 0.1);
     71  sharpness = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "sharpness:",
     72                                0, 1, 0.1);
     73  sat = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "saturation:", 0, 1,
     74                          0.1);
     75  autogain = new CheckBox(GetGroupBox()->NewRow(), "autogain:");
     76  autoexposure = new CheckBox(GetGroupBox()->LastRowLastCol(), "autoexposure:");
     77  awb = new CheckBox(GetGroupBox()->LastRowLastCol(), "awb:");
     78  fps = new Label(GetGroupBox()->NewRow(), "fps");
     79}
     80
     81V4LCamera::~V4LCamera() {
     82  SafeStop();
     83  Join();
     84}
     85
     86void V4LCamera::Run(void) {
     87  Time cam_time, new_time, fpsNow, fpsPrev;
     88  IplImage *img; // raw image
     89  int fpsCounter = 0;
     90
     91  // init image old
     92  if (!cvGrabFrame(capture)) {
     93    Printf("Could not grab a frame\n");
     94  }
     95  cam_time = GetTime();
     96  fpsPrev = cam_time;
     97
     98  while (!ToBeStopped()) {
     99    // fps counter
     100    fpsCounter++;
     101    if (fpsCounter == 100) {
     102      fpsNow = GetTime();
     103      fps->SetText("fps: %.1f",
     104                   fpsCounter / ((float)(fpsNow - fpsPrev) / 1000000000.));
     105      fpsCounter = 0;
     106      fpsPrev = fpsNow;
    57107    }
    58108
    59     //station sol
    60     gain=new DoubleSpinBox(GetGroupBox()->NewRow(),"gain:",0,1,0.1);
    61     exposure=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"exposure:",0,1,0.1);
    62     bright=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"bright:",0,1,0.1);
    63     contrast=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"contrast:",0,1,0.1);
    64     hue=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"hue:",0,1,0.1);
    65     sharpness=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"sharpness:",0,1,0.1);
    66     sat=new DoubleSpinBox(GetGroupBox()->LastRowLastCol(),"saturation:",0,1,0.1);
    67     autogain=new CheckBox(GetGroupBox()->NewRow(),"autogain:");
    68     autoexposure=new CheckBox(GetGroupBox()->LastRowLastCol(),"autoexposure:");
    69     awb=new CheckBox(GetGroupBox()->LastRowLastCol(),"awb:");
    70     fps=new Label(GetGroupBox()->NewRow(),"fps");
     109    // cam properties
     110    if (gain->ValueChanged() == true && autogain->Value() == false)
     111      SetGain(gain->Value());
     112    if (exposure->ValueChanged() == true && autoexposure->Value() == false)
     113      SetExposure(exposure->Value());
     114    if (bright->ValueChanged() == true)
     115      SetBrightness(bright->Value());
     116    if (sat->ValueChanged() == true)
     117      SetSaturation(sat->Value());
     118    if (contrast->ValueChanged() == true)
     119      SetContrast(contrast->Value());
     120    if (hue->ValueChanged() == true)
     121      SetHue(hue->Value());
     122    if (sharpness->ValueChanged() == true)
     123      cvSetCaptureProperty(capture, CV_CAP_PROP_SHARPNESS, sharpness->Value());
     124    if (autogain->ValueChanged() == true) {
     125      if (autogain->Value() == true) {
     126        gain->setEnabled(false);
     127      } else {
     128        gain->setEnabled(true);
     129        SetGain(gain->Value());
     130      }
     131      SetAutoGain(autogain->Value());
     132    }
     133    if (autoexposure->ValueChanged() == true) {
     134      if (autoexposure->Value() == true) {
     135        exposure->setEnabled(false);
     136      } else {
     137        exposure->setEnabled(true);
     138        SetExposure(exposure->Value());
     139      }
     140      SetAutoExposure(autoexposure->Value());
     141    }
     142    if (awb->ValueChanged() == true)
     143      cvSetCaptureProperty(capture, CV_CAP_PROP_AWB, awb->Value());
     144
     145    // cam pictures
     146    img = cvRetrieveRawFrame(capture);
     147    if (!cvGrabFrame(capture)) {
     148      Printf("Could not grab a frame\n");
     149    }
     150    new_time = GetTime();
     151
     152    output->GetMutex();
     153    output->img->imageData = img->imageData;
     154    output->ReleaseMutex();
     155
     156    output->SetDataTime(cam_time);
     157    ProcessUpdate(output);
     158
     159    cam_time = new_time;
     160  }
     161
     162  cvReleaseCapture(&capture);
    71163}
    72164
    73 V4LCamera::~V4LCamera()
    74 {
    75     SafeStop();
    76     Join();
     165void V4LCamera::SetAutoGain(bool value) {
     166  cvSetCaptureProperty(capture, CV_CAP_PROP_AUTOGAIN, value);
    77167}
    78168
    79 void V4LCamera::Run(void)
    80 {
    81     Time cam_time,new_time,fpsNow,fpsPrev;
    82     IplImage* img;//raw image
    83     int fpsCounter=0;
    84 
    85     //init image old
    86     if(!cvGrabFrame(capture))
    87     {
    88         Printf("Could not grab a frame\n");
    89     }
    90     cam_time=GetTime();
    91     fpsPrev = cam_time;
    92 
    93     while(!ToBeStopped())
    94     {
    95         //fps counter
    96         fpsCounter++;
    97         if(fpsCounter==100) {
    98             fpsNow = GetTime();
    99             fps->SetText("fps: %.1f",fpsCounter/((float)(fpsNow - fpsPrev)/1000000000.));
    100             fpsCounter=0;
    101             fpsPrev=fpsNow;
    102         }
    103 
    104         //cam properties
    105         if(gain->ValueChanged()==true && autogain->Value()==false) SetGain(gain->Value());
    106         if(exposure->ValueChanged()==true && autoexposure->Value()==false) SetExposure(exposure->Value());
    107         if(bright->ValueChanged()==true) SetBrightness(bright->Value());
    108         if(sat->ValueChanged()==true) SetSaturation(sat->Value());
    109         if(contrast->ValueChanged()==true) SetContrast(contrast->Value());
    110         if(hue->ValueChanged()==true) SetHue(hue->Value());
    111         if(sharpness->ValueChanged()==true) cvSetCaptureProperty(capture,CV_CAP_PROP_SHARPNESS,sharpness->Value());
    112         if(autogain->ValueChanged()==true)
    113         {
    114             if(autogain->Value()==true)
    115             {
    116                 gain->setEnabled(false);
    117             }
    118             else
    119             {
    120                 gain->setEnabled(true);
    121                 SetGain(gain->Value());
    122             }
    123             SetAutoGain(autogain->Value());
    124         }
    125         if(autoexposure->ValueChanged()==true)
    126         {
    127             if(autoexposure->Value()==true)
    128             {
    129                 exposure->setEnabled(false);
    130             }
    131             else
    132             {
    133                 exposure->setEnabled(true);
    134                 SetExposure(exposure->Value());
    135             }
    136             SetAutoExposure(autoexposure->Value());
    137         }
    138         if(awb->ValueChanged()==true) cvSetCaptureProperty(capture,CV_CAP_PROP_AWB,awb->Value());
    139 
    140 
    141         //cam pictures
    142         img=cvRetrieveRawFrame(capture);
    143         if(!cvGrabFrame(capture))
    144         {
    145             Printf("Could not grab a frame\n");
    146         }
    147         new_time=GetTime();
    148 
    149         output->GetMutex();
    150         output->img->imageData=img->imageData;
    151         output->ReleaseMutex();
    152 
    153         output->SetDataTime(cam_time);
    154         ProcessUpdate(output);
    155 
    156         cam_time=new_time;
    157     }
    158 
    159     cvReleaseCapture(&capture);
     169void V4LCamera::SetAutoExposure(bool value) {
     170  Thread::Warn("not implemented in opencv\n");
    160171}
    161172
    162 void V4LCamera::SetAutoGain(bool value)
    163 {
    164     cvSetCaptureProperty(capture,CV_CAP_PROP_AUTOGAIN,value);
     173void V4LCamera::SetGain(float value) {
     174  cvSetCaptureProperty(capture, CV_CAP_PROP_GAIN, value);
    165175}
    166176
    167 void V4LCamera::SetAutoExposure(bool value)
    168 {
    169     Thread::Warn("not implemented in opencv\n");
     177void V4LCamera::SetExposure(float value) {
     178  cvSetCaptureProperty(capture, CV_CAP_PROP_EXPOSURE, value);
    170179}
    171180
    172 void V4LCamera::SetGain(float value)
    173 {
    174     cvSetCaptureProperty(capture,CV_CAP_PROP_GAIN,value);
     181void V4LCamera::SetBrightness(float value) {
     182  cvSetCaptureProperty(capture, CV_CAP_PROP_BRIGHTNESS, value);
    175183}
    176184
    177 void V4LCamera::SetExposure(float value)
    178 {
    179     cvSetCaptureProperty(capture,CV_CAP_PROP_EXPOSURE,value);
     185void V4LCamera::SetSaturation(float value) {
     186  cvSetCaptureProperty(capture, CV_CAP_PROP_SATURATION, value);
    180187}
    181188
    182 void V4LCamera::SetBrightness(float value)
    183 {
    184     cvSetCaptureProperty(capture,CV_CAP_PROP_BRIGHTNESS,value);
     189void V4LCamera::SetHue(float value) {
     190  cvSetCaptureProperty(capture, CV_CAP_PROP_HUE, value);
    185191}
    186192
    187 void V4LCamera::SetSaturation(float value)
    188 {
    189     cvSetCaptureProperty(capture,CV_CAP_PROP_SATURATION,value);
    190 }
    191 
    192 void V4LCamera::SetHue(float value)
    193 {
    194     cvSetCaptureProperty(capture,CV_CAP_PROP_HUE,value);
    195 }
    196 
    197 void V4LCamera::SetContrast(float value)
    198 {
    199     cvSetCaptureProperty(capture,CV_CAP_PROP_CONTRAST,value);
     193void V4LCamera::SetContrast(float value) {
     194  cvSetCaptureProperty(capture, CV_CAP_PROP_CONTRAST, value);
    200195}
    201196
Note: See TracChangeset for help on using the changeset viewer.