proc_util.cpp
Go to the documentation of this file.
00001 
00024 #include "ccny_rgbd/proc_util.h"
00025 
00026 namespace ccny_rgbd {
00027 
00028 void unwarpDepthImage(
00029   cv::Mat& depth_img,
00030   const cv::Mat& coeff0,
00031   const cv::Mat& coeff1,
00032   const cv::Mat& coeff2,
00033   int fit_mode)
00034 {
00035   /*
00036   // NOTE: This is slightly faster (5ms vs 4ms)
00037   // BUT images need to be passed as CV_64FC1 or CV_32FC1
00038   // currently the conversion to float messes up 0 <-> nan values
00039   // Alternatively, coeff0 needs to be 0
00040   
00041   cv::Mat temp;
00042   depth_img.convertTo(temp, CV_64FC1);
00043   temp = coeff0 + temp.mul(coeff1 + temp.mul(coeff2));   
00044   temp.convertTo(depth_img, CV_16UC1);
00045   */
00046 
00047   if (fit_mode == DEPTH_FIT_QUADRATIC)
00048   {
00049     for (int u = 0; u < depth_img.cols; ++u)
00050     for (int v = 0; v < depth_img.rows; ++v)    
00051     {
00052       uint16_t d = depth_img.at<uint16_t>(v, u);    
00053       if (d != 0)
00054       {
00055         double c0 = coeff0.at<double>(v, u);
00056         double c1 = coeff1.at<double>(v, u);
00057         double c2 = coeff2.at<double>(v, u);
00058       
00059         uint16_t res = (int)(c0 + d*(c1 + d*c2));
00060         depth_img.at<uint16_t>(v, u) = res;
00061       }
00062     }
00063   }
00064   else if(fit_mode == DEPTH_FIT_LINEAR)
00065   {
00066     for (int u = 0; u < depth_img.cols; ++u)
00067     for (int v = 0; v < depth_img.rows; ++v)    
00068     {
00069       uint16_t d = depth_img.at<uint16_t>(v, u);    
00070       if (d != 0)
00071       {
00072         double c0 = coeff0.at<double>(v, u);
00073         double c1 = coeff1.at<double>(v, u);
00074       
00075         uint16_t res = (int)(c0 + d*c1);
00076         depth_img.at<uint16_t>(v, u) = res;
00077       }
00078     }
00079   }
00080   else if (fit_mode == DEPTH_FIT_LINEAR_ZERO)
00081   {
00082     cv::Mat temp;
00083     depth_img.convertTo(temp, CV_64FC1);
00084     temp = temp.mul(coeff1);   
00085     temp.convertTo(depth_img, CV_16UC1);
00086   }
00087   else if (fit_mode == DEPTH_FIT_QUADRATIC_ZERO)
00088   {
00089     cv::Mat temp;
00090     depth_img.convertTo(temp, CV_64FC1);
00091     temp = temp.mul(coeff1 + temp.mul(coeff2));   
00092     temp.convertTo(depth_img, CV_16UC1);
00093   }
00094 }
00095 
00096 } // namespace ccny_rgbd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends


ccny_rgbd
Author(s): Ivan Dryanovski
autogenerated on Fri Apr 12 2013 20:38:48