[122] | 1 | // created: 2012/04/12
|
---|
| 2 | // filename: OpticalFlowSpeed.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Guillaume Sanahuja
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: calcul de la vitesse à partir du flux optique
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | /*********************************************************************/
|
---|
| 13 |
|
---|
| 14 | #include "OpticalFlowSpeed.h"
|
---|
| 15 | #include "OpticalFlowData.h"
|
---|
[214] | 16 | #include <Matrix.h>
|
---|
[122] | 17 | #include <Object.h>
|
---|
| 18 |
|
---|
| 19 | using std::string;
|
---|
| 20 | using namespace flair::core;
|
---|
| 21 |
|
---|
| 22 | namespace flair
|
---|
| 23 | {
|
---|
| 24 | namespace filter
|
---|
| 25 | {
|
---|
| 26 |
|
---|
| 27 | OpticalFlowSpeed::OpticalFlowSpeed(const IODevice* parent,string name) : IODevice(parent,name)
|
---|
| 28 | {
|
---|
[148] | 29 | cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
|
---|
| 30 | desc->SetElementName(0,0,"vx");
|
---|
| 31 | desc->SetElementName(1,0,"vy");
|
---|
[214] | 32 | output=new Matrix(this,desc,floatType,name);
|
---|
[148] | 33 | delete desc;
|
---|
[122] | 34 |
|
---|
| 35 | AddDataToLog(output);
|
---|
[157] | 36 |
|
---|
| 37 | SetIsReady(true);
|
---|
[122] | 38 | }
|
---|
| 39 |
|
---|
| 40 | OpticalFlowSpeed::~OpticalFlowSpeed(void)
|
---|
| 41 | {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | void OpticalFlowSpeed::UpdateFrom(const io_data *data)
|
---|
| 45 | {
|
---|
| 46 | OpticalFlowData *input=(OpticalFlowData*)data;
|
---|
| 47 | float deplx,deply;
|
---|
| 48 | int nb_depl=0;
|
---|
| 49 |
|
---|
| 50 | deplx=0;
|
---|
| 51 | deply=0;
|
---|
| 52 |
|
---|
| 53 | input->GetMutex();
|
---|
[143] | 54 | for(int i=0;i<input->NbFeatures();i++) {
|
---|
| 55 | if(input->FoundFeature()[i]!=0) {
|
---|
[122] | 56 | deplx+=input->PointsB()[i].x-input->PointsA()[i].x;
|
---|
| 57 | deply+=input->PointsB()[i].y-input->PointsA()[i].y;
|
---|
| 58 | nb_depl++;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | input->ReleaseMutex();
|
---|
[143] | 62 | Time deltaT=data->DataTime()-output->DataTime();
|
---|
| 63 | output->SetDataTime(data->DataTime());
|
---|
[122] | 64 |
|
---|
[143] | 65 | 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);
|
---|
[122] | 68 | }
|
---|
| 69 |
|
---|
| 70 | ProcessUpdate(output);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | float OpticalFlowSpeed::Vx(void) const
|
---|
| 74 | {
|
---|
| 75 | return output->Value(0,0);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | float OpticalFlowSpeed::Vy(void) const
|
---|
| 79 | {
|
---|
| 80 | return output->Value(1,0);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[214] | 83 | core::Matrix *OpticalFlowSpeed::Output() const
|
---|
[122] | 84 | {
|
---|
| 85 | return output;
|
---|
| 86 | }
|
---|
| 87 | } // end namespace filter
|
---|
| 88 | } // end namespace flair
|
---|