Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLCV/src/ICLCV/ImageRegionData.h ** 00010 ** Module : ICLCV ** 00011 ** Authors: Christof Elbrechter, Erik Weitnauer ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/StackTimer.h> 00035 #include <ICLUtils/Any.h> 00036 #include <ICLCore/Img.h> 00037 #include <ICLCV/ImageRegionPart.h> 00038 #include <ICLCV/ImageRegion.h> 00039 #include <ICLCV/RegionPCAInfo.h> 00040 #include <ICLCV/CornerDetectorCSS.h> 00041 00042 #include <set> 00043 00044 namespace icl{ 00045 namespace cv{ 00046 00048 00050 struct ICLCV_API ImageRegionData{ 00051 private: 00052 typedef ImageRegionData IRD; 00053 public: 00054 friend class RegionDetector; 00055 friend struct ImageRegion; 00056 friend bool region_search_border(std::set<IRD*>&,IRD*); 00057 friend void collect_subregions_recursive(std::set<IRD*>&,IRD*); 00058 friend bool is_region_contained(IRD*,IRD*); 00059 friend bool region_search_outer_bb(const utils::Rect&,std::set<IRD*>&,IRD*); 00060 00061 private: 00063 int value; 00064 00066 int id; 00067 00069 mutable int size; 00070 00072 const core::ImgBase *image; 00073 00075 std::vector<LineSegment> segments; 00076 00078 utils::Any meta; 00079 00081 struct RegionGraphInfo{ 00083 RegionGraphInfo():isBorder(false),parent(0){} 00084 00086 bool isBorder; 00087 00088 // region graph information 00089 std::set<ImageRegionData*> neighbours; 00090 00091 // child regions 00092 std::vector<ImageRegionData*> children; 00093 00095 ImageRegionData *parent; 00096 } *graph; 00097 00098 // structure for representing simple region information 00099 struct SimpleInformation{ 00100 inline SimpleInformation(): 00101 boundingBox(0),cog(0),pcainfo(0), 00102 boundaryLength(0),boundary(0), 00103 thinned_boundary(0),pixels(0){} 00104 inline ~SimpleInformation(){ 00105 if(boundingBox) delete boundingBox; 00106 if(cog) delete cog; 00107 if(pcainfo) delete pcainfo; 00108 if(boundary) delete boundary; 00109 if(thinned_boundary) delete thinned_boundary; 00110 if(pixels) delete pixels; 00111 } 00112 utils::Rect *boundingBox; 00113 utils::Point32f *cog; 00114 RegionPCAInfo *pcainfo; 00115 int boundaryLength; 00116 00117 std::vector<utils::Point> *boundary; 00118 std::vector<utils::Point> *thinned_boundary; 00119 std::vector<utils::Point> *pixels; 00120 00121 } *simple; 00122 00123 struct CSSParams{ 00124 float angle_thresh; 00125 float rc_coeff; 00126 float sigma; 00127 float curvature_cutoff; 00128 float straight_line_thresh; 00129 std::vector<utils::Point32f> resultBuffer; 00130 00131 bool isOk(CornerDetectorCSS *css) const{ 00132 return css->getAngleThreshold() == angle_thresh && 00133 css->getRCCoeff() == rc_coeff && 00134 css->getSigma() == sigma && 00135 css->getCurvatureCutoff() == curvature_cutoff && 00136 css->getStraightLineThreshold() == straight_line_thresh; 00137 } 00138 00139 void setFrom(CornerDetectorCSS *css){ 00140 angle_thresh = css->getAngleThreshold(); 00141 rc_coeff = css->getRCCoeff(); 00142 sigma = css->getSigma(); 00143 curvature_cutoff = css->getCurvatureCutoff(); 00144 straight_line_thresh = css->getStraightLineThreshold(); 00145 } 00146 }; 00147 00149 struct ComplexInformation{ 00150 inline ComplexInformation(): 00151 directSubRegions(0),allSubRegions(0),parent(0), 00152 parentTree(0),publicNeighbours(0),cssParams(0){} 00153 inline ~ComplexInformation(){ 00154 if(directSubRegions) delete directSubRegions; 00155 if(allSubRegions) delete allSubRegions; 00156 if(parent) delete parent; 00157 if(parentTree) delete parentTree; 00158 if(publicNeighbours) delete publicNeighbours; 00159 if(cssParams) delete cssParams; 00160 } 00161 std::vector<ImageRegion> *directSubRegions; 00162 std::vector<ImageRegion> *allSubRegions; 00163 ImageRegion *parent; 00164 std::vector<ImageRegion> *parentTree; 00165 std::vector<ImageRegion> *publicNeighbours; 00166 CSSParams *cssParams; 00167 } *complex; 00168 00169 00170 CornerDetectorCSS *css; 00171 00173 static ImageRegionData *createInstance(CornerDetectorCSS *css, ImageRegionPart *topRegionPart, int id, bool createGraphInfo, const core::ImgBase *image); 00174 00176 inline ImageRegionData(CornerDetectorCSS *css, int value, int id, unsigned int segmentSize, bool createGraph,const core::ImgBase *image): 00177 value(value),id(id),size(0),image(image),segments(segmentSize),graph(createGraph ? new RegionGraphInfo : 0), 00178 simple(0),complex(0),css(css){} 00179 00181 inline ~ImageRegionData(){ 00182 if(graph) delete graph; 00183 if(simple) delete simple; 00184 if(complex) delete complex; 00185 } 00186 00187 // utility function (only if linkTable is not given) 00188 inline void link(ImageRegionData *a){ 00189 if(this != a){ 00190 if(a->graph->neighbours.size() < graph->neighbours.size()){ 00191 if(a->graph->neighbours.insert(this).second){ 00192 graph->neighbours.insert(a); 00193 } 00194 }else{ 00195 if(graph->neighbours.insert(a).second){ 00196 a->graph->neighbours.insert(this); 00197 } 00198 } 00199 } 00200 } 00201 00203 inline void addChild(ImageRegionData *a){ 00204 graph->children.push_back(a); 00205 a->graph->parent = this; 00206 } 00207 00209 void showTree(int indent=0) const; 00210 00212 void showWithNeighbours() const; 00213 00215 inline ComplexInformation *ensureComplex(){ 00216 if(!complex) complex = new ComplexInformation; 00217 return complex; 00218 } 00219 00221 inline SimpleInformation *ensureSimple(){ 00222 if(!simple) simple = new SimpleInformation; 00223 return simple; 00224 } 00225 }; 00226 00227 } // namespace cv 00228 } 00229