hough.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020 #ifndef HOUGH_H
00021 #define HOUGH_H
00022 
00023 #include <ardev/ardev.h>
00024 
00025 #include <list>
00026 #include <vector>
00027 
00028 #include <libthjc/matrix.h>
00029 #include <libthjc/geometry.h>
00030 
00031 using namespace std;
00032 
00033 
00034 class BoundingBox
00035 {
00036         public:
00037                 BoundingBox(unsigned int aTop=0,unsigned int aBottom=0,unsigned int aLeft=0,unsigned int aRight=0) {top=aTop;bottom=aBottom;left=aLeft;right=aRight;};
00038                 ~BoundingBox() {};      
00039 
00040                 unsigned int GetTop() const {return top;};
00041                 unsigned int GetBottom() const {return bottom;};
00042                 unsigned int GetLeft() const {return left;};
00043                 unsigned int GetRight() const {return right;};
00044 
00045                 unsigned int GetWidth() const {return right-left;};
00046                 unsigned int GetHeight() const {return bottom-top;};
00047 
00048                 double GetHWRatio() const {if (GetWidth() > 0) return static_cast<double> (GetHeight())/static_cast<double> (GetWidth()); else return 1000000;};
00049                 unsigned int GetArea() const {return GetHeight()*GetWidth();};
00050                 Point2D GetCenter() const {return Point2D(static_cast<double>(right+left)/2,static_cast<double>(bottom+top)/2);};
00051 
00052                 void SetTop(int aTop) {top = aTop;};
00053                 void SetBottom(int aBottom) {bottom = aBottom;};
00054                 void SetLeft(int aLeft) {left = aLeft;};
00055                 void SetRight(int aRight) {right = aRight;};
00056         
00057 
00058                 BoundingBox & operator = (const BoundingBox & rhs) {top = rhs.top; bottom = rhs.bottom; left = rhs.left; right = rhs.right; return *this;};
00059         private:
00060                 unsigned int top;
00061                 unsigned int bottom;
00062                 unsigned int left;
00063                 unsigned int right;
00064 };
00065 
00066 class ImageSegment
00067 {
00068         public:
00069                 ImageSegment() {};
00070                 ImageSegment(vector<Point2D> aPoints);
00071                 ~ImageSegment() {};
00072 
00073                 void AddPoint(const Point2D & NewPoint);
00074                 BoundingBox GetBoundingBox() const {return bb;};
00075 
00076                 double GetSolidity() const {return static_cast<double> (Points.size())/bb.GetArea();};
00077                 Point2D GetCenterOfMass() const {return CenterOfMass;};
00078 
00079                 const vector<Point2D> & GetPoints() const {return Points;};
00080                 vector<Point2D> & GetPointsRef() {return Points;};
00081 
00082                 unsigned int GetLabel() const {return Label;};
00083                 void SetLabel(unsigned int aLabel) {Label = aLabel;};
00084 
00085 
00086                 ImageSegment & operator = (const ImageSegment & rhs) {bb = rhs.bb; Points = rhs.Points; CenterOfMass = rhs.CenterOfMass; Label = rhs.Label; return * this;}
00087         private:
00088                 BoundingBox bb;
00089                 vector<Point2D> Points;
00090                 Point2D CenterOfMass;
00091                 unsigned int Label;
00092 };
00093 
00094 
00095 int doHough(ARImage & Image, ARImage & Hough);
00096 
00097 int doGray(ARImage & Image, ARImage & Output);
00098 
00099 int doHue(Point2D TopLeft, Point2D BottomRight, int ClearColour, ARImage & Image, ARImage & Output);
00100 
00101 int ExtractHue(int Colour, int Range, ARImage & Image, ARImage & Output);
00102 
00103 int doThresh(ARImage & Image, ARImage & Output, int thresh);
00104 
00105 int doHitMiss(ARImage & Input, ARImage & Output, int Size, int * Kernel);
00106 
00107 int doThinning(ARImage & Input, ARImage & Output);
00108 
00109 int doPruning(ARImage & Input, ARImage & Output, int Count);
00110 
00111 list<vector<Point2D> > doLabelSegmentsGray(int range, ARImage & Input, ARImage & Output);
00112 
00113 typedef enum SegmentMode {SEG_LESS, SEG_MORE, SEG_EQUAL};
00114 list<vector<Point2D> > doLabelSegments(ARImage & Input, SegmentMode Mode, int range=0);
00115 list<vector<Point2D> > doLabelSegments(ARImage & Input, BoundingBox ROI, SegmentMode Mode, int range=0);
00116 
00117 vector<Point2D> getBestRect(ARImage & ThresholdImage, list<vector<Point2D> > & Segments, ARImage & Output);
00118 vector<Point2D> getBestRect(ARImage & ThresholdImage, list<vector<Point2D> > & Segments);
00119 
00120 vector<Point2D> doRemoveBiggestSegment(list<vector<Point2D> > & Segments, ARImage & Output);
00121 vector<Point2D> doRemoveBiggestSegment(list<vector<Point2D> > & Segments);
00122 
00123 void doGetCubeRegion(vector<Point2D> Segment, Point2D & TopLeft, Point2D & BottomRight, ARImage & Input, ARImage & Output);
00124 
00125 Point2D doGetCenter(const vector<Point2D> & Segment);
00126 
00127 void getLRU(int & Left, int & Right, int & Up, const vector<Point2D> & Segment1, const vector<Point2D> & Segment2, const vector<Point2D> & Segment3);
00128 
00129 vector<Point2D> getNineDotCenters(list<vector<Point2D> > & Segments);
00130 
00131 vector<Point2D> orderNineDotsLeft(vector<Point2D> & Dots);
00132 vector<Point2D> orderNineDotsRight(vector<Point2D> & Dots);
00133 vector<Point2D> orderNineDotsTop(vector<Point2D> & Dots);
00134 vector<Point2D> orderNineDots(vector<Point2D> & Dots);
00135 
00136 Matrix doGetTopPoints(Matrix & InputPoints, unsigned int NumPoints, ARImage & Output);
00137 
00138 Matrix doOrderLinesByAngle(Matrix & InputPoints, ARImage & Output);
00139 
00140 Matrix doOrderLinesByNormal(Matrix & InputPoints, ARImage & Output);
00141 
00142 list<Line> doMatrixToLines(Matrix & InputPoints, ARImage & Reference);
00143 
00144 list<Point2D> doIntersectLines(list<Line> & InputLines);
00145 
00146 void PutDotsOnOriginal(const char * colour, const vector<Point2D> & Dots, ARImage & Output);
00147 void PutDotsOnOriginal(const vector<Point2D> & Dots, ARImage & Output);
00148 
00149 // display segments
00150 void DisplaySegments(ARImage & Output, list<vector<Point2D> > & Segments);
00151 void DisplaySegments(ARImage & Output, list<ImageSegment> & Segments);
00152 
00153 // remove segments less than desired size
00154 void ThresholdSegments(list<vector<Point2D> > & Segments, unsigned int MinSize);
00155 
00156 list<ImageSegment> GetSegmentInfo(list<vector<Point2D> > & Segments);
00157 
00158 // apply a set of rules to the segments, hard coded for now
00159 void ApplyRules(ARImage & ThresholdImage, list<ImageSegment> & Segments);
00160 
00161 int CountHoles(ARImage & ThresholdImage, ImageSegment aSegment, unsigned int MinSize=0);
00162 
00163 enum {MARKER_UNKNOWN, MARKER_LEFT, MARKER_RIGHT, MARKER_UP, MARKER_DOWN};
00164 void LabelSegments(list<ImageSegment> & Segments);
00165 
00166 void DrawLabelledSegments(ARImage & Output, list<ImageSegment> & Segments);
00167 void DrawLabelledSegmentsGreen(ARImage & Output, list<ImageSegment> & Segments);
00168 
00169 void Normalise(ARImage & Input, ARImage & Output);
00170 
00171 ImageSegment FillHoles(ImageSegment & Input, ARImage & Output);
00172 
00173 #endif

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1