示例#1
0
    /// <summary>
    /// Construct eye-rays through the specified pixels
    /// </summary>
    /// <param name="icp">Intrinsic camera parameters</param>
    /// <param name="pixels">Pixels</param>
    /// <returns>Enumerable ray collection</returns>
    public static Ray[] EyeRays(Emgu.CV.IntrinsicCameraParameters icp, PointF[] pixels) {
      Ray[] rays = new Ray[pixels.Length];
      if (pixels.Length > 0) {
        // 1. Undistort pixels
        PointF[] undistorted_pixels = icp.Undistort(pixels, null, icp.IntrinsicMatrix);
        // 2. Create rays
        // Use inverse intrinsic calibration and depth = 1
        double cx = icp.IntrinsicMatrix.Data[0, 2];
        double cy = icp.IntrinsicMatrix.Data[1, 2];
        double fx = icp.IntrinsicMatrix.Data[0, 0];
        double fy = icp.IntrinsicMatrix.Data[1, 1];


        Vector direction = new Vector(3);
        for (int i = 0; i < undistorted_pixels.Length; ++i) {
          PointF pixel = undistorted_pixels[i];
          direction[0] = (pixel.X - cx) / fx;
          direction[1] = (pixel.Y - cy) / fy;
          direction[2] = 1;
          rays[i] = new Ray(direction.Normalize());
        }
      }
      return rays;
    }