title: Kinect for Windows v2 depth to color image misalignment
body: <p>currently I am developing a tool for the Kinect for Windows v2 (similar to the one in XBOX ONE). I tried to follow some examples, and have a working example that shows the camera image, the depth image, and an image that maps the depth to the rgb using opencv. But I see that it duplicates my hand when doing the mapping, and I think it is due to something wrong in the coordinate mapper part.</p>
  
  <p>here is an example of it:
  <img src="https://i.stack.imgur.com/MJCw6.jpg" alt="error"></p>
  
  <p>And here is the code snippet that creates the image (rgbd image in the example) </p>
  
  <pre><code>void KinectViewer::create_rgbd(cv::Mat&amp; depth_im, cv::Mat&amp; rgb_im, cv::Mat&amp; rgbd_im){
      HRESULT hr = m_pCoordinateMapper-&gt;MapDepthFrameToColorSpace(cDepthWidth * cDepthHeight, (UINT16*)depth_im.data, cDepthWidth * cDepthHeight, m_pColorCoordinates);
      rgbd_im = cv::Mat::zeros(depth_im.rows, depth_im.cols, CV_8UC3);
      double minVal, maxVal;
      cv::minMaxLoc(depth_im, &amp;minVal, &amp;maxVal);
      for (int i=0; i &lt; cDepthHeight; i++){
          for (int j=0; j &lt; cDepthWidth; j++){
              if (depth_im.at&lt;UINT16&gt;(i, j) &gt; 0 &amp;&amp; depth_im.at&lt;UINT16&gt;(i, j) &lt; maxVal * (max_z / 100) &amp;&amp; depth_im.at&lt;UINT16&gt;(i, j) &gt; maxVal * min_z /100){
                  double a = i * cDepthWidth + j;
                  ColorSpacePoint colorPoint = m_pColorCoordinates[i*cDepthWidth+j];
                  int colorX = (int)(floor(colorPoint.X + 0.5));
                  int colorY = (int)(floor(colorPoint.Y + 0.5));
                  if ((colorX &gt;= 0) &amp;&amp; (colorX &lt; cColorWidth) &amp;&amp; (colorY &gt;= 0) &amp;&amp; (colorY &lt; cColorHeight))
                  {
                      rgbd_im.at&lt;cv::Vec3b&gt;(i, j) = rgb_im.at&lt;cv::Vec3b&gt;(colorY, colorX);
                  }
              }
  
          }
      }
  }
  </code></pre>
  
  <p>Does anyone have a clue of how to solve this? How to prevent this duplication?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If I do a simple depth image thresholding I obtain the following image:
  <img src="https://i.stack.imgur.com/bcHT0.jpg" alt="thresholding"></p>
  
  <p>This is what more or less I expected to happen, and not having a duplicate hand in the background. Is there a way to prevent this duplicate hand in the background?</p>