- Timestamp:
- Nov 30, 2018, 5:00:46 PM (6 years ago)
- Location:
- trunk/lib/FlairVisionFilter/src
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairVisionFilter/src/OpticalFlowSpeed.cpp
r214 r274 16 16 #include <Matrix.h> 17 17 #include <Object.h> 18 #include <Layout.h> 19 #include <GroupBox.h> 20 #include <SpinBox.h> 21 #include <CheckBox.h> 22 #include <DoubleSpinBox.h> 18 23 19 24 using std::string; 20 25 using namespace flair::core; 26 using namespace flair::gui; 21 27 22 namespace flair 23 { 24 namespace filter 25 { 28 namespace flair { namespace filter { 26 29 27 OpticalFlowSpeed::OpticalFlowSpeed(const IODevice* parent,string name) : IODevice(parent,name) 28 { 30 OpticalFlowSpeed::OpticalFlowSpeed(const IODevice* parent, const LayoutPosition* position,string name) : IODevice(parent,name) { 29 31 cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1); 30 32 desc->SetElementName(0,0,"vx"); … … 33 35 delete desc; 34 36 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); 38 43 } 39 44 40 OpticalFlowSpeed::~OpticalFlowSpeed(void) 41 { 42 } 45 OpticalFlowSpeed::~OpticalFlowSpeed(void) { } 43 46 44 void OpticalFlowSpeed::UpdateFrom(const io_data *data) 45 { 47 void OpticalFlowSpeed::UpdateFrom(const io_data *data) { 46 48 OpticalFlowData *input=(OpticalFlowData*)data; 47 49 float deplx,deply; 48 int nb_depl=0;50 float nb_depl=0; 49 51 50 52 deplx=0; 51 53 deply=0; 52 54 55 //error is 0 if perfect match and 7x7x255x255 at worst 56 float qualityThreshold=quality->Value()/100.*7*7*255*255; 53 57 input->GetMutex(); 58 int nbUsedPoints=0; 54 59 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; 59 71 } 60 72 } 61 73 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.; 63 77 output->SetDataTime(data->DataTime()); 64 78 65 79 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)); 68 83 } 69 84 // output->SetDataTime(data->DataTime()); 70 85 ProcessUpdate(output); 71 86 } 72 87 73 float OpticalFlowSpeed::Vx(void) const 74 { 88 float OpticalFlowSpeed::Vx(void) const { 75 89 return output->Value(0,0); 76 90 } 77 91 78 float OpticalFlowSpeed::Vy(void) const 79 { 92 float OpticalFlowSpeed::Vy(void) const { 80 93 return output->Value(1,0); 81 94 } 82 95 83 core::Matrix *OpticalFlowSpeed::Output() const 84 { 96 core::Matrix *OpticalFlowSpeed::Output() const { 85 97 return output; 86 98 } -
trunk/lib/FlairVisionFilter/src/OpticalFlowSpeed.h
r214 r274 19 19 class Matrix; 20 20 } 21 namespace gui { 22 class LayoutPosition; 23 class SpinBox; 24 class DoubleSpinBox; 25 class CheckBox; 26 } 21 27 } 22 28 … … 31 37 * \brief Optical flow speed calculation 32 38 * 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. 34 40 */ 35 41 class OpticalFlowSpeed : public core::IODevice … … 44 50 * \param name name 45 51 */ 46 OpticalFlowSpeed(const core::IODevice* parent, std::string name);52 OpticalFlowSpeed(const core::IODevice* parent, const gui::LayoutPosition* position,std::string name); 47 53 48 54 /*! … … 67 73 * \brief Output matrix 68 74 * 69 * Matrix is of s ize (2,1). \n75 * Matrix is of sze (2,1). \n 70 76 * First line is speed along x axis. \n 71 77 * Second line is speed along y axis. \n … … 84 90 85 91 core::Matrix *output; 86 }; 92 gui::DoubleSpinBox *quality; 93 gui::CheckBox *weightedAverage; 94 gui::CheckBox *timeMultiplication; 95 }; 96 87 97 } // end namespace filter 88 98 } // end namespace flair
Note:
See TracChangeset
for help on using the changeset viewer.