Changeset 274 in flair-src


Ignore:
Timestamp:
Nov 30, 2018, 5:00:46 PM (6 years ago)
Author:
Sanahuja Guillaume
Message:

opticalflow modif

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.cpp

    r214 r274  
    6363  opticalFlow=new OpticalFlow(greyCameraImage,uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique");
    6464  opticalFlowCompensated=new OpticalFlowCompensated(opticalFlow,uav->GetAhrs(),uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique compense");
    65   opticalFlowSpeedRaw=new OpticalFlowSpeed(opticalFlowCompensated,uav->GetAhrs(),uav->GetVerticalCamera()->GetLayout()->NewRow(),"vitesse du Flux Optique");
     65  opticalFlowSpeedRaw=new OpticalFlowSpeed(opticalFlowCompensated,uav->GetVerticalCamera()->GetLayout()->NewRow(),"vitesse du Flux Optique");
    6666  //opticalFlowSpeed=vitesse de déplacement en pixels par seconde (moyenne sur tous les points et division par le delta T)
    6767  Matrix* twoByOneOFS=new Matrix((const Thread*)this,2,1,floatType);
  • trunk/lib/FlairVisionFilter/src/OpticalFlowSpeed.cpp

    r214 r274  
    1616#include <Matrix.h>
    1717#include <Object.h>
     18#include <Layout.h>
     19#include <GroupBox.h>
     20#include <SpinBox.h>
     21#include <CheckBox.h>
     22#include <DoubleSpinBox.h>
    1823
    1924using std::string;
    2025using namespace flair::core;
     26using namespace flair::gui;
    2127
    22 namespace flair
    23 {
    24 namespace filter
    25 {
     28namespace flair { namespace filter {
    2629
    27 OpticalFlowSpeed::OpticalFlowSpeed(const IODevice* parent,string name) : IODevice(parent,name)
    28 {
     30OpticalFlowSpeed::OpticalFlowSpeed(const IODevice* parent, const LayoutPosition* position,string name) : IODevice(parent,name) {
    2931  cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
    3032  desc->SetElementName(0,0,"vx");
     
    3335  delete desc;
    3436
    35         AddDataToLog(output);
    36  
    37   SetIsReady(true);
     37  AddDataToLog(output);
     38
     39  GroupBox* reglages_groupbox=new GroupBox(position,name);
     40  quality=new DoubleSpinBox(reglages_groupbox->LastRowLastCol(),"optical flow quality:",0.,100.,1.,1,5.);
     41  weightedAverage=new CheckBox(reglages_groupbox->LastRowLastCol(),"Weighted average", true);
     42  timeMultiplication=new CheckBox(reglages_groupbox->LastRowLastCol(),"Time multiplication", true);
    3843}
    3944
    40 OpticalFlowSpeed::~OpticalFlowSpeed(void)
    41 {
    42 }
     45OpticalFlowSpeed::~OpticalFlowSpeed(void) { }
    4346
    44 void OpticalFlowSpeed::UpdateFrom(const io_data *data)
    45 {
     47void OpticalFlowSpeed::UpdateFrom(const io_data *data) {
    4648    OpticalFlowData *input=(OpticalFlowData*)data;
    4749    float deplx,deply;
    48     int nb_depl=0;
     50    float nb_depl=0;
    4951
    5052    deplx=0;
    5153    deply=0;
    5254
     55    //error is 0 if perfect match and 7x7x255x255 at worst
     56    float qualityThreshold=quality->Value()/100.*7*7*255*255;
    5357    input->GetMutex();
     58    int nbUsedPoints=0;
    5459    for(int i=0;i<input->NbFeatures();i++) {
    55         if(input->FoundFeature()[i]!=0) {
    56             deplx+=input->PointsB()[i].x-input->PointsA()[i].x;
    57             deply+=input->PointsB()[i].y-input->PointsA()[i].y;
    58             nb_depl++;
     60        //if point is found in both images and quality is sufficient
     61        if((input->FoundFeature()[i]!=0)&&(input->FeatureError()[i]<qualityThreshold)) {
     62          nbUsedPoints++;
     63          float qualityFactor=1.0;
     64          if (weightedAverage->Value()) {
     65            //displacement is weigthed by quality
     66            qualityFactor/=(1+input->FeatureError()[i]);
     67          }
     68            deplx+=(input->PointsB()[i].x-input->PointsA()[i].x)*qualityFactor;
     69            deply+=(input->PointsB()[i].y-input->PointsA()[i].y)*qualityFactor;
     70            nb_depl+=qualityFactor;
    5971        }
    6072    }
    6173    input->ReleaseMutex();
    62     Time deltaT=data->DataTime()-output->DataTime();
     74    float deltaT;
     75    if (timeMultiplication->Value()) deltaT=(float)(data->DataTime()-output->DataTime())/(1000.*1000.*1000.);
     76    else deltaT=1.;
    6377    output->SetDataTime(data->DataTime());
    6478
    6579    if(nb_depl!=0) {
    66         output->SetValue(0,0,deplx/(nb_depl*deltaT)*1000*1000*1000);
    67         output->SetValue(1,0,deply/(nb_depl*deltaT)*1000*1000*1000);
     80//Printf("Nombre de points=%d/%d (nb_depl=%f,pondération=%d), deltaT=%f\n",nbUsedPoints,input->NbFeatures(),nb_depl,weightedAverage->Value(),deltaT);
     81        output->SetValue(0,0,deplx/(nb_depl*deltaT));
     82        output->SetValue(1,0,deply/(nb_depl*deltaT));
    6883    }
    69 
     84//    output->SetDataTime(data->DataTime());
    7085    ProcessUpdate(output);
    7186}
    7287
    73 float OpticalFlowSpeed::Vx(void) const
    74 {
     88float OpticalFlowSpeed::Vx(void) const {
    7589    return output->Value(0,0);
    7690}
    7791
    78 float OpticalFlowSpeed::Vy(void) const
    79 {
     92float OpticalFlowSpeed::Vy(void) const {
    8093    return output->Value(1,0);
    8194}
    8295
    83 core::Matrix *OpticalFlowSpeed::Output() const
    84 {
     96core::Matrix *OpticalFlowSpeed::Output() const {
    8597    return output;
    8698}
  • trunk/lib/FlairVisionFilter/src/OpticalFlowSpeed.h

    r214 r274  
    1919        class Matrix;
    2020    }
     21  namespace gui {
     22    class LayoutPosition;
     23    class SpinBox;
     24    class DoubleSpinBox;
     25    class CheckBox;
     26  }
    2127}
    2228
     
    3137    * \brief Optical flow speed calculation
    3238    *
    33     * Speed is the mean of all optical flow values divided by the delta time between images.
     39    * Speed is the mean of all optical flow values.
    3440    */
    3541    class OpticalFlowSpeed : public core::IODevice
     
    4450            * \param name name
    4551            */
    46             OpticalFlowSpeed(const core::IODevice* parent,std::string name);
     52            OpticalFlowSpeed(const core::IODevice* parent, const gui::LayoutPosition* position,std::string name);
    4753
    4854            /*!
     
    6773            * \brief Output matrix
    6874            *
    69             * Matrix is of size (2,1). \n
     75            * Matrix is of sze (2,1). \n
    7076            * First line is speed along x axis. \n
    7177            * Second line is speed along y axis. \n
     
    8490
    8591            core::Matrix *output;
    86     };
     92      gui::DoubleSpinBox *quality;
     93      gui::CheckBox *weightedAverage;
     94      gui::CheckBox *timeMultiplication;
     95};
     96
    8797} // end namespace filter
    8898} // end namespace flair
Note: See TracChangeset for help on using the changeset viewer.