source: flair-src/branches/sanscv/lib/FlairVisionFilter/src/OpticalFlowData.cpp @ 324

Last change on this file since 324 was 324, checked in by Sanahuja Guillaume, 2 years ago

removing opencv dependency

File size: 3.9 KB
Line 
1//  created:    2012/04/12
2//  filename:   OpticalFlowData.cpp
3//
4//  author:     Guillaume Sanahuja
5//              Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7//  version:    $Id: $
8//
9//  purpose:    classe pour les données du flux optique
10//
11/*********************************************************************/
12
13#include "OpticalFlowData.h"
14#include <cstring>
15
16using std::string;
17
18namespace flair
19{
20namespace filter
21{
22
23OpticalFlowData::OpticalFlowData(const Object* parent,uint32_t max_features,string name,uint32_t n): io_data(parent,name,n)
24{
25    this->max_features=max_features;
26    nb_features=0;
27
28    pointsA=(CvPoint *)malloc(max_features*sizeof(CvPoint));
29    pointsB=(CvPoint2D32f *)malloc(max_features*sizeof(CvPoint2D32f));
30
31    found_features=(char *)malloc(max_features*sizeof(char));
32    features_error=(uint32_t*)malloc(max_features*sizeof(uint32_t));
33}
34
35OpticalFlowData::~OpticalFlowData()
36{
37    free(pointsA);
38    free(pointsB);
39
40    free(found_features);
41    free(features_error);
42}
43
44CvPoint* OpticalFlowData::PointsA(void) const
45{
46    return pointsA;
47}
48
49CvPoint2D32f* OpticalFlowData::PointsB(void) const
50{
51    return pointsB;
52}
53
54char *OpticalFlowData::FoundFeature(void) const
55{
56    return found_features;
57}
58
59uint32_t *OpticalFlowData::FeatureError(void) const
60{
61    return features_error;
62}
63
64// value is new max_features value
65void OpticalFlowData::Resize(uint32_t value) {
66    CvPoint *new_pointsA;
67    CvPoint2D32f *new_pointsB;
68    char *new_found_features;
69    uint32_t *new_features_error;
70
71    new_pointsA=(CvPoint *)malloc(value*sizeof(CvPoint));
72    new_pointsB=(CvPoint2D32f *)malloc(value*sizeof(CvPoint2D32f));
73    new_found_features=(char *)malloc(value*sizeof(char));
74    new_features_error=(uint32_t *)malloc(value*sizeof(uint32_t));
75
76    GetMutex();
77    if(value>max_features) {
78        memcpy(new_pointsA,pointsA,max_features*sizeof(CvPoint));
79        memcpy(new_pointsB,pointsB,max_features*sizeof(CvPoint2D32f));
80        memcpy(new_found_features,found_features,max_features*sizeof(char));
81        memcpy(new_features_error,features_error,max_features*sizeof(uint32_t));
82    }
83    else {
84        memcpy(new_pointsA,pointsA,value*sizeof(CvPoint));
85        memcpy(new_pointsB,pointsB,value*sizeof(CvPoint2D32f));
86        memcpy(new_found_features,found_features,value*sizeof(char));
87        memcpy(new_features_error,features_error,value*sizeof(uint32_t));
88        if(nb_features>value) nb_features=value; //si nb_features est le nombre de point qui ont effectivement une correspondande, ça me parait louche. Sauf si les points sont classés et que ceux qui ont une correpondance sont toujours au début
89    }
90    max_features=value;
91    ReleaseMutex();
92
93    free(pointsA);
94    free(pointsB);
95    free(found_features);
96    free(features_error);
97
98    pointsA=new_pointsA;
99    pointsB=new_pointsB;
100    found_features=new_found_features;
101    features_error=new_features_error;
102}
103
104void OpticalFlowData::RawRead(char* dst) const
105{
106    Warn("non implementé\n");
107}
108
109void OpticalFlowData::SetPointsA(const CvPoint* points)
110{
111    GetMutex();
112    memcpy(pointsA,points,max_features*sizeof(CvPoint));
113    ReleaseMutex();
114}
115
116void OpticalFlowData::SetPointsB(const CvPoint2D32f* points)
117{
118    GetMutex();
119    memcpy(pointsB,points,max_features*sizeof(CvPoint2D32f));
120    ReleaseMutex();
121}
122
123void OpticalFlowData::SetFoundFeature(const char *found_features)
124{
125    GetMutex();
126    memcpy(this->found_features,found_features,max_features*sizeof(char));
127    ReleaseMutex();
128}
129
130void OpticalFlowData::SetFeatureError(const uint32_t *features_error)
131{
132    GetMutex();
133    memcpy(this->features_error,features_error,max_features*sizeof(uint32_t));
134    ReleaseMutex();
135}
136
137uint32_t OpticalFlowData::MaxFeatures(void) const
138{
139    return max_features;
140}
141
142uint32_t OpticalFlowData::NbFeatures(void) const
143{
144    return nb_features;
145}
146
147void OpticalFlowData::SetNbFeatures(uint32_t value)
148{
149    GetMutex();
150    nb_features=value;
151    ReleaseMutex();
152}
153
154} // end namespace filter
155} // end namespace flair
Note: See TracBrowser for help on using the repository browser.