source: flair-src/trunk/lib/FlairVisionFilter/src/OpticalFlowSpeed.cpp@ 148

Last change on this file since 148 was 148, checked in by Sanahuja Guillaume, 5 years ago

m

File size: 1.9 KB
Line 
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
19using std::string;
20using namespace flair::core;
21
22namespace flair
23{
24namespace filter
25{
26
27OpticalFlowSpeed::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 delete desc;
34
35 AddDataToLog(output);
36}
37
38OpticalFlowSpeed::~OpticalFlowSpeed(void)
39{
40}
41
42void OpticalFlowSpeed::UpdateFrom(const io_data *data)
43{
44 OpticalFlowData *input=(OpticalFlowData*)data;
45 float deplx,deply;
46 int nb_depl=0;
47
48 deplx=0;
49 deply=0;
50
51 input->GetMutex();
52 for(int i=0;i<input->NbFeatures();i++) {
53 if(input->FoundFeature()[i]!=0) {
54 deplx+=input->PointsB()[i].x-input->PointsA()[i].x;
55 deply+=input->PointsB()[i].y-input->PointsA()[i].y;
56 nb_depl++;
57 }
58 }
59 input->ReleaseMutex();
60 Time deltaT=data->DataTime()-output->DataTime();
61 output->SetDataTime(data->DataTime());
62
63 if(nb_depl!=0) {
64 output->SetValue(0,0,deplx/(nb_depl*deltaT)*1000*1000*1000);
65 output->SetValue(1,0,deply/(nb_depl*deltaT)*1000*1000*1000);
66 }
67
68 ProcessUpdate(output);
69}
70
71float OpticalFlowSpeed::Vx(void) const
72{
73 return output->Value(0,0);
74}
75
76float OpticalFlowSpeed::Vy(void) const
77{
78 return output->Value(1,0);
79}
80
81core::cvmatrix *OpticalFlowSpeed::Output() const
82{
83 return output;
84}
85} // end namespace filter
86} // end namespace flair
Note: See TracBrowser for help on using the repository browser.