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

Last change on this file since 143 was 143, checked in by Bayard Gildas, 5 years ago

Plop

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
34 AddDataToLog(output);
35}
36
37OpticalFlowSpeed::~OpticalFlowSpeed(void)
38{
39}
40
41void 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 if(input->FoundFeature()[i]!=0) {
53 deplx+=input->PointsB()[i].x-input->PointsA()[i].x;
54 deply+=input->PointsB()[i].y-input->PointsA()[i].y;
55 nb_depl++;
56 }
57 }
58 input->ReleaseMutex();
59 Time deltaT=data->DataTime()-output->DataTime();
60 output->SetDataTime(data->DataTime());
61
62 if(nb_depl!=0) {
63 output->SetValue(0,0,deplx/(nb_depl*deltaT)*1000*1000*1000);
64 output->SetValue(1,0,deply/(nb_depl*deltaT)*1000*1000*1000);
65 }
66
67 ProcessUpdate(output);
68}
69
70float OpticalFlowSpeed::Vx(void) const
71{
72 return output->Value(0,0);
73}
74
75float OpticalFlowSpeed::Vy(void) const
76{
77 return output->Value(1,0);
78}
79
80core::cvmatrix *OpticalFlowSpeed::Output() const
81{
82 return output;
83}
84} // end namespace filter
85} // end namespace flair
Note: See TracBrowser for help on using the repository browser.