Difference between revisions of "Bug on image sink"

From Wiki for iCub and Friends
Jump to: navigation, search
 
Line 5: Line 5:
 
   ImageOf<PixelRgb> *imgIn = portIn.read(true);
 
   ImageOf<PixelRgb> *imgIn = portIn.read(true);
 
   ImageOf<PixelRgb>& imgOut = portOut.prepare();
 
   ImageOf<PixelRgb>& imgOut = portOut.prepare();
 
 
   imgOut.copy(*imgIn);
 
   imgOut.copy(*imgIn);
 
   addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
 
   addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
 
 
   ct++;
 
   ct++;
 
   if (ct==imgOut.width())
 
   if (ct==imgOut.width())
 
       ct=0;
 
       ct=0;
   
 
 
   portOut.write();
 
   portOut.write();
 
   ....
 
   ....
Line 22: Line 19:
 
     {
 
     {
 
         ImageOf<PixelRgb>& imgOut = portOut.prepare();
 
         ImageOf<PixelRgb>& imgOut = portOut.prepare();
 
 
         imgOut.copy(*imgIn);
 
         imgOut.copy(*imgIn);
 
 
         addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
 
         addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
   
 
 
         ct++;
 
         ct++;
 
         if (ct==imgOut.width())
 
         if (ct==imgOut.width())
 
             ct=0;
 
             ct=0;
   
 
 
         portOut.write();
 
         portOut.write();
 
     }
 
     }

Revision as of 12:53, 20 July 2006

There is a possible bug in the image_sink program. In some cases the read of a port can return a null pointer, so the code must check it.

Old code:

 ImageOf<PixelRgb> *imgIn = portIn.read(true);
 ImageOf<PixelRgb>& imgOut = portOut.prepare();
 imgOut.copy(*imgIn);
 addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
 ct++;
 if (ct==imgOut.width())
     ct=0;
 portOut.write();
 ....

New code:

 ImageOf<PixelRgb> *imgIn = portIn.read(true);
 if (imgIn!=0)
   {
       ImageOf<PixelRgb>& imgOut = portOut.prepare();
       imgOut.copy(*imgIn);
       addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
       ct++;
       if (ct==imgOut.width())
           ct=0;
       portOut.write();
   }
 ...

The iCub repository has been update accordingly, so you can also update your local copy of the software.