Ignore:
Timestamp:
11/30/18 17:00:46 (5 years ago)
Author:
Sanahuja Guillaume
Message:

opticalflow modif

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.