Changeset 338 in flair-src for trunk/lib/FlairVisionFilter/src/OpticalFlowData.cpp
- Timestamp:
- Oct 17, 2019, 2:49:35 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/sanscv merged eligible
-
Property svn:mergeinfo
set to
-
trunk/lib/FlairVisionFilter/src/OpticalFlowData.cpp
r252 r338 12 12 13 13 #include "OpticalFlowData.h" 14 #include "VisionFilter.h" 15 #include <string.h> 14 16 15 17 using std::string; 16 18 17 namespace flair 18 { 19 namespace filter 20 { 19 class OpticalFlowData_impl { 20 public: 21 OpticalFlowData_impl(flair::filter::OpticalFlowData* self,uint32_t max_features) { 22 this->self=self; 23 this->max_features=max_features; 24 nb_features=0; 25 pointsA=(IntPoint*)malloc(max_features*sizeof(IntPoint)); 26 pointsB=(FloatPoint*)malloc(max_features*sizeof(FloatPoint)); 21 27 22 OpticalFlowData::OpticalFlowData(const Object* parent,uint32_t max_features,string name,uint32_t n): io_data(parent,name,n) 23 { 24 this->max_features=max_features; 25 nb_features=0; 28 found_features=(char*)malloc(max_features*sizeof(char)); 29 features_error=(uint32_t*)malloc(max_features*sizeof(uint32_t)); 30 } 26 31 27 pointsA=(CvPoint *)cvAlloc(max_features*sizeof(CvPoint)); 28 pointsB=(CvPoint2D32f *)cvAlloc(max_features*sizeof(CvPoint2D32f)); 32 ~OpticalFlowData_impl() { 33 free((char*)pointsA); 34 free((char*)pointsB); 29 35 30 found_features=(char *)cvAlloc(max_features*sizeof(char)); 31 features_error=(uint32_t*)cvAlloc(max_features*sizeof(uint32_t)); 36 free((char*)found_features); 37 free((char*)features_error); 38 } 39 40 void Resize(uint32_t value) { 41 IntPoint *new_pointsA; 42 FloatPoint *new_pointsB; 43 char *new_found_features; 44 uint32_t *new_features_error; 45 46 new_pointsA=(IntPoint*)malloc(value*sizeof(IntPoint)); 47 new_pointsB=(FloatPoint*)malloc(value*sizeof(FloatPoint)); 48 new_found_features=(char*)malloc(value*sizeof(char)); 49 new_features_error=(uint32_t*)malloc(value*sizeof(uint32_t)); 50 51 self->GetMutex(); 52 if(value>max_features) { 53 memcpy(new_pointsA,pointsA,max_features*sizeof(IntPoint)); 54 memcpy(new_pointsB,pointsB,max_features*sizeof(FloatPoint)); 55 memcpy(new_found_features,found_features,max_features*sizeof(char)); 56 memcpy(new_features_error,features_error,max_features*sizeof(uint32_t)); 57 } else { 58 memcpy(new_pointsA,pointsA,value*sizeof(IntPoint)); 59 memcpy(new_pointsB,pointsB,value*sizeof(FloatPoint)); 60 memcpy(new_found_features,found_features,value*sizeof(char)); 61 memcpy(new_features_error,features_error,value*sizeof(uint32_t)); 62 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 63 } 64 max_features=value; 65 self->ReleaseMutex(); 66 67 free((char*)pointsA); 68 free((char*)pointsB); 69 free((char*)found_features); 70 free((char*)features_error); 71 72 pointsA=new_pointsA; 73 pointsB=new_pointsB; 74 found_features=new_found_features; 75 features_error=new_features_error; 76 } 77 78 uint32_t max_features; 79 uint32_t nb_features; 80 IntPoint* pointsA; 81 FloatPoint* pointsB; 82 char *found_features; 83 uint32_t *features_error; 84 85 private: 86 flair::filter::OpticalFlowData *self; 87 }; 88 89 namespace flair { 90 namespace filter { 91 92 OpticalFlowData::OpticalFlowData(const Object* parent,uint32_t max_features,string name,uint32_t n): io_data(parent,name,n) { 93 pimpl_=new OpticalFlowData_impl(this,max_features); 32 94 } 33 95 34 OpticalFlowData::~OpticalFlowData() 35 { 36 cvFree(&pointsA); 37 cvFree(&pointsB); 38 39 cvFree(&found_features); 40 cvFree(&features_error); 96 OpticalFlowData::~OpticalFlowData() { 97 delete pimpl_; 41 98 } 42 99 43 CvPoint* OpticalFlowData::PointsA(void) const 44 { 45 return pointsA; 100 IntPoint* OpticalFlowData::PointsA(void) const { 101 return pimpl_->pointsA; 46 102 } 47 103 48 CvPoint2D32f* OpticalFlowData::PointsB(void) const 49 { 50 return pointsB; 104 FloatPoint* OpticalFlowData::PointsB(void) const { 105 return pimpl_->pointsB; 51 106 } 52 107 53 char *OpticalFlowData::FoundFeature(void) const 54 { 55 return found_features; 108 char *OpticalFlowData::FoundFeature(void) const { 109 return pimpl_->found_features; 56 110 } 57 111 58 uint32_t *OpticalFlowData::FeatureError(void) const 59 { 60 return features_error; 112 uint32_t *OpticalFlowData::FeatureError(void) const { 113 return pimpl_->features_error; 61 114 } 62 115 63 116 // value is new max_features value 64 117 void OpticalFlowData::Resize(uint32_t value) { 65 CvPoint *new_pointsA; 66 CvPoint2D32f *new_pointsB; 67 char *new_found_features; 68 uint32_t *new_features_error; 69 70 new_pointsA=(CvPoint *)cvAlloc(value*sizeof(CvPoint)); 71 new_pointsB=(CvPoint2D32f *)cvAlloc(value*sizeof(CvPoint2D32f)); 72 new_found_features=(char *)cvAlloc(value*sizeof(char)); 73 new_features_error=(uint32_t *)cvAlloc(value*sizeof(uint32_t)); 74 75 GetMutex(); 76 if(value>max_features) 77 { 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 { 85 memcpy(new_pointsA,pointsA,value*sizeof(CvPoint)); 86 memcpy(new_pointsB,pointsB,value*sizeof(CvPoint2D32f)); 87 memcpy(new_found_features,found_features,value*sizeof(char)); 88 memcpy(new_features_error,features_error,value*sizeof(uint32_t)); 89 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 90 } 91 max_features=value; 92 ReleaseMutex(); 93 94 cvFree(&pointsA); 95 cvFree(&pointsB); 96 cvFree(&found_features); 97 cvFree(&features_error); 98 99 pointsA=new_pointsA; 100 pointsB=new_pointsB; 101 found_features=new_found_features; 102 features_error=new_features_error; 118 pimpl_->Resize(value); 103 119 } 104 120 105 void OpticalFlowData::RawRead(char* dst) const 106 { 121 void OpticalFlowData::RawRead(char* dst) const { 107 122 Warn("non implementé\n"); 108 123 } 109 124 110 void OpticalFlowData::SetPointsA(const CvPoint* points) 111 { 125 void OpticalFlowData::SetPointsA(const IntPoint* points) { 112 126 GetMutex(); 113 memcpy(p ointsA,points,max_features*sizeof(CvPoint));127 memcpy(pimpl_->pointsA,points,pimpl_->max_features*sizeof(IntPoint)); 114 128 ReleaseMutex(); 115 129 } 116 130 117 void OpticalFlowData::SetPointsB(const CvPoint2D32f* points) 118 { 131 void OpticalFlowData::SetPointsB(const FloatPoint* points) { 119 132 GetMutex(); 120 memcpy(p ointsB,points,max_features*sizeof(CvPoint2D32f));133 memcpy(pimpl_->pointsB,points,pimpl_->max_features*sizeof(FloatPoint)); 121 134 ReleaseMutex(); 122 135 } 123 136 124 void OpticalFlowData::SetFoundFeature(const char *found_features) 125 { 137 void OpticalFlowData::SetFoundFeature(const char *found_features) { 126 138 GetMutex(); 127 memcpy( this->found_features,found_features,max_features*sizeof(char));139 memcpy(pimpl_->found_features,found_features,pimpl_->max_features*sizeof(char)); 128 140 ReleaseMutex(); 129 141 } 130 142 131 void OpticalFlowData::SetFeatureError(const uint32_t *features_error) 132 { 143 void OpticalFlowData::SetFeatureError(const uint32_t *features_error) { 133 144 GetMutex(); 134 memcpy( this->features_error,features_error,max_features*sizeof(uint32_t));145 memcpy(pimpl_->features_error,features_error,pimpl_->max_features*sizeof(uint32_t)); 135 146 ReleaseMutex(); 136 147 } 137 148 138 uint32_t OpticalFlowData::MaxFeatures(void) const 139 { 140 return max_features; 149 uint32_t OpticalFlowData::MaxFeatures(void) const { 150 return pimpl_->max_features; 141 151 } 142 152 143 uint32_t OpticalFlowData::NbFeatures(void) const 144 { 145 return nb_features; 153 uint32_t OpticalFlowData::NbFeatures(void) const { 154 return pimpl_->nb_features; 146 155 } 147 156 148 void OpticalFlowData::SetNbFeatures(uint32_t value) 149 { 157 void OpticalFlowData::SetNbFeatures(uint32_t value) { 150 158 GetMutex(); 151 nb_features=value;159 pimpl_->nb_features=value; 152 160 ReleaseMutex(); 153 161 }
Note:
See TracChangeset
for help on using the changeset viewer.