latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiFastCircleExtraction.h 00027 * authors ....: Ingo Grothues (ingo@isdevelop.de) 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 22.4.2004 00030 * revisions ..: $Id: ltiFastCircleExtraction.h,v 1.7 2006/02/08 11:05:48 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_FAST_CIRCLE_EXTRACTION_H_ 00034 #define _LTI_FAST_CIRCLE_EXTRACTION_H_ 00035 00036 #include "ltiFeatureExtractor.h" 00037 #include "ltiPoint.h" 00038 #include <vector> 00039 00040 namespace lti { 00041 00042 /** 00043 * This functor implements a fast circle extraction 00044 * using the line segments found in digital images. 00045 * 00046 * To achieve this, the lines of an image are extracted 00047 * by a fast line extraction. The edge lines of circles are 00048 * filtered by several checks. In further passes these lines 00049 * are combined to arcs, adjacent arcs are combined to extended 00050 * arcs which at last are used to extract circles. 00051 * 00052 * The fastCircleExtraction::parameters specify several 00053 * ranges and conditions that the lines and arcs must fulfill. 00054 * The result strongly depends on these parameters, 00055 * especially the number and the precision of the 00056 * extracted circles. 00057 * 00058 * The extracted arcs and circles are stored in STL vector 00059 * containers of the types <arcEntry>, <extArcEntry> and 00060 * <circleEntry>. They can be accessed by the methods 00061 * getArcList(), getExtArcList and getCircleList(). 00062 * 00063 * \c arcEntry is the data struct for arcs: 00064 * <pre> struct arcEntry 00065 * { 00066 * ipoint start; // start point 00067 * ipoint end; // end point 00068 * ipoint mid; // midpoint 00069 * int r2; // length or squared radius 00070 * ipoint firstVec; // first line vector 00071 * ipoint lastVec; // last line vector 00072 * int used; // counts arc<->extarc assignments 00073 * int group; // base line group (1,2,3 or 4) 00074 * std::vector<int> *lineIdxList; // base line index list 00075 * };</pre> 00076 * 00077 * \c extArcEntry is the data struct for extended arcs: 00078 * <pre> struct extArcEntry 00079 * { 00080 * ipoint start; // start point 00081 * ipoint end; // end point 00082 * ipoint mid; // circle midpoint 00083 * int r2; // squared radius 00084 * ipoint firstMid; // midpoint of the first segment 00085 * double firstTang; // tangent of the first segment 00086 * ipoint lastMid; // midpoint of the last segment 00087 * double lastTang; // tangent of the last segment 00088 * int used; // counts extarc<->circle assignments 00089 * int group; // ext arc group (1,2,3 or 4) 00090 * int arcIdxA; // 1st base arc index (groups I:1, II:3, III:2, IV:4) 00091 * int arcIdxB; // 2nd base arc index (groups I:3, II:2, III:4, IV:1) 00092 * };</pre> 00093 * 00094 * \c circleEntry is the data struct for circles: 00095 * <pre>struct circleEntry 00096 * { 00097 * ipoint center; // circle center 00098 * int radius; // circle radius 00099 * double coverage; // circle coverage (accuracy strongly depends on radius and other effects) 00100 * };</pre> 00101 * 00102 * The fast circle extraction does not perform any changes 00103 * to the analyzed image. To visualize the extracted circles 00104 * they have to be drawn by other code using the 00105 * circle lists and a drawing functor. 00106 * 00107 * 00108 * Example: 00109 * \code 00110 * 00111 * #include "ltiViewer.h" // visualization tool 00112 * #include "ltiDraw.h" // drawing tool 00113 * #include "ltiALLfunctor.h" // image loader 00114 * #include "ltiCannyEdges.h" // edge detector 00115 * #include "ltiFastCircleExtraction.h" // circle detector 00116 * 00117 * // ... 00118 * 00119 * lti::image inputImg; 00120 * lti::channel8 edges; 00121 * lti::channel8 result; 00122 * 00123 * // load image 00124 * lti::loadImage loader; 00125 * loader.load("myImage.bmp", inputImg); 00126 * 00127 * // we need the edges 00128 * lti::cannyEdges canny; 00129 * canny.apply(inputImg, edges); 00130 * 00131 * // create FCE functor (using default parameters) 00132 * lti::fastCircleExtraction fce; 00133 * 00134 * // extract some circles 00135 * fce.apply(edges); 00136 * 00137 * // get the circle list 00138 * std::vector<lti::fastCircleExtraction::circleEntry> &circles = fce.getCircleList(); 00139 * 00140 * // create a drawing functor 00141 * lti::draw<lti::channel8::value_type> drawer; 00142 * drawer.use(result); 00143 * drawer.setColor(255); 00144 * 00145 * // create background with grey edges 00146 * result = edges; 00147 * result /= 2; 00148 * 00149 * for(int i=0; i<circles.size(); i++) { 00150 * // draw all circles 00151 * drawer.circle(circles[i].center.x, circles[i].center.y, circles[i].radius, false); 00152 * // print circle data 00153 * printf("circle[%i]: center=(%i,%i) radius=%i coverage=%.1f%% \n", 00154 * i, circles[i].center.x, circles[i].center.y, circles[i].radius, circles[i].coverage*100); 00155 * } 00156 * 00157 * // show the extracted circles 00158 * lti::viewer view("Detected circles"); 00159 * view.show(result); 00160 * 00161 * // wait for a mouse click in the viewer window 00162 * view.waitButtonPressed(); 00163 * 00164 * \endcode 00165 */ 00166 00167 class fastCircleExtraction : public featureExtractor { 00168 public: 00169 00170 struct segmEntry 00171 { 00172 ipoint start; // start point 00173 ipoint end; // end point 00174 int len; // length 00175 int used; // counts segment<->line assignments 00176 }; 00177 00178 struct lineEntry 00179 { 00180 ipoint start; // start point 00181 ipoint end; // end point 00182 ipoint mid; // midpoint 00183 double tangent; // line tangent 00184 int len; // length 00185 int used; // counts line<->arc assignments 00186 int group; // base segment group (1,2,3 or 4) 00187 std::vector<int> *segmIdxList; // base segment index list 00188 }; 00189 00190 struct arcEntry 00191 { 00192 ipoint start; // start point 00193 ipoint end; // end point 00194 ipoint mid; // estimated circle midpoint 00195 int r2; // estimated squared radius 00196 ipoint firstVec; // first line vector 00197 ipoint lastVec; // last line vector 00198 int used; // counts arc<->extarc assignments 00199 int group; // base line group (1,2,3 or 4) 00200 std::vector<int> *lineIdxList; // base line index list 00201 }; 00202 00203 struct extArcEntry 00204 { 00205 ipoint start; // start point 00206 ipoint end; // end point 00207 ipoint mid; // estimated circle midpoint 00208 int r2; // estimated squared radius 00209 ipoint firstMid; // midpoint of the first segment 00210 double firstTang;// tangent of the first segment 00211 ipoint lastMid; // midpoint of the last segment 00212 double lastTang; // tangent of the last segment 00213 int used; // counts extarc<->circle assignments 00214 int group; // ext arc group (1,2,3 or 4) 00215 int arcIdx[2];// base arc indices (groups I:3, II:2, III:4, IV:1) 00216 }; 00217 00218 struct circleEntry 00219 { 00220 ipoint center; // circle center 00221 int radius; // circle radius 00222 double coverage; // circle coverage (accuracy strongly depends on radius and other effects) 00223 std::vector<int> *mergedArcs; // extarc index list 00224 }; 00225 00226 00227 /** 00228 * the parameters for the class fastCircleExtraction 00229 */ 00230 class parameters : public featureExtractor::parameters { 00231 public: 00232 /** 00233 * default constructor 00234 */ 00235 parameters(); 00236 00237 /** 00238 * copy constructor 00239 * @param other the parameters object to be copied 00240 */ 00241 parameters(const parameters& other); 00242 00243 /** 00244 * destructor 00245 */ 00246 ~parameters(); 00247 00248 /** 00249 * returns name of this type 00250 */ 00251 const char* getTypeName() const; 00252 00253 /** 00254 * copy the contents of a parameters object 00255 * @param other the parameters object to be copied 00256 * @return a reference to this parameters object 00257 */ 00258 parameters& copy(const parameters& other); 00259 00260 /** 00261 * copy the contents of a parameters object 00262 * @param other the parameters object to be copied 00263 * @return a reference to this parameters object 00264 */ 00265 parameters& operator=(const parameters& other); 00266 00267 00268 /** 00269 * returns a pointer to a clone of the parameters 00270 */ 00271 virtual functor::parameters* clone() const; 00272 00273 /** 00274 * write the parameters in the given ioHandler 00275 * @param handler the ioHandler to be used 00276 * @param complete if true (the default) the enclosing begin/end will 00277 * be also written, otherwise only the data block will be written. 00278 * @return true if write was successful 00279 */ 00280 virtual bool write(ioHandler& handler,const bool complete=true) const; 00281 00282 /** 00283 * read the parameters from the given ioHandler 00284 * @param handler the ioHandler to be used 00285 * @param complete if true (the default) the enclosing begin/end will 00286 * be also written, otherwise only the data block will be written. 00287 * @return true if write was successful 00288 */ 00289 virtual bool read(ioHandler& handler,const bool complete=true); 00290 00291 # ifdef _LTI_MSC_6 00292 /** 00293 * this function is required by MSVC only, as a workaround for a 00294 * very awful bug, which exists since MSVC V.4.0, and still by 00295 * V.6.0 with all bugfixes (so called "service packs") remains 00296 * there... This method is also public due to another bug, so please 00297 * NEVER EVER call this method directly: use read() instead 00298 */ 00299 bool readMS(ioHandler& handler,const bool complete=true); 00300 00301 /** 00302 * this function is required by MSVC only, as a workaround for a 00303 * very awful bug, which exists since MSVC V.4.0, and still by 00304 * V.6.0 with all bugfixes (so called "service packs") remains 00305 * there... This method is also public due to another bug, so please 00306 * NEVER EVER call this method directly: use write() instead 00307 */ 00308 bool writeMS(ioHandler& handler,const bool complete=true) const; 00309 # endif 00310 00311 // ------------------------------------------------ 00312 // the parameters 00313 // ------------------------------------------------ 00314 00315 /** This threshold constant defines the maximum mismatch 00316 * between the found line segments and the estimated analog line. 00317 * The segment is discarded if its starting/finishing pixel 00318 * differs more than <code>maxQuantizationError</code> 00319 * from the estimated analog line. 00320 * If this value is greater than 1.0 the line detection will 00321 * also extract lines that are not completely straight, which 00322 * may be useful for estimation of lines. 00323 * possible values are 00324 * <pre> 00325 * 0.5 < maxQuantizationError 00326 * </pre> 00327 * A high maxQuantizationError value will extract longer lines 00328 * at the cost of precision. Low values result in better pixel 00329 * matching but also in shorter lines. 00330 * Best compromise between pixel matching and good detection 00331 * is a value between 0.6 and 0.7 (the default is 0.79) 00332 */ 00333 float maxQuantizationError; 00334 00335 00336 /** 00337 * This constant defines how much the value of two adjacent pixels 00338 * may differ and still be considered pixels of the same segment. 00339 * A <code>segmentTolerance</code> of 0 will only group pixels 00340 * of the same value to one segment. When analyzing binary maps 00341 * such as edge-images a value of 0 should be used. 00342 * possible values are 00343 * <pre> 00344 * 0 <= segmentTolerance <= 254 00345 * </pre> 00346 * Higher segmentTolerance values allow non-binary 00347 * images to be analysed but may also result in wrong 00348 * segment start/end detection. 00349 * The default is 0 00350 */ 00351 int segmentTolerance; 00352 00353 00354 /** 00355 * The maximum gap two line segments may have and 00356 * still be considered segments of the same line. 00357 * This parameter changes the size of the searching window 00358 * for line segments. Small sizes allow fast processing but may 00359 * also cause detection failures (as well as too high values) 00360 * A <code>maxSegmentGap</code> of 1 will only group 00361 * contiguous segments to a line. 00362 * possible values are 00363 * <pre> 00364 * maxSegmentGap >= 1 (pixel) 00365 * </pre> 00366 * Higher maxSegmentGap values also allow extraction of 00367 * non-contiguous lines such as found in corrupted images. 00368 * The default is 1 00369 */ 00370 int maxSegmentGap; 00371 00372 00373 /** 00374 * The minimum length a line must have to get extracted. 00375 * The parameter <code>minLineLen</code> is used as 00376 * threshold, smaller lines will be ignored. 00377 * possible values are 00378 * <pre> 00379 * minLineLen >= 3 (pixel) 00380 * </pre> 00381 * Values greater than 3 will strongly decrease 00382 * the number of extracted lines and therefore speed up 00383 * the following extraction stages. For most circles 00384 * the optimal value lies between 5 and 7. 00385 * The default is 6 00386 */ 00387 int minLineLen; 00388 00389 00390 /** 00391 * The minimum length a line segment must have to be detected. 00392 * The parameter <code>minSegmLen</code> is used as 00393 * threshold, smaller segments will be ignored. 00394 * Values greater than 2 strongly decrease the number 00395 * of detected segments and the size of the segment lists. 00396 * possible values are 00397 * <pre> 00398 * minSegmLen >= 2 (pixel) 00399 * </pre> 00400 * Values greater than 2 result in smaller segment lists 00401 * and therefore allow slightly faster line detection. 00402 * But mostly good line detection is more important than 00403 * a small speedup, so don't change this parameter unless 00404 * there is a good reason to do so. 00405 * The default is 2 00406 */ 00407 int minSegmLen; 00408 00409 00410 /** 00411 * The maximum gap two lines may have and 00412 * still be considered lines of the same arc. 00413 * This parameter changes the size of the searching window 00414 * for lines. Best results were obtained with small values, 00415 * because large window sizes tend to combine adjacent parallel 00416 * lines to one arc which causes detection failures. 00417 * A <code>maxLineGap</code> of 1 will only group 00418 * contiguous lines to an arc. 00419 * possible values are 00420 * <pre> 00421 * maxLineGap >= 1 (pixel) 00422 * </pre> 00423 * Higher maxLineGap values also allow extraction of 00424 * non-contiguous arcs such as found in corrupted images. 00425 * The default is 2 00426 */ 00427 int maxLineGap; 00428 00429 00430 /** 00431 * The maximum gap two arcs may have and 00432 * still be considered arcs of the same extended arc. 00433 * This parameter changes the size of the searching window 00434 * for arcs. Best results were obtained with large values, 00435 * because every arc has to find at least one other to 00436 * remain in the extraction process. (the gap between 00437 * these arcs mostly lies between 10 and 40 pixels) 00438 * A <code>maxArcGap</code> of 1 will only group 00439 * contiguous arcs to an extended arc. 00440 * possible values are 00441 * <pre> 00442 * maxArcGap >= 1 (pixel) 00443 * </pre> 00444 * Higher maxArcGap values also allow extraction of 00445 * non-contiguous arcs such as found in corrupted images. 00446 * The default is 30 00447 */ 00448 int maxArcGap; 00449 00450 00451 /** This parameter defines the maximum difference that 00452 * the tangents of two lines may have in relation to the 00453 * tangents of the arc that these lines represent. 00454 * In other words, this parameter affects the tolerance 00455 * in terms of roundness of the countour. 00456 * Line pairs which exceed this threshold won't be 00457 * combined to an arc. Too large values result in 00458 * incorrect arcs and detection failures. 00459 * reasonable values are 00460 * <pre> 00461 * 8.5 <= maxLineTangentError <= 20 00462 * </pre> 00463 * Small values cause stricter circle checks 00464 * whereas large values allow more tolerance. 00465 * Best compromise between accuracy and tolerance 00466 * is a value between 10 and 15 (the default is 15) 00467 */ 00468 float maxLineTangentError; 00469 00470 00471 /** This parameter defines the maximum difference that 00472 * the tangents of two arcs may have in relation to the 00473 * tangents of the circle that these arcs represent. 00474 * In other words, this parameter affects the tolerance 00475 * in terms of circle matching. 00476 * Arc pairs which exceed this threshold won't be 00477 * combined to an extended arc. Too large values result 00478 * incorrect extended arcs and detection failures. 00479 * reasonable values are 00480 * <pre> 00481 * 8.5 <= maxArcTangentError <= 20 00482 * </pre> 00483 * Small values cause stricter circle checks 00484 * whereas large values allow more tolerance. 00485 * Best compromise between accuracy and tolerance 00486 * is a value between 10 and 15 (the default is 12) 00487 */ 00488 float maxArcTangentError; 00489 00490 00491 /** This parameter defines the maximum distance 00492 * between the start and end points of one arc and 00493 * the estimated circle contour of the other arc. 00494 * Arc pairs which exceed this threshold won't be 00495 * combined to an extended arc. Too large values 00496 * cause detection failures. 00497 * reasonable values are 00498 * <pre> 00499 * 1 <= maxExtArcMismatch <= 10 00500 * </pre> 00501 * Small values cause stricter arc matching checks 00502 * whereas large values allow more tolerance. 00503 * Best compromise between accuracy and tolerance 00504 * is a value between 1.5 and 4 (the default is 2.75) 00505 */ 00506 float maxExtArcMismatch; 00507 00508 00509 /** This parameter defines the minimal ratio 00510 * of the estimated circle radii of two arcs. 00511 * Arc pairs which under-run this threshold won't be 00512 * combined to an extended arc. Too small values 00513 * cause detection failures. 00514 * reasonable values are 00515 * <pre> 00516 * 0.5 <= minExtArcMatchRatio <= 0.95 00517 * </pre> 00518 * Large values cause stricter arc matching checks 00519 * whereas small values allow more tolerance. 00520 * Best compromise between accuracy and tolerance 00521 * is a value between 0.7 and 0.9 (the default is 0.8) 00522 */ 00523 float minExtArcMatchRatio; 00524 00525 00526 /** This parameter is a toggle to switch between 00527 * the old and the new extended arc checks. 00528 * In general the new checks should be better, 00529 * but in some situations the old check obtain 00530 * better results. 00531 * The old check required only one threshold 00532 * parameter: <code>oldExtArcThreshold</code> 00533 * possible values are 00534 * <pre> 00535 * true or false 00536 * </pre> 00537 * (the default is false) 00538 */ 00539 bool oldExtArcCheck; 00540 00541 00542 /** This parameter defines an admeasurement 00543 * in terms of circle arc matching. 00544 * Arc pairs which exceed this threshold won't be 00545 * combined to an extended arc. Too large values 00546 * cause detection failures. The threshold check 00547 * gets stricter with larger radii because of 00548 * comparing squared distances. This is the main 00549 * difference between the old and new ExtArc check. 00550 * reasonable values are 00551 * <pre> 00552 * 50 <= oldExtArcThreshold <= 250 00553 * </pre> 00554 * Small values cause stricter arc matching checks 00555 * whereas large values allow more tolerance. 00556 * Best compromise between accuracy and tolerance 00557 * is a value between 80 and 120 (the default is 100) 00558 */ 00559 int oldExtArcThreshold; 00560 00561 00562 /** This parameter defines the maximum gap between 00563 * the estimated circle centers of two extended arcs. 00564 * ExtArc pairs which exceed this threshold won't be 00565 * combined to a circle. Too large values cause 00566 * detection failures. 00567 * reasonable values are 00568 * <pre> 00569 * 1 <= maxCenterMismatch <= 10 00570 * </pre> 00571 * Small values cause stricter extArc matching checks 00572 * whereas large values allow more tolerance. 00573 * Best compromise between accuracy and tolerance 00574 * is a value between 1.5 and 4 (the default is 2.5) 00575 */ 00576 float maxCenterMismatch; 00577 00578 00579 /** This parameter defines the minimal ratio 00580 * of the estimated circle radii of two extended arcs. 00581 * ExtArc pairs which underrun this threshold won't be 00582 * combined to a circle. Too small values cause 00583 * detection failures. 00584 * reasonable values are 00585 * <pre> 00586 * 0.5 <= minRadiusMatchRatio <= 0.95 00587 * </pre> 00588 * Large values cause stricter extArc matching checks 00589 * whereas small values allow more tolerance. 00590 * Best compromise between accuracy and tolerance 00591 * is a value between 0.7 and 0.9 (the default is 0.75) 00592 */ 00593 float minRadiusMatchRatio; 00594 00595 00596 /** This parameter defines the minimal coverage for estimated 00597 * circles to get extracted. That is the ratio of the estimated 00598 * circumference and the number of extracted arc pixels. 00599 * Circles which underrun this threshold won't get extracted. 00600 * Too small values cause extraction of circles with randomly 00601 * matching arcs. Also this threshold shouldn't be set to values 00602 * greater than 0.7, since only well fitting parts of a circle 00603 * are extracted. Therefore even a completely present circle 00604 * may get only 70%% coverage. 00605 * reasonable values are 00606 * <pre> 00607 * 0.2 <= minCoverage <= 0.7 00608 * </pre> 00609 * Best compromise between accuracy and tolerance 00610 * is a value between 0.3 and 0.5 (the default is 0.3) 00611 * Note: Very close and similar circles are sometimes 00612 * merged to one circle which shows more than 100%% coverage. 00613 */ 00614 float minCoverage; 00615 }; 00616 00617 //////////////////////////////////////////////////////////////////////////// 00618 00619 /** 00620 * default constructor 00621 */ 00622 fastCircleExtraction(); 00623 00624 /** 00625 * Construct a functor using the given parameters 00626 */ 00627 fastCircleExtraction(const parameters& par); 00628 00629 /** 00630 * copy constructor 00631 * @param other the object to be copied 00632 */ 00633 fastCircleExtraction(const fastCircleExtraction& other); 00634 00635 /** 00636 * destructor 00637 */ 00638 virtual ~fastCircleExtraction(); 00639 00640 /** 00641 * returns the name of this type ("fastCircleExtraction") 00642 */ 00643 virtual const char* getTypeName() const; 00644 00645 /** 00646 * Applies fast circle detection on-place. 00647 * @param srcdest channel8 with the source data. 00648 * @return true if apply was successful or false otherwise. 00649 */ 00650 bool apply(const channel8& srcdest); 00651 00652 /** 00653 * Applies fast circle detection on-place. 00654 * @param srcdest channel with the source data. 00655 * @return true if apply was successful or false otherwise. 00656 */ 00657 bool apply(const channel& srcdest); 00658 00659 /** 00660 * copy data of "other" functor. 00661 * @param other the functor to be copied 00662 * @return a reference to this functor object 00663 */ 00664 fastCircleExtraction& copy(const fastCircleExtraction& other); 00665 00666 /** 00667 * alias for copy member 00668 * @param other the functor to be copied 00669 * @return a reference to this functor object 00670 */ 00671 fastCircleExtraction& operator=(const fastCircleExtraction& other); 00672 00673 /** 00674 * returns a pointer to a clone of this functor. 00675 */ 00676 virtual functor* clone() const; 00677 00678 /** 00679 * returns used parameters 00680 */ 00681 const parameters& getParameters() const; 00682 00683 00684 /////////////////////////////////////////////////////////// 00685 00686 /** 00687 * returns a vector with line segments of the specified group 00688 * @param group_number number of the line segment group (1,2,3,4) 00689 * @return vector with detected line segments 00690 */ 00691 virtual std::vector<segmEntry>& getSegmentList(const int group_number); 00692 00693 /** 00694 * returns a vector with lines of the specified group 00695 * @param group_number number of the line group (1,2,3,4, or 0 for all lines) 00696 * @return vector with extracted lines 00697 */ 00698 virtual std::vector<lineEntry>& getLineList(const int group_number); 00699 00700 /** 00701 * returns a vector with arcs of the specified group 00702 * @param group_number number of the arc group (1,2,3,4, or 0 for all arcs) 00703 * @return vector with extracted arcs 00704 */ 00705 virtual std::vector<arcEntry>& getArcList(const int group_number); 00706 00707 /** 00708 * returns a vector with extended arcs of the specified group 00709 * @param group_number number of the arc group (1,2,3,4, or 0 for all arcs) 00710 * @return vector with extracted extended arcs 00711 */ 00712 virtual std::vector<extArcEntry>& getExtArcList(const int group_number); 00713 00714 /** 00715 * returns a vector with extracted circles. 00716 * @return vector with extracted circles 00717 */ 00718 virtual std::vector<circleEntry>& getCircleList(); 00719 00720 00721 private: 00722 00723 /** 00724 * clears a line list and its allocated objects 00725 * @param group_number number of the line group (1,2,3,4) 00726 */ 00727 virtual void clearLineList(const int group_number); 00728 00729 /** 00730 * clears an arc list and its allocated objects 00731 * @param group_number number of the arc group (1,2,3,4) 00732 */ 00733 virtual void clearArcList(const int group_number); 00734 00735 /** 00736 * clears an extended arc list and its allocated objects 00737 * @param group_number number of the arc group (1,2,3,4) 00738 */ 00739 virtual void clearExtArcList(const int group_number); 00740 00741 /** 00742 * clears the circle list and its allocated objects 00743 */ 00744 virtual void clearCircleList(); 00745 00746 /** 00747 * The segment detection methods. They detect segments by scanning pixel rows. 00748 * For performance and review reasons there are 4 methods (one per segment group). 00749 * Results are stored in STL vectors of type <segmEntry>. These vectors can 00750 * be accessed by the method getSegmentList(). 00751 * @param src channel with source data 00752 */ 00753 virtual void detectGroup1Segments(const channel8& src); 00754 virtual void detectGroup2Segments(const channel8& src); 00755 virtual void detectGroup3Segments(const channel8& src); 00756 virtual void detectGroup4Segments(const channel8& src); 00757 00758 /** 00759 * The line extraction methods. They extract lines by tracking line segments. 00760 * For performance and review reasons there are 4 methods (one per segment group). 00761 * Results are stored in STL vectors of type <lineEntry>. These vectors can 00762 * be accessed by the method getLineList(). 00763 */ 00764 virtual void extractGroup1Lines(); 00765 virtual void extractGroup2Lines(); 00766 virtual void extractGroup3Lines(); 00767 virtual void extractGroup4Lines(); 00768 00769 /** 00770 * The arc extraction methods. They extract arcs by tracking lines. 00771 * For performance and review reasons there are 4 methods (one per segment group). 00772 * Results are stored in STL vectors of type <arcEntry>. These vectors can 00773 * be accessed by the method getArcList(). 00774 */ 00775 virtual void extractGroup1Arcs(); 00776 virtual void extractGroup2Arcs(); 00777 virtual void extractGroup3Arcs(); 00778 virtual void extractGroup4Arcs(); 00779 00780 /** 00781 * The extended arc extraction methods. They extract extended arcs by tracking arcs. 00782 * For performance and review reasons there are 4 methods (one per segment group). 00783 * Results are stored in STL vectors of type <extArcEntry>. These vectors can 00784 * be accessed by the method getExtArcList(). 00785 */ 00786 virtual void extractExtGroup1Arcs(); 00787 virtual void extractExtGroup2Arcs(); 00788 virtual void extractExtGroup3Arcs(); 00789 virtual void extractExtGroup4Arcs(); 00790 00791 /** 00792 * Calculates and checks the tangent matching of two extended arcs. 00793 * @param extarc1 first extarc to be checked 00794 * @param extarc2 second extarc to be checked 00795 * @param Xest x coordinate of estimated circle center 00796 * @param Yest y coordinate of estimated circle center 00797 * @return the number of tangent mismatches 00798 */ 00799 virtual int checkExtArcTangents(const extArcEntry &extarc1, 00800 const extArcEntry &extarc2, 00801 const double Xest, 00802 const double Yest); 00803 00804 /** 00805 * The circle extraction method. 00806 * Circles are extracted by merging extended arcs. Each extArc will be checked 00807 * against each other. This algorithm has a squared complexity but as long as 00808 * the number of extArcs doesn't exceed a few hundred, it will be fast enough. 00809 */ 00810 virtual void extractCircles(); 00811 00812 /** 00813 * estimates circle parameters by using a least square fitting algorithm. 00814 * @param idxlist vector with arc line index numbers 00815 * @param group group number of the arc lines 00816 * @param Xest the estimated x-coordinate 00817 * @param Yest the estimated y-coordinate 00818 * @param R2est the estimated squared radius 00819 * @return true if calculation was successful otherwise false 00820 */ 00821 virtual bool estimateCircle(std::vector<int> &idxlist, const int group, 00822 double &Xest, double &Yest, double &R2est); 00823 00824 /** 00825 * estimates circle parameters by using a least square fitting algorithm. 00826 * @param idxlist1 first vector with arc line index numbers 00827 * @param group1 group number of the first arc lines 00828 * @param idxlist2 second vector with arc line index numbers 00829 * @param group2 group number of the second arc lines 00830 * @param Xest the estimated x-coordinate 00831 * @param Yest the estimated y-coordinate 00832 * @param R2est the estimated squared radius 00833 * @return true if calculation was successful otherwise false 00834 */ 00835 virtual bool estimateCircle(std::vector<int> &idxlist1, const int group1, 00836 std::vector<int> &idxlist2, const int group2, 00837 double &Xest, double &Yest, double &R2est); 00838 00839 /** 00840 * estimates circle parameters by using a least square fitting algorithm. 00841 * @param arc1 first extended arc 00842 * @param arc2 second extended arc 00843 * @param Xest the estimated x-coordinate 00844 * @param Yest the estimated y-coordinate 00845 * @param R2est the estimated squared radius 00846 * @return true if calculation was successful otherwise false 00847 */ 00848 virtual bool estimateCircle(const extArcEntry &arc1, const extArcEntry &arc2, 00849 double &Xest, double &Yest, double &R2est); 00850 00851 00852 /** 00853 * estimates circle parameters by using a least square fitting algorithm. 00854 * @param start1 startpoint of 1st extended arc 00855 * @param end1 endpoint of 1st extended arc 00856 * @param start2 startpoint of 2nd extended arc 00857 * @param end2 endpoint of 2nd extended arc 00858 * @param Xest the estimated x-coordinate 00859 * @param Yest the estimated y-coordinate 00860 * @param R2est the estimated squared radius 00861 * @return true if calculation was successful otherwise false 00862 */ 00863 virtual bool estimateCircle(const ipoint &start1, const ipoint &end1, 00864 const ipoint &start2, const ipoint &end2, 00865 double &Xest, double &Yest, double &R2est); 00866 00867 /** 00868 * estimates circle parameters by using a least square fitting algorithm. 00869 * @param lines vector with arc lines 00870 * @param Xest the estimated x-coordinate 00871 * @param Yest the estimated y-coordinate 00872 * @param R2est the estimated squared radius 00873 * @return true if calculation was successful otherwise false 00874 */ 00875 virtual bool estimateCircle(std::vector<lineEntry> &lines, 00876 double &Xest, double &Yest, double &R2est); 00877 00878 /** 00879 * The segment containers. (to allow easier implementation 00880 * the arraysize is 5 although only 4 conatainers are used) 00881 * m_vecSegments[1..4] contain segment groups I..IV, 00882 * m_vecSegments[0] is not used. 00883 */ 00884 std::vector<segmEntry> m_vecSegments[5]; 00885 00886 /** 00887 * The line containers. 00888 * m_vecLines[1..4] contain line groups I..IV, 00889 * m_vecLines[0] contains all lines. 00890 */ 00891 std::vector<lineEntry> m_vecLines[5]; 00892 00893 /** 00894 * The arc containers. 00895 * m_vecArcs[1..4] contain arc groups I..IV, 00896 * m_vecArcs[0] contains all arcs. 00897 */ 00898 std::vector<arcEntry> m_vecArcs[5]; 00899 00900 /** 00901 * The extended arc containers. 00902 * m_vecExtArcs[1..4] contain extArc groups I..IV, 00903 * m_vecExtArcs[0] contains all extended arcs. 00904 */ 00905 std::vector<extArcEntry> m_vecExtArcs[5]; 00906 00907 /** 00908 * The circle container. 00909 */ 00910 std::vector<circleEntry> m_vecCircles; 00911 00912 /** 00913 * The input image width. Needed for coordinate transformation 00914 * when extracting diagonal lines. 00915 */ 00916 int m_iWidth; 00917 00918 /** 00919 * The number of pre-allocated vector entries. 00920 */ 00921 static const int SegmPreallocation; 00922 static const int LinePreallocation; 00923 static const int ArcPreallocation; 00924 static const int ExtArcPreallocation; 00925 static const int CirclePreallocation; 00926 00927 // Circle constant 00928 static const double PI; 00929 00930 }; 00931 } 00932 00933 #endif