فهرست منبع

workaround for empty ichannels when using CachedExample in 2D scenarios -> needs proper solution

Sven Sickert 8 سال پیش
والد
کامیت
34dd34de61
2فایلهای تغییر یافته به همراه34 افزوده شده و 38 حذف شده
  1. 33 37
      cbaselib/CachedExample.cpp
  2. 1 1
      cbaselib/CachedExample.h

+ 33 - 37
cbaselib/CachedExample.cpp

@@ -38,9 +38,10 @@ void CachedExample::init ()
     }
 }
 
-CachedExample::CachedExample ( const std::string & _imgfn,
-                               int _newWidth,
-                               int _newHeight )
+CachedExample::CachedExample (
+        const std::string & _imgfn,
+        int _newWidth,
+        int _newHeight )
 {
     imgfn.push_back(_imgfn);
     newWidth = _newWidth;
@@ -105,7 +106,9 @@ CachedExample::CachedExample (
     hasColorInformation = false;
 }
 
-CachedExample::CachedExample ( const NICE::ColorImage & img, bool disableGrayConversion )
+CachedExample::CachedExample (
+        const NICE::ColorImage & img,
+        bool disableGrayConversion )
 {
     imgfn.push_back("");
     oxsize = img.width();
@@ -239,24 +242,22 @@ void CachedExample::readImageData ()
         else
             imggray = orig;
 
+	// FIXME: gray values are saved twice (ichannels and ichannels3)
+        // for compatibility with all 2D programs that refer to ichannels
+        // which is of type MultiChannelImageT instead of MultiChannelImage3DT
         if ( z == 0 )
         {
             oxsize = imggray.width();
             oysize = imggray.height();
 
-            if ( ozsize > 1 )
-                ichannels3[I_GRAYVALUES].reInit( oxsize, oysize, ozsize, 1);
-            else
-            {
-                ichannels[I_GRAYVALUES].freeData();
-                ichannels[I_GRAYVALUES].addChannel(imggray);
-            }
+            ichannels3[I_GRAYVALUES].reInit( oxsize, oysize, ozsize, 1);
+            ichannels[I_GRAYVALUES].freeData();
+            ichannels[I_GRAYVALUES].addChannel(imggray);
         }
 
-        if ( ozsize > 1 )
-            for ( int y = 0; y < oysize; y++ )
-                for ( int x = 0; x < oxsize; x++ )
-                    ichannels3[I_GRAYVALUES](x,y,z,0) = imggray.getPixel(x,y);
+        for ( int y = 0; y < oysize; y++ )
+            for ( int x = 0; x < oxsize; x++ )
+                ichannels3[I_GRAYVALUES](x,y,z,0) = imggray.getPixel(x,y);
     }
 }
 
@@ -285,27 +286,20 @@ void CachedExample::readImageDataRGB ()
 
             hasColorInformation = true;
 
-            if ( ozsize > 1 )
-                ichannels3[I_COLOR].reInit ( oxsize, oysize, ozsize, 3);
-            else
-                ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
+            // FIXME: see readImageData issue
+            ichannels3[I_COLOR].reInit ( oxsize, oysize, ozsize, 3);
+            ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
         }
 
         for ( int y = 0; y < oysize; y++ )
             for ( int x = 0; x < oxsize; x++ )
             {
-                if ( ozsize > 1 )
-                {
-                    ichannels3[I_COLOR](x,y,z,0) = img.getPixel(x,y,0);
-                    ichannels3[I_COLOR](x,y,z,1) = img.getPixel(x,y,1);
-                    ichannels3[I_COLOR](x,y,z,2) = img.getPixel(x,y,2);
-                }
-                else
-                {
-                    ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
-                    ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
-                    ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
-                }
+                ichannels3[I_COLOR](x,y,z,0) = img.getPixel(x,y,0);
+                ichannels3[I_COLOR](x,y,z,1) = img.getPixel(x,y,1);
+                ichannels3[I_COLOR](x,y,z,2) = img.getPixel(x,y,2);
+                ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
+                ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
+                ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
             }
     }
 }
@@ -371,9 +365,10 @@ void CachedExample::calcIntegralImage ()
     }
 }
 
-void CachedExample::buildIntegralSV ( int svchannel,
-                                      NICE::SparseVector *_map,
-                                      int xsize_s, int ysize_s )
+void CachedExample::buildIntegralSV (
+        int svchannel,
+        NICE::SparseVector *_map,
+        int xsize_s, int ysize_s )
 {
     NICE::SparseVector *map = _map;
     svmap[svchannel] = _map;
@@ -401,9 +396,10 @@ void CachedExample::buildIntegralSV ( int svchannel,
     }
 }
 
-void CachedExample::setSVMap ( int svchannel,
-                               NICE::SparseVector *_map,
-                               int xsize_s, int ysize_s )
+void CachedExample::setSVMap (
+        int svchannel,
+        NICE::SparseVector *_map,
+        int xsize_s, int ysize_s )
 {
     svmap[svchannel] = _map;
     svmap_xsize[svchannel] = xsize_s;

+ 1 - 1
cbaselib/CachedExample.h

@@ -321,7 +321,7 @@ inline NICE::MultiChannelImage3DT<double> & CachedExample::getDChannel3 ( int ch
         if ( j == dtemps.end() )
         {
             //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel %s (double %d)!\n",
-            // imgfn.c_str(), channel);
+            //imgfn[0].c_str(), channel);
         }
         else
         {