title: Kinect v2 mapping color coordinates to camera space
body: <p>I am trying to map coordinates from the color space to the camera space.
  The code I am using is the following:</p>
  
  <pre><code>HRESULT ModelRecognizer::MapColorToCameraCoordinates(const std::vector&lt;ColorSpacePoint&gt;&amp; colorsps, std::vector&lt;CameraSpacePoint&gt;&amp; camerasps)
  {
      //Access frame
      HRESULT hr = GetDepthFrame();
  
      if (SUCCEEDED(hr))
      {
          ICoordinateMapper* pMapper;
          hr = m_pKinectSensor-&gt;get_CoordinateMapper(&amp;pMapper);
          if (SUCCEEDED(hr))
          {
              CameraSpacePoint* cameraSpacePoints = new CameraSpacePoint[cColorWidth * cColorHeight];
              hr = pMapper-&gt;MapColorFrameToCameraSpace(nDepthWidth * nDepthHeight, depthImageBuffer, cColorWidth * cColorHeight, cameraSpacePoints);
              if (SUCCEEDED(hr))
              {
                  for (ColorSpacePoint colorsp : colorsps)
                  {
                      long colorIndex = (long)(colorsp.Y * cColorWidth + colorsp.X);
                      CameraSpacePoint csp = cameraSpacePoints[colorIndex];
                      camerasps.push_back(csp);
                  }
              }
              delete[] cameraSpacePoints;
          }
      }
      ReleaseDepthFrame();
      return hr;
  }
  </code></pre>
  
  <p>I do not get any errors, however, the result seems to be rotated by 180 degrees and has an offset. Does anyone have suggestions what I am doing wrong? Any help is appreciated.</p>
  
  <p>Just to give a bigger picture why I need this:</p>
  
  <p>I am tracking colored tape pasted on a table from the color image using open cv. Then I create walls at the locations of the tape in a 3D mesh. Furthermore, I am using KinectFusion to generate a mesh of the other objects on the table. However, when I open both meshes in Meshlab the misalignment can clearly be seen. As I assume KinectFusion's mesh is created correctly in the CameraSpace and I create the mesh of the walls exactly at the CameraSpacePoints returned by the above function, I am pretty sure that the error lies in the CoordinateMapping procedure.</p>
  
  <p>Images showing the misalignment can be found at <a href="http://imgur.com/UsrEdZb,ZseN2br#0" rel="nofollow">http://imgur.com/UsrEdZb,ZseN2br#0</a> , <a href="http://imgur.com/UsrEdZb,ZseN2br#1" rel="nofollow">http://imgur.com/UsrEdZb,ZseN2br#1</a></p>