Esempio n. 1
0
        /// <summary>
        /// 3次元の手の座標をカメラの2次元座標に変換する
        /// </summary>
        /// <param name="image"></param>
        /// <param name="fingers"></param>
        /// <returns></returns>
        private static Leap.Vector[] MapCameraToColor(Leap.Image image, FingerList fingers)
        {
            var colorPoints = new List <Leap.Vector>();

            float cameraOffset = 20; //x-axis offset in millimeters

            foreach (Finger finger in fingers)
            {
                // 3次元座標を2次元座標に変換する
                var   tip    = finger.TipPosition;
                float hSlope = -(tip.x + cameraOffset * (2 * image.Id - 1)) / tip.y;
                float vSlope = tip.z / tip.y;

                colorPoints.Add(image.Warp(new Leap.Vector(hSlope, vSlope, 0)));
            }

            return(colorPoints.ToArray());
        }
Esempio n. 2
0
        private static BitmapSource ToCalibratedBitmap(int targetWidth, int targetHeight, Leap.Image image)
        {
            var buffer = new byte[targetWidth * targetHeight];

            //Iterate over target image pixels, converting xy to ray slope
            for (int y = 0; y < targetHeight; y++)
            {
                for (int x = 0; x < targetWidth; x++)
                {
                    //Normalize from pixel xy to range [0..1]
                    var input = new Leap.Vector(x / (float)targetWidth, y / (float)targetHeight, 0);

                    //Convert from normalized [0..1] to slope [-4..4]
                    input.x = (input.x - image.RayOffsetX) / image.RayScaleX;
                    input.y = (input.y - image.RayOffsetY) / image.RayScaleY;

                    //Use slope to get coordinates of point in image.Data containing the brightness for this target pixel
                    var pixel = image.Warp(input);

                    int bufferIndex = (y * targetWidth) + x;

                    if (pixel.x >= 0 && pixel.x < image.Width && pixel.y >= 0 && pixel.y < image.Height)
                    {
                        int dataIndex = (int)(Math.Floor(pixel.y) * image.Width + Math.Floor(pixel.x));     //xy to buffer index
                        buffer[bufferIndex] = image.Data[dataIndex];
                    }
                    else
                    {
                        buffer[bufferIndex] = 255;
                    }
                }
            }

            return(BitmapSource.Create(targetWidth, targetHeight, 96, 96,
                                       PixelFormats.Gray8, null, buffer, targetWidth));
        }