00001 /*!@file Robots2/Beobot2/LaneFollowing/TV_Lane/TV_Lane.C */ 00002 // //////////////////////////////////////////////////////////////////// // 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 // //////////////////////////////////////////////////////////////////// // 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 00030 // //////////////////////////////////////////////////////////////////// // 00031 // 00032 // Primary maintainer for this file: Chin-Kai Chang <chinkaic@usc.edu> 00033 // $HeadURL: svn://ilab.usc.edu/trunk/saliency/src/Robots/Beobot2/TV_Lane.C 00034 // $ $Id: TV_Lane.C 13084 2010-03-30 02:42:00Z kai $ 00035 // 00036 ////////////////////////////////////////////////////////////////////////// 00037 //#include "Image/OpenCVUtil.H" 00038 #include "Robots/Beobot2/LaneFollowing/TV_Lane/TV_Lane.H" 00039 00040 #include "Raster/Raster.H" 00041 #include "Util/sformat.H" 00042 #include "Image/Image.H" 00043 #include "Image/DrawOps.H" // for 00044 #include "Image/ColorOps.H" // for luminance(),colorize() 00045 #include "Image/ShapeOps.H" // for rescale() 00046 #include "Image/MathOps.H" // for stdev() 00047 #include "Image/MatrixOps.H" // for matrixMult() 00048 #include "Image/CutPaste.H" // for inplacePaste() 00049 #include "Image/Transforms.H" // for segmentObject() 00050 #include "Image/Normalize.H" // for normalizeFloat() 00051 #include "Util/Timer.H" 00052 #include "Ice/BeobotEvents.ice.H" 00053 00054 00055 #include "SIFT/Keypoint.H" 00056 #include "SIFT/VisualObject.H" 00057 #include "SIFT/VisualObjectMatch.H" 00058 #include "Transport/FrameInfo.H" 00059 00060 #include "Ice/IceImageUtils.H" 00061 00062 #include "Component/ModelParam.H" 00063 #include "Component/ModelOptionDef.H" 00064 00065 #include "GUI/DebugWin.H" // for SHOWIMG() 00066 00067 #include <map> 00068 #define FOLDER "../data/logs" 00069 //#define DBNAME "Lane" 00070 #define DBNAME "outdoor" 00071 #define IMAGE_PREFIX "image_0000000000" 00072 #define WINDOW_SIZE 5 00073 // ###################################################################### 00074 TV_Lane::TV_Lane(OptionManager& mgr, 00075 const std::string& descrName, const std::string& tagName) : 00076 RobotBrainComponent(mgr, descrName, tagName), 00077 itsSmt(new SaliencyMT(mgr,descrName,tagName)), 00078 itsOfs(new OutputFrameSeries(mgr)), 00079 itsIfs(new InputFrameSeries(mgr)), 00080 itsKf(80.0,30.0), 00081 itsKfx(0), 00082 itsTimer(1000000) 00083 { 00084 setModelParamVal("InputFameDims",Dims(320,240),MC_RECURSE|MC_IGNORE_MISSING); 00085 addSubComponent(itsSmt); 00086 00087 itsOfs->addFrameDest("display");//Add default --out=display 00088 addSubComponent(itsOfs); 00089 00090 addSubComponent(itsIfs); 00091 } 00092 00093 // ###################################################################### 00094 00095 // ###################################################################### 00096 TV_Lane::~TV_Lane() 00097 { } 00098 00099 // ###################################################################### 00100 void TV_Lane::start1() 00101 { 00102 00103 } 00104 00105 // ###################################################################### 00106 void TV_Lane::registerTopics() 00107 { 00108 // subscribe to all sensor data 00109 this->registerSubscription("CameraMessageTopic"); 00110 } 00111 00112 // ###################################################################### 00113 void TV_Lane::evolve() 00114 { 00115 // if simulation 00116 drawState(); 00117 itsOfs->writeRGB(itsDispImg, "display", FrameInfo("TV_nav",SRC_POS)); 00118 //itsOfs->writeRGB(itsDispImg, "TV_nav", FrameInfo("TV_nav",SRC_POS)); 00119 } 00120 // ###################################################################### 00121 Image<PixRGB<byte> > TV_Lane::getSuperPixel(Image<PixRGB<byte> > img) 00122 { 00123 if(!img.initialized()) 00124 return Image<PixRGB<byte> >(320,240,ZEROS); 00125 // default parameters for the Superpixel segmentation 00126 float sigma = .5; uint k = 500; uint minSize = 20; 00127 int num_ccs; 00128 Image<PixRGB<byte> > sp_img = segment_image(img,sigma,k,minSize,num_ccs); 00129 00130 int w = sp_img.getWidth(); 00131 int h = sp_img.getHeight(); 00132 00133 //Look for road color, let's assume it always show up in the middle bottom 00134 //(h-5,w/2 +- 10) 00135 00136 std::vector<PixRGB<byte> > color_map; 00137 std::vector<int> color_map_count; 00138 00139 PixRGB<byte> roadColor; 00140 for(int i = -10; i<= 10;i++) 00141 { 00142 PixRGB<byte> tmp_color = sp_img.getVal((w/2) + i,h-5); 00143 00144 bool notfound = true; 00145 00146 00147 // Search color 00148 for(int j = 0; j < (int)color_map.size() && notfound ; j++) 00149 { 00150 if(color_map[j] == tmp_color) 00151 { 00152 notfound = false; 00153 color_map_count[j]++; 00154 } 00155 } 00156 if(notfound) 00157 { 00158 //This color is not in the map 00159 color_map.push_back(tmp_color); 00160 color_map_count.push_back(0); 00161 } 00162 } 00163 00164 if(color_map.size() != 1) 00165 {//if we found more than one color 00166 //Choose max count color 00167 int max = color_map_count[0]; 00168 int max_index = 0; 00169 for(int i = 1; i < (int)color_map_count.size() ; i++) 00170 { 00171 if(max < color_map_count[i]) 00172 { 00173 max = color_map_count[i]; 00174 max_index = i; 00175 } 00176 } 00177 roadColor = color_map[max_index]; 00178 LINFO("Max count color have count %d",max); 00179 } 00180 else 00181 { 00182 roadColor = color_map[0]; 00183 LINFO("Only one color (%d,%d,%d)",roadColor.red(),roadColor.green(),roadColor.blue()); 00184 } 00185 00186 // use iterator!!!!!! 00187 Image<PixRGB<byte> > output(w,h,ZEROS); 00188 for(int y = 0 ; y < h ; y ++) 00189 { 00190 for(int x = 0 ; x < w ; x ++) 00191 { 00192 PixRGB<byte> c = sp_img.getVal(x,y); 00193 //LINFO("Pixel color(%d,%d,%d)road color(%d,%d,%d)",c.red(),c.green(),c.blue(), 00194 // roadColor.red(),roadColor.green(),roadColor.blue()); 00195 if(c == roadColor) { 00196 00197 //Set road color to red 00198 output.setVal(x,y,PixRGB<byte>(255,0,0)); 00199 //LINFO("Found road pixel============"); 00200 00201 } 00202 else{ 00203 output.setVal(x,y,PixRGB<byte>(0,0,0)); 00204 // output.setVal(x,y,c); 00205 00206 } 00207 00208 } 00209 } 00210 if(!output.initialized()) 00211 return img; 00212 return output; 00213 00214 00215 00216 } 00217 // ###################################################################### 00218 00219 int TV_Lane::getVotingCount(Image<PixRGB<byte> > img,int topX,int topY,int windowSize,PixRGB<byte> bgColor) 00220 { 00221 if(!img.initialized()) 00222 return 0; 00223 00224 int w = img.getWidth(); 00225 int h = img.getHeight(); 00226 int count = 0; 00227 for(int i = topX ; i < topX + windowSize ; i++){ 00228 for(int j = topY ; j < topY + windowSize ; j++){ 00229 00230 if(i < w && j < h){ 00231 PixRGB<byte> tmp_color = img.getVal(i,j); 00232 if(tmp_color != bgColor) 00233 count++; 00234 } 00235 } 00236 } 00237 return count; 00238 00239 } 00240 // ###################################################################### 00241 PixRGB<byte> TV_Lane::getBackgroundColor(Image<PixRGB<byte> >img) 00242 { 00243 00244 int w = img.getWidth(); 00245 int h = img.getHeight(); 00246 00247 std::vector<PixRGB<byte> > color_map; 00248 std::vector<int> color_map_count; 00249 for(int i = 0; i < w; i++){ 00250 for(int j = 0 ; j < h; j++){ 00251 00252 if(i < w && j < h){ 00253 PixRGB<byte> tmp_color = img.getVal(i,j); 00254 bool notfound = true; 00255 00256 // Search color 00257 for(int k = 0; k < (int)color_map.size() && notfound ; k++) 00258 { 00259 if(color_map[k] == tmp_color) 00260 { 00261 notfound = false; 00262 color_map_count[k]++; 00263 } 00264 } 00265 if(notfound) 00266 { 00267 //This color is not in the map 00268 color_map.push_back(tmp_color); 00269 color_map_count.push_back(0); 00270 } 00271 } 00272 } 00273 } 00274 PixRGB<byte> bgColor; 00275 if(color_map.size() != 1){//if we found more than on color 00276 //Choose max count color 00277 int max = color_map_count[0]; 00278 int max_index = 0; 00279 for(int i = 1; i < (int)color_map_count.size() ; i++){ 00280 if(max < color_map_count[i]){ 00281 max = color_map_count[i]; 00282 max_index = i; 00283 } 00284 } 00285 bgColor= color_map[max_index]; 00286 LINFO("Max count color have count %d",max); 00287 }else{ 00288 bgColor = color_map[0]; 00289 } 00290 00291 return bgColor; 00292 00293 00294 } 00295 //Doing Canny Edge 00296 Image<PixRGB<byte> > TV_Lane::getCannyEdge(Image<PixRGB<byte> > img,Image<PixRGB<byte> > &rawCannyImg){ 00297 00298 //Doing Canny Edge 00299 //img = itsCurrImg; 00300 IplImage *cvImg = cvCreateImage(cvGetSize(img2ipl(luminance(img))),8,1); 00301 //IplImage *dst = cvCloneImage(cvImg); 00302 IplConvKernel* element = 0; 00303 element = cvCreateStructuringElementEx(2,2,1,1,CV_SHAPE_ELLIPSE,0); 00304 cvErode(img2ipl(luminance(img)),cvImg,element,3); 00305 cvDilate(img2ipl(luminance(img)),cvImg,element,1); 00306 CvMemStorage *s = cvCreateMemStorage(0); 00307 CvSeq *lines = 0; 00308 00309 //cvCanny(img2ipl(luminance(img)),cvImg,100,110,3); 00310 //Image<PixRGB<byte> > edgeImg = toRGB(ipl2gray(cvImg)); 00311 Image<PixRGB<byte> > edgeImg = toRGB(ipl2gray(cvImg)); 00312 return edgeImg; 00313 rawCannyImg = edgeImg; 00314 00315 lines = cvHoughLines2(cvImg,s,CV_HOUGH_PROBABILISTIC,1,CV_PI/180,80,30,10); 00316 00317 int lx1 = 0,lx2 = 0,ly1 = 0,ly2 = 0,rx1 = 0,rx2 =0 ,ry1 = 0,ry2 = 0; 00318 LINFO("Total Line %d",lines->total); 00319 for(int i = 0;i<MIN(lines->total,100);i++) 00320 { 00321 CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i); 00322 Point2D<int> pt1 = Point2D<int>(line[0].x,line[0].y); 00323 Point2D<int> pt2 = Point2D<int>(line[1].x,line[1].y); 00324 int dx = pt2.i - pt1.i; 00325 int dy = pt2.j - pt1.j; 00326 int midx = (pt1.i+pt2.i)/2; 00327 int midy = (pt1.j+pt2.j)/2; 00328 float slope = 0; 00329 if(dx*dy != 0) 00330 slope = dy/dx; 00331 PixRGB<byte > line_color; 00332 if(slope == 0.0) 00333 line_color = PixRGB<byte>(200,0,0);//Dark Red 00334 else if(slope < 0.0 && slope > -10.0) 00335 { 00336 line_color = PixRGB<byte>(128,128,200);//Light blue 00337 LDEBUG("Left edge Road!!!! %f",slope); 00338 lx1 = pt2.i - (pt2.j*slope); 00339 ly1 = 0; 00340 lx2 = pt2.i -(pt2.j-240)*slope; 00341 ly2 = 240; 00342 } 00343 else if(slope <= -10.0 ) 00344 line_color = PixRGB<byte>(0,128,0);//Green 00345 else if(slope > 0.0 && slope < 10.0) 00346 { 00347 line_color = PixRGB<byte>(0,255,0);//light green 00348 rx1 = pt2.i - pt2.j*slope; 00349 ry1 = 0; 00350 rx2 = pt2.i -(pt2.j-240)*slope; 00351 ry2 = 240; 00352 } 00353 else { 00354 line_color = PixRGB<byte>(0,0,128);//blue 00355 } 00356 if(slope != 0.0) 00357 { 00358 drawLine(edgeImg,pt1,pt2,line_color,2); 00359 char buffer[128]; 00360 sprintf(buffer,"%1.2f",slope); 00361 writeText(edgeImg,Point2D<int>(midx,midy),buffer,line_color,PixRGB<byte>(0,0,0),SimpleFont::FIXED(8)); 00362 }//end slope != 0.0 00363 00364 //find center line, using Kalman filter 00365 //int midx1 = (lx1+rx1)/2; 00366 //int midx2 = (lx2+rx2)/2; 00367 //int mid_dx = midx1 -midx2; 00368 /* 00369 if(midx1 != 0){ 00370 float fkfx = itsKf.update(midx1*1.0); 00371 //LINFO("update kalman filter old_kfx[%d],measure[%d],new_kfx[%f]",itsKfx,midx1,fkfx); 00372 00373 itsKfx = (int)fkfx; 00374 } 00375 //LINFO("Slope %f",slope); 00376 drawLine(edgeImg,Point2D<int>(itsKfx,0),Point2D<int>(itsKfx,240),PixRGB<byte>(255,255,0),2);//Yellow line 00377 */ 00378 00379 }//end for loop 00380 return edgeImg; 00381 00382 00383 } 00384 00385 // ###################################################################### 00386 Image<float> TV_Lane::getVotingBlock(Image<PixRGB<byte> > img) 00387 { 00388 if(!img.initialized()) 00389 return Image<float>(320,240,ZEROS); 00390 // default parameters for the Superpixel segmentation 00391 00392 int w = img.getWidth(); 00393 int h = img.getHeight(); 00394 PixRGB<byte> bgColor = getBackgroundColor(img); 00395 Image<float> vote_map(w/WINDOW_SIZE + 1,h/WINDOW_SIZE +1,ZEROS); 00396 char buffer[200]; 00397 for(int y = 0 ; y < h ; y += WINDOW_SIZE) 00398 { 00399 for(int x = 0 ; x < w ; x += WINDOW_SIZE) 00400 { 00401 int count = getVotingCount(img,x,y,WINDOW_SIZE,bgColor); 00402 sprintf(buffer,"%2d",count/10); 00403 //if(count > 1) 00404 // writeText(itsCurrImg,Point2D<int>(x,y),buffer,PixRGB<byte>(255,255,255),PixRGB<byte>(0,0,0),SimpleFont::FIXED(8)); 00405 int ww = WINDOW_SIZE*WINDOW_SIZE; 00406 float weight = (ww-count); 00407 //LINFO("Count:(%d,%d) %d weight %f",x,y,count,weight); 00408 if(x < w && y < h) 00409 vote_map.setVal(x/WINDOW_SIZE,y/WINDOW_SIZE,weight); 00410 00411 /* 00412 for(int i = 0;i< WINDOW_SIZE;i++){ 00413 for(int j = 0;j< WINDOW_SIZE;j++){ 00414 if(x+i<w && y+j<h) 00415 vote_map.setVal(x+i,y+j,weight); 00416 } 00417 } 00418 */ 00419 00420 00421 } 00422 } 00423 00424 // use iterator!!!!!! 00425 Image<PixRGB<byte> > output(w,h,ZEROS); 00426 for(int y = 0 ; y < h ; y ++) 00427 { 00428 for(int x = 0 ; x < w ; x ++) 00429 { 00430 00431 } 00432 } 00433 return vote_map; 00434 00435 00436 00437 } 00438 00439 // ###################################################################### 00440 Image<float> TV_Lane::updateVoteBlock(Image<float> map) 00441 { 00442 int w = map.getWidth(); 00443 int h = map.getHeight(); 00444 LINFO("Do it w,h = %d %d",w,h); 00445 Image<float> new_map(w,h,ZEROS); 00446 int ww = WINDOW_SIZE*WINDOW_SIZE; 00447 for(int y = 0 ; y < h ; y ++) 00448 { 00449 for(int x = 0 ; x < w ; x ++ ) 00450 { 00451 float root_weight = map.getVal(x,y); 00452 //float newWeight; 00453 float left_w = 0,right_w = 0,up_w = 0,down_w = 0; 00454 //update neighborhood value 00455 if(x-1 > 0) 00456 left_w = map.getVal(x-1,y); 00457 if(x+1 < w) 00458 right_w = map.getVal(x+1,y); 00459 if(y-1 > 0) 00460 up_w = map.getVal(x,y-1); 00461 if(y+1 < h) 00462 down_w = map.getVal(x,y+1); 00463 00464 //float fill = 0.2; 00465 //if black-white-black patten appear 00466 if(root_weight > ww/2)//if block is potential road block 00467 { 00468 bool keepgoing = true; 00469 int length = 0; 00470 std::vector<Point2D<int> >line; 00471 int y2 = y; 00472 while(keepgoing) 00473 { 00474 //look down five block 00475 if(y2+1 < h) 00476 { 00477 keepgoing = false; 00478 for(int child = 0;child < 1;child++) 00479 { 00480 if(x+child > 0 && x+child < w) 00481 { 00482 float childWeight = map.getVal(x+child,y2+1); 00483 if(childWeight >= root_weight) 00484 { 00485 if(length >60) 00486 LINFO("(%d,%d) weight %f count %d",x+child,y2+1,childWeight,length); 00487 if(!keepgoing)//first child found 00488 length++; 00489 keepgoing = true; 00490 line.push_back(Point2D<int>(x+child,y2+1)); 00491 new_map.setVal(x+child,y2+1,childWeight); 00492 00493 }//found child 00494 00495 }//child in range 00496 00497 }//for 6 child 00498 y2++; 00499 }else{ 00500 keepgoing = false; 00501 } 00502 00503 }//while keep going 00504 if(length > 70){ 00505 LINFO("find line length:%d",length); 00506 00507 length = 0; 00508 } 00509 }//if block is potential road block 00510 00511 /* 00512 if(root_weight > ww/2 &&left_w < ww*fill && right_w < ww*fill) 00513 { 00514 newWeight = (left_w+right_w)/2; 00515 new_map.setVal(x,y,newWeight); 00516 LINFO("L:%f R:%f C:%f N:%f",left_w,right_w,root_weight,newWeight); 00517 }else{ 00518 new_map.setVal(x,y,root_weight); 00519 00520 } 00521 00522 //if black-white-black patten appear 00523 if(root_weight > ww/2 &&up_w < ww*fill && down_w < ww*fill) 00524 { 00525 newWeight = (up_w+down_w)/2; 00526 new_map.setVal(x,y,newWeight); 00527 } 00528 */ 00529 /* 00530 for(int xx = -1; xx <= 1; xx++) 00531 { 00532 for(int yy = -1; yy <= 1; yy++) 00533 { 00534 int neighborX = x+xx; 00535 int neighborY = y+yy; 00536 00537 if(neighborX < w && neighborX >= 0 && neighborY < h && neighborY >=0) 00538 { 00539 double distance = sqrt(xx*xx + yy*yy); 00540 double normalScale = getNormalWeight(distance); 00541 double neighborWeight = map.getVal(neighborX,neighborY); 00542 double newAddWeight = normalScale*root_weight*0.05; 00543 double newWeight = 0; 00544 if(xx !=0 || yy !=0)//skip itself 00545 { 00546 newWeight = (neighborWeight + newAddWeight); 00547 }else 00548 { 00549 newWeight = root_weight; 00550 } 00551 if(newWeight > 255) 00552 newWeight = 255; 00553 00554 if(x%10 == 0 && y%10 == 0) 00555 { 00556 //LINFO("(%d,%d) + (%d,%d) rw %f nbw %f new %f newAdd %f ns %f",x,y,xx,yy,root_weight, neighborWeight,newWeight,newAddWeight,normalScale); 00557 } 00558 for(int i = 0;i< WINDOW_SIZE;i++){ 00559 for(int j = 0;j< WINDOW_SIZE;j++){ 00560 if(neighborX + i < w && neighborY+j < h) 00561 new_map.setVal(neighborX+i,neighborY+j,newWeight); 00562 } 00563 } 00564 00565 }//if 00566 00567 }//for yy 00568 }//for xx 00569 */ 00570 }//for x 00571 }//for y 00572 return new_map; 00573 } 00574 // ###################################################################### 00575 void TV_Lane::drawState() 00576 { 00577 Image<PixRGB<byte> > voteImg; 00578 int w=0,h=0; 00579 if(!itsCurrImg.initialized()){ 00580 itsCurrImg = itsIfs->readRGB(); 00581 00582 itsVoteMap = getVotingBlock(itsCurrImg); 00583 voteImg = normalizeFloat(itsVoteMap,FLOAT_NORM_0_255); 00584 w = itsCurrImg.getWidth()/2; 00585 h = itsCurrImg.getHeight()/2; 00586 itsDispImg.resize(w*4,h,ZEROS); 00587 00588 inplacePaste(itsDispImg,rescale(voteImg,w,h),Point2D<int>(w,0)); 00589 00590 itsVoteMap = updateVoteBlock(itsVoteMap); 00591 voteImg = normalizeFloat(itsVoteMap,FLOAT_NORM_0_255); 00592 inplacePaste(itsDispImg,rescale(voteImg,w,h),Point2D<int>(w*2,0)); 00593 00594 Image<PixRGB<byte> > cannyImg; 00595 cannyImg = getCannyEdge(voteImg,cannyImg); 00596 00597 inplacePaste(itsDispImg, rescale(itsCurrImg,w,h), Point2D<int>(0, 0)); 00598 inplacePaste(itsDispImg,rescale(cannyImg,w,h),Point2D<int>(w*3,0)); 00599 00600 }else{ 00601 w = itsCurrImg.getWidth()/2; 00602 h = itsCurrImg.getHeight()/2; 00603 00604 } 00605 00606 00607 //itsVoteMap = updateVoteBlock(itsVoteMap); 00608 Raster::waitForKey(); 00609 itsVoteMap = updateVoteBlock(itsVoteMap); 00610 LINFO("Do Once1"); 00611 voteImg = normalizeFloat(itsVoteMap,FLOAT_NORM_0_255); 00612 LINFO("Do Once2"); 00613 inplacePaste(itsDispImg,rescale(voteImg,w,h),Point2D<int>(w*2,0)); 00614 LINFO("Do Once3"); 00615 00616 //itsDispImg.resize(itsCurrImg.getDims()); 00617 //LINFO("Hi"); 00618 //inplacePaste(itsDispImg, itsCurrImg, Point2D<int>(0, 0)); 00619 00620 //LINFO("Do Canny"); 00621 // Do canny edge 00622 // Segment the regions in the image 00623 // using Superpixel algorithm (Felzenszwalb & Huttenlocher 2003) 00624 00625 // resize to original for display only 00626 00627 00628 //inplacePaste(itsDispImg,getSaliency(itsCurrImg), Point2D<int>(0, h)); 00629 } 00630 00631 00632 // ###################################################################### 00633 void TV_Lane:: updateMessage 00634 (const RobotSimEvents::EventMessagePtr& eMsg, const Ice::Current&) 00635 { 00636 // camera message 00637 if(eMsg->ice_isA("::BeobotEvents::CameraMessage")) 00638 { 00639 // store the image 00640 BeobotEvents::CameraMessagePtr cameraMsg = 00641 BeobotEvents::CameraMessagePtr::dynamicCast(eMsg); 00642 00643 int currRequestID = cameraMsg->RequestID; 00644 Image<PixRGB<byte> > img = Ice2Image<PixRGB<byte> >(cameraMsg->image); 00645 00646 LDEBUG("Got a CameraMessage with Request ID = %d", currRequestID); 00647 00648 its_Curr_Img_mutex.lock(); 00649 itsCurrImg = img; 00650 itsCurrImgID = cameraMsg->RequestID; 00651 its_Curr_Img_mutex.unlock(); 00652 } 00653 00654 // motor message 00655 else if(eMsg->ice_isA("::BeobotEvents::MotorMessage")) 00656 { 00657 BeobotEvents::MotorMessagePtr mtrMsg = 00658 BeobotEvents::MotorMessagePtr::dynamicCast(eMsg); 00659 LDEBUG("Got a MotorMessage with Request ID = %d: RC Trans %f, Rot %f", 00660 mtrMsg->RequestID, itsRcTransSpeed, itsRcRotSpeed); 00661 its_Curr_Mtr_mutex.lock(); 00662 itsRemoteMode = mtrMsg->rcMode; 00663 itsRcTransSpeed = mtrMsg->rcTransVel; 00664 itsRcRotSpeed = mtrMsg->rcRotVel; 00665 its_Curr_Mtr_mutex.unlock(); 00666 } 00667 // LINFO("updateMessage"); 00668 00669 00670 } 00671 00672 // ###################################################################### 00673 /* So things look consistent in everyone's emacs... */ 00674 /* Local Variables: */ 00675 /* indent-tabs-mode: nil */ 00676 /* End: */