rgbdemo / nestk

C++ Library for Kinect
http://nicolas.burrus.name/index.php/Research/KinectUseNestk
Other
78 stars 45 forks source link

Rewrite loops so that debug mode gets faster #6

Open nburrus opened 12 years ago

nburrus commented 12 years ago

According to Cristobal Belles:

//=============47 ms en un i7

      for_all_rc(m_image->depthMaskRef())
   {
       float d = m_image->depth()(r,c);
       if (d < 1e-5 || ntk::math::isnan(d))
           m_image->depthMaskRef()(r,c) = 0;
       else
           m_image->depthMaskRef()(r,c) = 255;
   }

//=============

Equivalent code, faster in debug mode:

//=============3 ms

           cv::Mat1b& depth_mask  = m_image->depthMaskRef();
           const cv::Mat1f& depth = m_image->depth();
           for (int r = 0; r < depth_mask.rows; ++r)
           {
              unsigned char* f_depth_mask  = depth_mask.ptr<unsigned char>(r);
              const float* f_depth      = depth.ptr<float>(r);
              for (int c = 0; c < depth_mask.cols; ++c)
              {
                 float d = f_depth[c];
                 if (d < 1e-5 || ntk::math::isnan(d))
                     f_depth_mask[c] = 0;
                 else
                    f_depth_mask[c] = 255;
              }
           }