private byte[] UndistortImage(byte[] imgData, Leap.Image.CameraType type)
    {
        byte[] undistortedImg = new byte[TEX_WIDTH * TEX_HEIGHT];
        for (float row = ROW_OFFSET; row < TEX_HEIGHT - ROW_OFFSET; row++)
        {
            for (float col = COL_OFFSET; col < TEX_WIDTH - COL_OFFSET; col++)
            {
                //Normalize from pixel xy to range [0..1]
                Leap.Vector input = new Leap.Vector();
                input.x = col / TEX_WIDTH;
                input.y = row / TEX_HEIGHT;

                //Convert from normalized [0..1] to ray slopes
                input.x = (input.x - 0.5f) * V_FOV * FOV_MODIFIER;
                input.y = (input.y - 0.5f) * H_FOV * FOV_MODIFIER;


                Leap.Vector pixel  = _currentImage.RectilinearToPixel(type, input);
                int         dindex = (int)Mathf.Floor(row * TEX_WIDTH + col);
                int         pindex = (int)Mathf.Floor(pixel.y) * _currentImage.Width + (int)Mathf.Floor(pixel.x);

                if (pixel.x >= 0 && pixel.x < _currentImage.Width && pixel.y >= 0 && pixel.y < _currentImage.Height)
                {
                    undistortedImg[dindex] = imgData[pindex];
                }
                else
                {
                    undistortedImg[dindex] = 100;
                }
            }
        }
        return(undistortedImg);
    }
    private float[] ProcessImage(byte[] imgData, Leap.Image.CameraType type)
    {
        byte[] undistortedImg        = UndistortImage(imgData, type);
        byte[] croppedUndistortedImg = new byte[WIDTH_WITH_OFFSET * HEIGHT_WITH_OFFSET];
        LeapToolTracking.CropImage(
            undistortedImg,
            croppedUndistortedImg,
            TEX_WIDTH, TEX_HEIGHT,
            COL_OFFSET, //COL_OFFSET and ROW_OFFSET have to be swapped here
            ROW_OFFSET,
            WIDTH_WITH_OFFSET,
            HEIGHT_WITH_OFFSET);

        float[] markerLocations = new float[] { 1000000, 1000000, 1000000, 1000000 };
        LeapToolTracking.GetMarkerLocations(croppedUndistortedImg, markerLocations, WIDTH_WITH_OFFSET, HEIGHT_WITH_OFFSET, (int)type);

        return(markerLocations);
    }