将BackwardQuadrilateralTransformation应用于定义的GRAFT点

时间:2013-10-03 17:13:17

标签: c# wpf canvas kinect glyph

我有一小段C#代码,它使用Kinect在画布上检测最多4个字形并在它们之间绘制和绘制多边形,如下所示:

enter image description here

我尝试跟随this以实现2D增强现实并在创建的多边形内投影图像。我在源图像中读过并尝试将BackwardQuadrilateralTransformation应用于它但似乎无法显示转换后的图像。我可能使用了错误的方法,但我试图转换图像并将其绘制到画布上,没有运气。我不确定我是否只是大量误解了这种方法,也许这是不可能的,任何帮助都会非常感激。如果需要,我可以提供更多示例代码。

    private void GlyphBackQuad(List<IntPoint> quadpoints)
    {
        Bitmap srcImage = new Bitmap( // my sample image filepath );
        UnmanagedImage sourceImage = UnmanagedImage.FromManagedImage(srcImage);
        BackwardQuadrilateralTransformation filter = new BackwardQuadrilateralTransformation(sourceImage, quadpoints);
        filter.Apply(sourceImage);

        Bitmap bmp = sourceImage.ToManagedImage();
        ImageBrush ib = new ImageBrush();
        ib.ImageSource = ConvertDrawingImage2MediaImageSource(bmp);
        PolyCanvas.Background = ib;
    }

在进一步使用代码之后,我认为我已经开发了部分解决方案,它仍然需要一些工作,但希望这对人们阅读/调试更有帮助。

    private void GlyphBackQuad(List<IntPoint> quadpoints, Bitmap bmp)
    {
        // Read in bitmap source image and clone it to the same format as destination
        Bitmap srcImage = AForge.Imaging.Image.Clone(new Bitmap( // my sample filepath), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        System.Drawing.Imaging.BitmapData bitmapData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        // Convert to unmanaged image
        UnmanagedImage unmanagedImage = new UnmanagedImage( bitmapData );
        // Filter
        BackwardQuadrilateralTransformation filter = new BackwardQuadrilateralTransformation(srcImage, quadpoints);
        filter.ApplyInPlace(unmanagedImage);
        // Convert back to managed image and save
        Bitmap managedImage = unmanagedImage.ToManagedImage();
        managedImage.Save( // my save filepath, System.Drawing.Imaging.ImageFormat.Png);
    }

0 个答案:

没有答案