【问题标题】:How can i grab pRgb32 image buffer from BitmapSource or PlanarImage (from Kinect)?如何从 BitmapSource 或 PlanarImage(来自 Kinect)获取 pRgb32 图像缓冲区?
【发布时间】:2012-01-25 03:00:43
【问题描述】:

我正在尝试将 PlanarImage 位转换为 WPF 应用程序上的 pRgb32buffer,以在 VcamSDK 提供的虚拟网络摄像头上显示它。我不知道 pRgb32buffer 是什么,但 e2eSoft 需要它作为 VcamSDK 中的覆盖参数。 addOverlay 方法的文档如下:

HRESULT AddOverlay([in] VARIANT pRgb32Buffer, [in] ULONG width, [in] ULONG height
    , [in] LONG px, [in] LONG py, [in] ULONG whichOne);
Add an image overlay to current VCam video.
pRgb32Buffer: overlay image buffer, in RGB32 format (with alpha channel), size is
    [width x height], if it's NULL, this overlay (whichOne) will be removed; 
px, py: overlay position, [0, 0] is left-top point;
whichOne: VCam support 5 image overlay (0~4).

PlanarImage 的代码如下,PixelFormat 是 Bgr32,所以还需要一点转换;

void _nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
    PlanarImage Image = e.ImageFrame.Image;
    video.Source = BitmapSource.Create(
        Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, 
            Image.Bits, Image.Width * Image.BytesPerPixel);

我在 Google 上搜索了 pRgb32,但只找到了有限的信息,并且没有关于 vCam SDK 的示例文档。

我并不是图像处理方面的专家,因此非常感谢任何帮助!谢谢!


编辑:

我想我可以使用 SDK 中也存在的 PlayVideoFile(string fileName); 方法,但它需要显示图像的 Uri。而且由于对我的应用程序的某些限制,我无法将其保存到 HDD(我可能会多次更改图像并从图像制作流式视频,如果我尝试保存它,运行时会给我一个错误,它当前在使用),我不认为有黑客或其他方式将布局上的图像作为参数中的 Uri 发送?


更新:

我已经成功完成了以下位转换,因为我知道 Kinect 没有使用 Alpha 通道,因此它发送的所有 Alpha 位都是 0。首先我解决了这个问题(由于 0 alpha,图像不可见),然后我'已经完成了从 BGRA(Kinect)到 ABGR(所需像素格式)的以下转换。该文件有点妄想,说它是带有 alpha 通道的 RGB 格式,花了一点时间才明白真正的格式是 ABGR。

这是转换:

   for (int i = 0; i < myBits.Length; i+=4)
   {
       for (int j = 0; j < 4; j++)
       {
            tempBit = myBits[i + j];
            myBits[i + j] = myBits[i + 3];
            myBits[i + 3] = tempBit;
        }
        myBits[i] = 255;
    }

如果有人能以更有效的方式帮助我做到这一点,我很乐意接受他们的回答。否则我不知道如何结束问题?

【问题讨论】:

    标签: c# wpf image-processing bufferedimage kinect


    【解决方案1】:

    我想你可以简单地删除内部 for,然后这样做:

    
    for (int i = 0; i < myBits.Length; i+=4)
    {
        myBits[i+3] = myBits[i+2];
        myBits[i+2] = myBits[i+1];
        myBits[i+1] = myBits[i];
        myBits[i] = 255;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-07
      • 2015-09-08
      • 2020-03-30
      • 2013-06-11
      • 1970-01-01
      • 2018-06-07
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多