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

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

modifs uav vrpn i686

File size: 1.8 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 {
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
72float OpticalFlowSpeed::Vx(void) const
73{
74 return output->Value(0,0);
75}
76
77float OpticalFlowSpeed::Vy(void) const
78{
79 return output->Value(1,0);
80}
81
82core::cvmatrix *OpticalFlowSpeed::Output() const
83{
84 return output;
85}
86} // end namespace filter
87} // end namespace flair
Note: See TracBrowser for help on using the repository browser.