Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/ImageProcessor/RasterImageProcessor/REdgeDetection.cpp

Go to the documentation of this file.
00001 /**
00002 * @file Modules/ImageProcessor/RasterImageProcessor/REdgeDetection.cpp
00003 * 
00004 * Implementation of REdgeDetection.
00005 *
00006 * @author <A href="mailto:sadprofessor@web.de">Bernd Schmidt</A>
00007 */
00008 
00009 #include "REdgeDetection.h"
00010 #include "Tools/Location.h"
00011 #include <math.h>
00012 
00013 enum{DEFAULT_EDGE_THRESHOLD = 12};
00014 
00015 REdgeDetection::REdgeDetection(
00016                      ImageProcessor& processor)
00017   :ip(processor),
00018   susanDetector(8),
00019   threshold(DEFAULT_EDGE_THRESHOLD)
00020 {
00021 
00022 }
00023 
00024 REdgeDetection::~REdgeDetection(){
00025 }
00026 
00027 
00028 bool REdgeDetection::scanEast(int& x, int& y){
00029   if (!insideImage(x,y)) return false;
00030   int voteBuffer = 0;
00031   int vote = fastCrossEdgeVote(x,y);
00032   int x2 = ip.image.cameraInfo.resolutionWidth-1;
00033 
00034   while(x < x2){
00035     if (vote > threshold || voteBuffer != 0){
00036       if (voteBuffer < vote) voteBuffer = vote;
00037       else{
00038         x--; 
00039         return true; //edge found (found local maximum)
00040       }
00041     }   
00042     x++;
00043     vote = fastCrossEdgeVote(x,y);
00044   }
00045 
00046   if (vote > threshold){
00047     x--;
00048     return true; //edgeFound (vote high enough, so found edge on Border)
00049   }
00050   else return false; // noEdgeFound
00051 }
00052 
00053 bool REdgeDetection::scanWest(int& x, int& y){
00054   if (!insideImage(x,y)) return false;
00055   int voteBuffer = 0;
00056   int vote = fastCrossEdgeVote(x,y);
00057 
00058   while(x > 1){
00059     if (vote > threshold || voteBuffer != 0){
00060       if (voteBuffer < vote) voteBuffer = vote;
00061       else{
00062         x++; 
00063         return true; //edge found (found local maximum)
00064       }
00065     }   
00066     x--;
00067     vote = fastCrossEdgeVote(x,y);
00068   }
00069 
00070   if (vote > threshold){
00071     x++;
00072     return true; //edgeFound (vote high enough, so found edge on Border)
00073   }
00074   else return false; // noEdgeFound
00075 }
00076   
00077 bool REdgeDetection::scanNorth(int& x, int& y){
00078   if(!insideImage(x,y)) return false;
00079   int voteBuffer = 0;
00080   int vote = fastCrossEdgeVote(x,y);
00081 
00082   while(y > 1){
00083     if (vote > threshold || voteBuffer != 0){
00084       if (voteBuffer < vote) voteBuffer = vote;
00085       else{
00086         y++; 
00087         return true; //edge found (found local maximum)
00088       }
00089     }   
00090     y--;
00091     vote = fastCrossEdgeVote(x,y);
00092   }
00093 
00094   if (vote > threshold){
00095     y++;
00096     return true; //edgeFound (vote high enough, so found edge on Border)
00097   }
00098   else return false; // noEdgeFound
00099 }
00100 
00101 bool REdgeDetection::scanSouth(int& x, int& y){
00102   if (!insideImage(x,y)) return false;
00103   int voteBuffer = 0;
00104   int vote = fastCrossEdgeVote(x,y);
00105   int y2 = ip.image.cameraInfo.resolutionHeight -2;
00106 
00107   while(y < y2){
00108     if (vote > threshold || voteBuffer != 0){
00109       if (voteBuffer < vote) voteBuffer = vote;
00110       else{
00111         y--; 
00112         return true; //edge found (found local maximum)
00113       }
00114     }   
00115     y++;
00116     vote = fastCrossEdgeVote(x,y);
00117   }
00118 
00119   if (vote > threshold){
00120     y--;
00121     return true; //edgeFound (vote high enough, so found edge on Border)
00122   }
00123   else return false; // noEdgeFound
00124 }
00125 
00126 bool REdgeDetection::ballScanEast(int& x, int& y){
00127   int voteBuffer = 0;
00128   int vote = ballEdgeVote(x,y);
00129 
00130   while(vote > -1){
00131     if (vote > threshold || voteBuffer != 0){
00132       if (voteBuffer < vote) voteBuffer = vote;
00133       else{
00134         x--; 
00135         return true; //edge found (found local maximum)
00136       }
00137     }   
00138     x++;
00139     vote = ballEdgeVote(x,y);
00140   }
00141 
00142   if (vote > threshold){
00143     x--;
00144     return true; //edgeFound (vote high enough, so found edge on Border)
00145   }
00146   else return false; // noEdgeFound
00147 }
00148 
00149 bool REdgeDetection::ballScanWest(int& x, int& y){
00150   int voteBuffer = 0;
00151   int vote = ballEdgeVote(x,y);
00152 
00153   while(vote > -1){
00154     if (vote > threshold || voteBuffer != 0){
00155       if (voteBuffer < vote) voteBuffer = vote;
00156       else{
00157         x++; 
00158         return true; //edge found (found local maximum)
00159       }
00160     }   
00161     x--;
00162     vote = ballEdgeVote(x,y);
00163   }
00164 
00165   if (vote > threshold){
00166     x++;
00167     return true; //edgeFound (vote high enough, so found edge on Border)
00168   }
00169   else return false; // noEdgeFound
00170 }
00171 
00172 bool REdgeDetection::scan(int& x,int& y,Vector2<double> direction){
00173   cx = 1;
00174   cy = 1;
00175 
00176   if (direction.x < 0) cx = -1;
00177   if (direction.y < 0) cy = -1;
00178 
00179   tempX = x;
00180   tempY = y;
00181 
00182   int vote = crossEdgeVote(x,y);
00183   int buffer = 0;
00184   if (vote > threshold) buffer = vote;
00185 
00186   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00187 
00188   dx = abs((int)(direction.x * 500));
00189   dy = abs((int)(direction.y * 500));
00190 
00191   if (dx > dy){
00192     e = dx - 2*dy;
00193     f = 2*(dx - dy);
00194     g = -2*dy;
00195     //setPixel(0,0)
00196      
00197     for (x+=cx;vote != -1;x+=cx) {
00198       if (e<0) {
00199         y+=cy;
00200         e+=f;
00201       }
00202       else {
00203         e+=g;
00204       }
00205       //setPixel(x,y)
00206       //DOT(imageProcessor_general,x,y,
00207       //  Drawings::white, Drawings::red);
00208       vote = crossEdgeVote(x,y);
00209       
00210       if (vote > threshold || buffer != 0){
00211         if (buffer < vote) buffer = vote;
00212         else{
00213           x = tempX;
00214           y = tempY;
00215           return true; //edge found (found local maximum)
00216         }
00217       }
00218 
00219       tempX = x;
00220       tempY = y;
00221     }
00222   }
00223   else{
00224     e = dy - 2*dx;
00225     f = 2*(dy - dx);
00226     g = -2*dx;
00227     //setPixel(0,0)
00228 
00229      
00230     for (y+=cy;vote != -1;y+=cy) {
00231       if (e<0) {
00232         x+=cx;
00233         e+=f;
00234       }
00235       else {
00236         e+=g;
00237       }
00238       //setPixel(x,y)
00239       //DOT(imageProcessor_general,x,y,
00240       //  Drawings::white, Drawings::red);
00241       vote = crossEdgeVote(x,y);
00242 
00243       if (vote > threshold || buffer != 0){
00244         if (buffer < vote) buffer = vote;
00245         else{
00246           x = tempX;
00247           y = tempY;
00248           return true; //edge found (found local maximum)
00249         }
00250       }
00251       
00252       tempX = x;
00253       tempY = y;
00254     }
00255   }
00256 
00257   if (buffer != 0){
00258         x = tempX;
00259         y = tempY;
00260         return true; //edge found (found edge on border)
00261   }
00262 
00263   return false; //no edge found
00264 }
00265 
00266 bool REdgeDetection::bufferedScan(int& x,int& y,Vector2<double> direction){ 
00267   
00268   cx = 1;
00269   cy = 1;
00270 
00271   if (direction.x < 0) cx = -1;
00272   if (direction.y < 0) cy = -1;
00273 
00274   tempX = x;
00275   tempY = y;
00276 
00277   int vote = crossEdgeVote(x,y);
00278   currentColor = lastColor = getColor(x,y);
00279   bufferSize = 0;
00280 
00281   int buffer = 0;
00282   if (vote > threshold) buffer = vote;
00283 
00284   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00285 
00286   dx = abs((int)(direction.x * 500));
00287   dy = abs((int)(direction.y * 500));
00288 
00289   if (dx > dy){
00290     e = dx - 2*dy;
00291     f = 2*(dx - dy);
00292     g = -2*dy;
00293     //setPixel(0,0)
00294      
00295     for (x+=cx;vote != -1;x+=cx) {
00296       if (e<0) {
00297         y+=cy;
00298         e+=f;
00299       }
00300       else {
00301         e+=g;
00302       }
00303       //setPixel(x,y)
00304       //DOT(imageProcessor_general,x,y,
00305       //  Drawings::white, Drawings::red);
00306       vote = crossEdgeVote(x,y);
00307       currentColor = getColor(x,y);
00308       colorRange++;
00309       
00310       if (currentColor != lastColor){
00311         addColor();
00312         // there are to many colorChanges between two edge-points
00313         if (bufferSize > 19) return false;
00314       } 
00315 
00316       if (vote > threshold || buffer != 0){
00317         if (buffer < vote) buffer = vote;
00318         else{
00319           x = tempX;
00320           y = tempY;
00321           if (colorRange!=0){
00322             lastColor = currentColor;
00323             addColor();
00324           }
00325           return true; //edge found (found local maximum)
00326         }
00327       }
00328 
00329       tempX = x;
00330       tempY = y;
00331       lastColor = currentColor;
00332     }
00333   }
00334   else{
00335     e = dy - 2*dx;
00336     f = 2*(dy - dx);
00337     g = -2*dx;
00338     //setPixel(0,0)
00339 
00340      
00341     for (y+=cy;vote != -1;y+=cy) {
00342       if (e<0) {
00343         x+=cx;
00344         e+=f;
00345       }
00346       else {
00347         e+=g;
00348       }
00349       //setPixel(x,y)
00350       //DOT(imageProcessor_general,x,y,
00351       //  Drawings::white, Drawings::red);
00352       vote = crossEdgeVote(x,y);
00353       currentColor = getColor(x,y);
00354       colorRange++;
00355       
00356       if (currentColor != lastColor){
00357         addColor();
00358         // there are to many colorChanges between two edge-points
00359         if (bufferSize > 19) return false;
00360       } 
00361 
00362       if (vote > threshold || buffer != 0){
00363         if (buffer < vote) buffer = vote;
00364         else{
00365           if (colorRange!=0){
00366             lastColor = currentColor;
00367             addColor();
00368           }
00369           x = tempX;
00370           y = tempY;
00371           return true; //edge found (found local maximum)
00372         }
00373       }
00374       
00375       tempX = x;
00376       tempY = y;
00377       lastColor = currentColor;
00378     }
00379   }
00380 
00381   if (buffer != 0){
00382         if (colorRange!=0){
00383           lastColor = currentColor;
00384           addColor();
00385         }
00386         x = tempX;
00387         y = tempY;
00388         return true; //edge found (found edge on border)
00389   }
00390 
00391   return false; //no edge found
00392 }
00393 
00394 bool REdgeDetection::bufferedScan(int& x,int& y){ 
00395   
00396   currentColor = lastColor = getColor(x,y);
00397   colorRange = 0;
00398   bufferSize = 0;
00399 
00400   //skipping 3 pixels, not to detect 1 edge 2 times
00401   //this will be replaced with threshold hysteresis
00402   for (int i = 0;i<3;i++){
00403     skip(x,y);
00404     currentColor = getColor(x,y);
00405     colorRange++;
00406     if (currentColor != lastColor)addColor();
00407     lastColor = currentColor;
00408   }
00409   
00410   tempX = x;
00411   tempY = y;
00412 
00413   int vote = crossEdgeVote(x,y);
00414 
00415   int buffer = 0;
00416   if (vote > threshold) buffer = vote;
00417 
00418   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00419 
00420   if (dx > dy){    
00421     for (x+=cx;vote != -1;x+=cx) {
00422       if (e<0) {
00423         y+=cy;
00424         e+=f;
00425       }
00426       else {
00427         e+=g;
00428       }
00429       //setPixel(x,y)
00430       //DOT(imageProcessor_general,x,y,
00431       //  Drawings::white, Drawings::red);
00432       vote = crossEdgeVote(x,y);
00433       currentColor = getColor(x,y);
00434       colorRange++;
00435       
00436       if (currentColor != lastColor){
00437         addColor();
00438         // there are to many colorChanges between two edge-points
00439         if (bufferSize > 19) return false; 
00440       } 
00441 
00442       if (vote > threshold || buffer != 0){
00443         if (buffer < vote) buffer = vote;
00444         else{
00445           x = tempX;
00446           y = tempY;
00447           if (colorRange!=0){
00448             lastColor = currentColor;
00449             addColor();
00450           }
00451           return true; //edge found (found local maximum)
00452         }
00453       }
00454 
00455       tempX = x;
00456       tempY = y;
00457       lastColor = currentColor;
00458     }
00459   }
00460   else{
00461     for (y+=cy;vote != -1;y+=cy) {
00462       if (e<0) {
00463         x+=cx;
00464         e+=f;
00465       }
00466       else {
00467         e+=g;
00468       }
00469       //setPixel(x,y)
00470       //DOT(imageProcessor_general,x,y,
00471       //  Drawings::white, Drawings::red);
00472       vote = crossEdgeVote(x,y);
00473       currentColor = getColor(x,y);
00474       colorRange++;
00475       
00476       if (currentColor != lastColor){
00477         addColor();
00478       } 
00479 
00480       if (vote > threshold || buffer != 0){
00481         if (buffer < vote) buffer = vote;
00482         else{
00483           if (colorRange!=0){
00484             lastColor = currentColor;
00485             addColor();
00486           }
00487           x = tempX;
00488           y = tempY;
00489           return true; //edge found (found local maximum)
00490         }
00491       }
00492       
00493       tempX = x;
00494       tempY = y;
00495       lastColor = currentColor;
00496     }
00497   }
00498 
00499   if (buffer != 0){
00500         if (colorRange!=0){
00501           addColor();
00502         }
00503         x = tempX;
00504         y = tempY;
00505         return true; //edge found (found edge on border)
00506   }
00507 
00508   return false; //no edge found
00509 }
00510 
00511 bool REdgeDetection::scanField(int& x,int& y,Vector2<double> direction){
00512   cx = 1;
00513   cy = 1;
00514 
00515   if (direction.x < 0) cx = -1;
00516   if (direction.y < 0) cy = -1;
00517 
00518   tempX = x;
00519   tempY = y;
00520 
00521   int vote = fieldEdgeVote(x,y);
00522   int buffer = 0;
00523   if (vote > threshold) buffer = vote;
00524 
00525   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00526 
00527   dx = abs((int)(direction.x * 500));
00528   dy = abs((int)(direction.y * 500));
00529 
00530   if (dx > dy){
00531     e = dx - 2*dy;
00532     f = 2*(dx - dy);
00533     g = -2*dy;
00534     //setPixel(0,0)
00535      
00536     for (x+=cx;vote != -1;x+=cx) {
00537       if (e<0) {
00538         y+=cy;
00539         e+=f;
00540       }
00541       else {
00542         e+=g;
00543       }
00544       //setPixel(x,y)
00545       //DOT(imageProcessor_general,x,y,
00546       //  Drawings::white, Drawings::red);
00547       vote = fieldEdgeVote(x,y);
00548       
00549       if (vote > threshold || buffer != 0){
00550         if (buffer < vote) buffer = vote;
00551         else{
00552           x = tempX;
00553           y = tempY;
00554           return true; //edge found (found local maximum)
00555         }
00556       }
00557 
00558       tempX = x;
00559       tempY = y;
00560     }
00561   }
00562   else{
00563     e = dy - 2*dx;
00564     f = 2*(dy - dx);
00565     g = -2*dx;
00566     //setPixel(0,0)
00567 
00568      
00569     for (y+=cy;vote != -1;y+=cy) {
00570       if (e<0) {
00571         x+=cx;
00572         e+=f;
00573       }
00574       else {
00575         e+=g;
00576       }
00577       //setPixel(x,y)
00578       //DOT(imageProcessor_general,x,y,
00579       //  Drawings::white, Drawings::red);
00580       vote = fieldEdgeVote(x,y);
00581 
00582       if (vote > threshold || buffer != 0){
00583         if (buffer < vote) buffer = vote;
00584         else{
00585           x = tempX;
00586           y = tempY;
00587           return true; //edge found (found local maximum)
00588         }
00589       }
00590       
00591       tempX = x;
00592       tempY = y;
00593     }
00594   }
00595 
00596   if (buffer != 0){
00597     x = tempX;
00598     y = tempY;
00599     return true; //edge found (found edge on border)
00600   }
00601 
00602   return false; //no edge found
00603 }
00604 
00605 bool REdgeDetection::scanField(int& x,int& y){
00606 
00607   tempX = x;
00608   tempY = y;
00609 
00610   int vote = fieldEdgeVote(x,y);
00611   int buffer = 0;
00612   if (vote > threshold) buffer = vote;
00613 
00614   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00615   if (dx > dy){    
00616     for (x+=cx;vote != -1;x+=cx) {
00617       if (e<0) {
00618         y+=cy;
00619         e+=f;
00620       }
00621       else {
00622         e+=g;
00623       }
00624       //setPixel(x,y)
00625       //DOT(imageProcessor_general,x,y,
00626       //  Drawings::white, Drawings::red);
00627       vote = fieldEdgeVote(x,y);
00628       
00629       if (vote > threshold || buffer != 0){
00630         if (buffer < vote) buffer = vote;
00631         else{
00632           x = tempX;
00633           y = tempY;
00634           return true; //edge found (found local maximum)
00635         }
00636       }
00637 
00638       tempX = x;
00639       tempY = y;
00640     }
00641   }
00642   else{
00643     for (y+=cy;vote != -1;y+=cy) {
00644       if (e<0) {
00645         x+=cx;
00646         e+=f;
00647       }
00648       else {
00649         e+=g;
00650       }
00651       //setPixel(x,y)
00652       //DOT(imageProcessor_general,x,y,
00653       //  Drawings::white, Drawings::red);
00654       vote = fieldEdgeVote(x,y);
00655 
00656       if (vote > threshold || buffer != 0){
00657         if (buffer < vote) buffer = vote;
00658         else{
00659           x = tempX;
00660           y = tempY;
00661           return true; //edge found (found local maximum)
00662         }
00663       }     
00664       tempX = x;
00665       tempY = y;
00666     }
00667   }
00668 
00669   if (buffer != 0){
00670         x = tempX;
00671         y = tempY;
00672         return true; //edge found (found edge on border)
00673   }
00674 
00675   return false; //no edge found
00676 }
00677 
00678 bool REdgeDetection::scan(int& x,int& y,int x1,int y1){
00679   cx = 1;
00680   cy = 1;
00681 
00682   dx = x1 - x;
00683   dy = y1 - y;
00684 
00685   if (dx < 0) cx = -1;
00686   if (dy < 0) cy = -1;
00687 
00688   tempX = x;
00689   tempY = y;
00690 
00691   int vote = crossEdgeVote(x,y);
00692   int buffer = 0;
00693   if (vote > threshold) buffer = vote;
00694 
00695   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00696   if (dx > dy){
00697     e = dx - 2*dy;
00698     f = 2*(dx - dy);
00699     g = -2*dy;
00700     //setPixel(0,0)
00701      
00702     for (x+=cx;x<x1;x+=cx) {
00703       if (e<0) {
00704         y+=cy;
00705         e+=f;
00706       }
00707       else {
00708         e+=g;
00709       }
00710       //setPixel(x,y)
00711       //DOT(imageProcessor_general,x,y,
00712       //  Drawings::white, Drawings::red);
00713       vote = fastCrossEdgeVote(x,y);
00714       
00715       if (vote > threshold || buffer != 0){
00716         if (buffer < vote) buffer = vote;
00717         else{
00718           x = tempX;
00719           y = tempY;
00720           return true; //edge found (found local maximum)
00721         }
00722       }
00723 
00724       tempX = x;
00725       tempY = y;
00726     }
00727   }
00728   else{
00729     e = dy - 2*dx;
00730     f = 2*(dy - dx);
00731     g = -2*dx;
00732     //setPixel(0,0)
00733 
00734      
00735     for (y+=cy;y<y1;y+=cy) {
00736       if (e<0) {
00737         x+=cx;
00738         e+=f;
00739       }
00740       else {
00741         e+=g;
00742       }
00743       //setPixel(x,y)
00744       //DOT(imageProcessor_general,x,y,
00745       //  Drawings::white, Drawings::red);
00746       vote = fastCrossEdgeVote(x,y);
00747 
00748       if (vote > threshold || buffer != 0){
00749         if (buffer < vote) buffer = vote;
00750         else{
00751           x = tempX;
00752           y = tempY;
00753           return true; //edge found (found local maximum)
00754         }
00755       }
00756       
00757       tempX = x;
00758       tempY = y;
00759     }
00760   }
00761 
00762   if (buffer != 0){
00763         x = tempX;
00764         y = tempY;
00765         return true; //edge found (found edge on border)
00766   }
00767 
00768   return false; //no edge found
00769 }
00770 
00771 bool REdgeDetection::colorScan(int& x,int& y,int x1,int y1,colorClass& lastColor){
00772   cx = 1;
00773   cy = 1;
00774 
00775   colorClass start = getColor(x,y);
00776   colorClass current = start;
00777   
00778   dx = x1 - x;
00779   dy = y1 - y;
00780 
00781   if (dx < 0) cx = -1;
00782   if (dy < 0) cy = -1;
00783 
00784   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00785   if (dx > dy){
00786     e = dx - 2*dy;
00787     f = 2*(dx - dy);
00788     g = -2*dy;
00789     //TODO(schmidtb): remove inefficient code
00790     int count = 0; //not to write more code and hold the order
00791     //setPixel(0,0)
00792      
00793     for (x+=cx ; current == start && count < dx ; x+=cx,count++) {
00794       if (e<0) {
00795         y+=cy;
00796         e+=f;
00797       }
00798       else {
00799         e+=g;
00800       }
00801       //setPixel(x,y)
00802       //DOT(imageProcessor_general,x,y,
00803       //  Drawings::white, Drawings::red);
00804       current = getColor(x,y);
00805     }
00806   }
00807   else{
00808     e = dy - 2*dx;
00809     f = 2*(dy - dx);
00810     g = -2*dx;
00811     int count = 0;
00812     //setPixel(0,0)
00813     
00814      
00815     for (y+=cy; current==start && count<dy; y+=cy,count++) {
00816       if (e<0) {
00817         x+=cx;
00818         e+=f;
00819       }
00820       else {
00821         e+=g;
00822       }
00823       //setPixel(x,y)
00824       //DOT(imageProcessor_general,x,y,
00825       //  Drawings::white, Drawings::red);
00826       current = getColor(x,y);
00827     }
00828   }
00829 
00830   if (current == -1){ 
00831     lastColor = noColor;
00832     return false;
00833   }
00834   else {
00835     lastColor = start;
00836     return true;
00837   }
00838 }
00839 
00840 bool REdgeDetection::colorScan(int& x,int& y,Vector2<double> direction,colorClass& lastColor){
00841   cx = 1;
00842   cy = 1;
00843 
00844   colorClass start = getColor(x,y);
00845   colorClass current = start;
00846 
00847   if (direction.x < 0) cx = -1;
00848   if (direction.y < 0) cy = -1;
00849 
00850 
00851   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00852 
00853   dx = abs((int)(direction.x * 500));
00854   dy = abs((int)(direction.y * 500));
00855 
00856   if (dx > dy){
00857     e = dx - 2*dy;
00858     f = 2*(dx - dy);
00859     g = -2*dy;
00860     //setPixel(0,0)
00861      
00862     for (x+=cx;current == start && current != -1;x+=cx) {
00863       if (e<0) {
00864         y+=cy;
00865         e+=f;
00866       }
00867       else {
00868         e+=g;
00869       }
00870       //setPixel(x,y)
00871       //DOT(imageProcessor_general,x,y,
00872       //  Drawings::white, Drawings::red);
00873       current = getColor(x,y);
00874     }
00875   }
00876   else{
00877     e = dy - 2*dx;
00878     f = 2*(dy - dx);
00879     g = -2*dx;
00880     //setPixel(0,0)
00881 
00882      
00883     for (y+=cy;current == start && current != -1;y+=cy) {
00884       if (e<0) {
00885         x+=cx;
00886         e+=f;
00887       }
00888       else {
00889         e+=g;
00890       }
00891       //setPixel(x,y)
00892       //DOT(imageProcessor_general,x,y,
00893       //  Drawings::white, Drawings::red);
00894       current = getColor(x,y);
00895     }
00896   }
00897 
00898   if (current == -1){ 
00899     lastColor = noColor;
00900     return false;
00901   }
00902   else {
00903     lastColor = start;
00904     return true;
00905   }
00906 }
00907 
00908 bool REdgeDetection::colorScan(int& x,int& y,colorClass& lastColor){
00909 
00910   colorClass start = getColor(x,y);
00911   colorClass current = start;
00912 
00913   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00914   if (dx > dy){    
00915     for (x+=cx;current == start && current != -1;x+=cx) {
00916       if (e<0) {
00917         y+=cy;
00918         e+=f;
00919       }
00920       else {
00921         e+=g;
00922       }
00923       //setPixel(x,y)
00924       //DOT(imageProcessor_general,x,y,
00925       //  Drawings::white, Drawings::red);
00926       current = getColor(x,y);
00927     }
00928   }
00929   else{    
00930     for (y+=cy;current == start && current != -1;y+=cy) {
00931       if (e<0) {
00932         x+=cx;
00933         e+=f;
00934       }
00935       else {
00936         e+=g;
00937       }
00938       //setPixel(x,y)
00939       //DOT(imageProcessor_general,x,y,
00940       //  Drawings::white, Drawings::red);
00941       current = getColor(x,y);
00942     }
00943   }
00944 
00945   if (current == -1){ 
00946     lastColor = noColor;
00947     return false;
00948   }
00949   else {
00950     lastColor = start;
00951     return true;
00952   }
00953 }
00954 
00955 bool REdgeDetection::susanScan(int& x,int& y,Vector2<double> direction){
00956   cx = 1;
00957   cy = 1;
00958 
00959   if (direction.x < 0) cx = -1;
00960   if (direction.y < 0) cy = -1;
00961 
00962   tempX = x;
00963   tempY = y;
00964 
00965   int vote = susanVote(x,y);
00966   int buffer = 0;
00967   if (vote > 0) buffer = vote;
00968 
00969   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
00970 
00971   dx = abs((int)(direction.x * 500));
00972   dy = abs((int)(direction.y * 500));
00973 
00974   if (dx > dy){
00975     e = dx - 2*dy;
00976     f = 2*(dx - dy);
00977     g = -2*dy;
00978     //setPixel(0,0)
00979      
00980     for (x+=cx;vote != -1;x+=cx) {
00981       if (e<0) {
00982         y+=cy;
00983         e+=f;
00984       }
00985       else {
00986         e+=g;
00987       }
00988       //setPixel(x,y)
00989       //DOT(imageProcessor_general,x,y,
00990       //  Drawings::white, Drawings::red);
00991       vote = susanVote(x,y);
00992       
00993       if (vote > 0 || buffer != 0){
00994         if (buffer < vote) buffer = vote;
00995         else{
00996           x = tempX;
00997           y = tempY;
00998           return true; //edge found (found local maximum)
00999         }
01000       }
01001 
01002       tempX = x;
01003       tempY = y;
01004     }
01005   }
01006   else{
01007     e = dy - 2*dx;
01008     f = 2*(dy - dx);
01009     g = -2*dx;
01010     //setPixel(0,0)
01011 
01012      
01013     for (y+=cy;vote != -1;y+=cy) {
01014       if (e<0) {
01015         x+=cx;
01016         e+=f;
01017       }
01018       else {
01019         e+=g;
01020       }
01021       //setPixel(x,y)
01022       //DOT(imageProcessor_general,x,y,
01023       //  Drawings::white, Drawings::red);
01024       vote = susanVote(x,y);
01025 
01026       if (vote > 0 || buffer != 0){
01027         if (buffer < vote) buffer = vote;
01028         else{
01029           x = tempX;
01030           y = tempY;
01031           return true; //edge found (found local maximum)
01032         }
01033       }
01034       
01035       tempX = x;
01036       tempY = y;
01037     }
01038   }
01039 
01040   if (buffer != 0){
01041         x = tempX;
01042         y = tempY;
01043         return true; //edge found (found edge on border)
01044   }
01045 
01046   return false; //no edge found
01047 }
01048 
01049 bool REdgeDetection::scan(int& x,int& y){
01050 
01051   tempX = x;
01052   tempY = y;
01053 
01054   int vote = crossEdgeVote(x,y);
01055   int buffer = 0;
01056   if (vote > threshold) buffer = vote;
01057 
01058   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
01059   if (dx > dy){    
01060     for (x+=cx;vote != -1;x+=cx) {
01061       if (e<0) {
01062         y+=cy;
01063         e+=f;
01064       }
01065       else {
01066         e+=g;
01067       }
01068       //setPixel(x,y)
01069       //DOT(imageProcessor_general,x,y,
01070       //  Drawings::white, Drawings::red);
01071       vote = crossEdgeVote(x,y);
01072       
01073       if (vote > threshold || buffer != 0){
01074         if (buffer < vote) buffer = vote;
01075         else{
01076           x = tempX;
01077           y = tempY;
01078           return true; //edge found (found local maximum)
01079         }
01080       }
01081 
01082       tempX = x;
01083       tempY = y;
01084     }
01085   }
01086   else{
01087     for (y+=cy;vote != -1;y+=cy) {
01088       if (e<0) {
01089         x+=cx;
01090         e+=f;
01091       }
01092       else {
01093         e+=g;
01094       }
01095       //setPixel(x,y)
01096       //DOT(imageProcessor_general,x,y,
01097       //  Drawings::white, Drawings::red);
01098       vote = crossEdgeVote(x,y);
01099 
01100       if (vote > threshold || buffer != 0){
01101         if (buffer < vote) buffer = vote;
01102         else{
01103           x = tempX;
01104           y = tempY;
01105           return true; //edge found (found local maximum)
01106         }
01107       }
01108       
01109       tempX = x;
01110       tempY = y;
01111     }
01112   }
01113 
01114   if (buffer != 0){
01115         x = tempX;
01116         y = tempY;
01117         return true; //edge found (found edge on border)
01118   }
01119 
01120   return false; //no edge found
01121 }
01122 
01123 
01124 /*
01125  * Change log :
01126  *
01127  * $Log: REdgeDetection.cpp,v $
01128  * Revision 1.1  2004/09/09 11:08:04  spranger
01129  * renamed GT2004EdgeDetection to REdgeDetection for consistency
01130  *
01131  * Revision 1.4  2004/09/06 12:02:25  schmidtb
01132  * commented almost all members, removed warnings in documentation
01133 
01134  * did further code clean up
01135  *
01136  * Revision 1.3  2004/09/03 11:32:13  nistico
01137  * References to MSH2004ColorCorrector removed, now uses the unified ColorCorrector
01138  *
01139  * Revision 1.2  2004/09/02 07:59:29  schmidtb
01140  * Added RasterImageProcessor to repository, because we used it for the OpenChallenge.
01141  *
01142  * Revision 1.1  2004/05/17 11:57:04  nistico
01143  * Imported ball detection from RasterImageProcessor (integrated in MSH by Bernd in New Orleans)
01144  *
01145  * Revision 1.1  2004/04/25 17:40:18  pg_arce
01146  * stand 1. spiel
01147  *
01148  * Revision 1.4  2004/04/15 19:02:28  pg_besc
01149  * removed 3 tabs
01150  *
01151  * Revision 1.3  2004/03/25 15:10:03  pg_besc
01152  * made some changes
01153  *
01154  * Revision 1.2  2004/03/17 20:58:47  schmidtb
01155  * added new scan methods and buffering.
01156  *
01157  * Revision 1.1  2004/03/11 20:19:43  schmidtb
01158  * Established GT2004EdgeDetection.
01159  *
01160  */

Generated on Thu Sep 23 19:57:30 2004 for GT2004 by doxygen 1.3.6