utils.cpp 2.29 KB
Newer Older
1 2 3 4 5 6 7 8
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory

// This code is also subject to the license terms in the LICENSE_WillowGarage.md file found in this module's directory

9
#include "precomp.hpp"
10
#include "utils.hpp"
Vincent Rabaud's avatar
Vincent Rabaud committed
11 12 13

namespace cv
{
14 15
namespace rgbd
{    
Vincent Rabaud's avatar
Vincent Rabaud committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  /** If the input image is of type CV_16UC1 (like the Kinect one), the image is converted to floats, divided
   * by 1000 to get a depth in meters, and the values 0 are converted to std::numeric_limits<float>::quiet_NaN()
   * Otherwise, the image is simply converted to floats
   * @param in_in the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters
   *              (as done with the Microsoft Kinect), it is assumed in meters)
   * @param depth the desired output depth (floats or double)
   * @param out_out The rescaled float depth image
   */
  void
  rescaleDepth(InputArray in_in, int depth, OutputArray out_out)
  {
    cv::Mat in = in_in.getMat();
    CV_Assert(in.type() == CV_64FC1 || in.type() == CV_32FC1 || in.type() == CV_16UC1 || in.type() == CV_16SC1);
    CV_Assert(depth == CV_64FC1 || depth == CV_32FC1);

    int in_depth = in.depth();

    out_out.create(in.size(), depth);
    cv::Mat out = out_out.getMat();
    if (in_depth == CV_16U)
    {
      in.convertTo(out, depth, 1 / 1000.0); //convert to float so that it is in meters
Ilya Lavrenov's avatar
Ilya Lavrenov committed
38
      cv::Mat valid_mask = in == std::numeric_limits<ushort>::min(); // Should we do std::numeric_limits<ushort>::max() too ?
Vincent Rabaud's avatar
Vincent Rabaud committed
39 40 41 42 43
      out.setTo(std::numeric_limits<float>::quiet_NaN(), valid_mask); //set a$
    }
    if (in_depth == CV_16S)
    {
      in.convertTo(out, depth, 1 / 1000.0); //convert to float so tha$
Ilya Lavrenov's avatar
Ilya Lavrenov committed
44
      cv::Mat valid_mask = (in == std::numeric_limits<short>::min()) | (in == std::numeric_limits<short>::max()); // Should we do std::numeric_limits<ushort>::max() too ?
Vincent Rabaud's avatar
Vincent Rabaud committed
45 46 47 48 49
      out.setTo(std::numeric_limits<float>::quiet_NaN(), valid_mask); //set a$
    }
    if ((in_depth == CV_32F) || (in_depth == CV_64F))
      in.convertTo(out, depth);
  }
50 51 52 53 54 55 56
} // namespace rgbd

namespace kinfu {

} // namespace kinfu
} // namespace cv