| 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"
|
---|
| 16 | #include <cvmatrix.h>
|
---|
| 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 | {
|
---|
| 29 | cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
|
---|
| 30 | desc->SetElementName(0,0,"vx");
|
---|
| 31 | desc->SetElementName(1,0,"vy");
|
---|
| 32 | output=new cvmatrix(this,desc,floatType,name);
|
---|
| 33 |
|
---|
| 34 | AddDataToLog(output);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | OpticalFlowSpeed::~OpticalFlowSpeed(void)
|
---|
| 38 | {
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | void OpticalFlowSpeed::UpdateFrom(const io_data *data)
|
---|
| 42 | {
|
---|
| 43 | OpticalFlowData *input=(OpticalFlowData*)data;
|
---|
| 44 | float deplx,deply;
|
---|
| 45 | int nb_depl=0;
|
---|
| 46 |
|
---|
| 47 | deplx=0;
|
---|
| 48 | deply=0;
|
---|
| 49 |
|
---|
| 50 | input->GetMutex();
|
---|
| 51 | for(int i=0;i<input->NbFeatures();i++)
|
---|
| 52 | {
|
---|
| 53 | if(input->FoundFeature()[i]!=0)
|
---|
| 54 | {
|
---|
| 55 | deplx+=input->PointsB()[i].x-input->PointsA()[i].x;
|
---|
| 56 | deply+=input->PointsB()[i].y-input->PointsA()[i].y;
|
---|
| 57 | nb_depl++;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | input->ReleaseMutex();
|
---|
| 61 |
|
---|
| 62 | if(nb_depl!=0)
|
---|
| 63 | {
|
---|
| 64 | output->SetValue(0,0,deplx/nb_depl);
|
---|
| 65 | output->SetValue(1,0,deply/nb_depl);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | output->SetDataTime(data->DataTime());
|
---|
| 69 | ProcessUpdate(output);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | float OpticalFlowSpeed::Vx(void) const
|
---|
| 73 | {
|
---|
| 74 | return output->Value(0,0);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | float OpticalFlowSpeed::Vy(void) const
|
---|
| 78 | {
|
---|
| 79 | return output->Value(1,0);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | core::cvmatrix *OpticalFlowSpeed::Output() const
|
---|
| 83 | {
|
---|
| 84 | return output;
|
---|
| 85 | }
|
---|
| 86 | } // end namespace filter
|
---|
| 87 | } // end namespace flair
|
---|