【问题标题】:Image corrupted after zooming缩放后图像损坏
【发布时间】:2015-05-19 14:02:54
【问题描述】:

我正在使用 Microsoft Kinect SDK v2 从 Kinect V2 传感器读取颜色帧。我将帧数据复制到字节数组中,稍后将其转换为 EmguCV 图像。下面是代码中的sn-p-

// A pixel buffer to hold image data from the incoming color frame
private byte[] pixels = null;
private KinectSensor kinectSensor = null;
private ColorFrameReader colorFrameReader = null;
public KinectForm()
{
    this.kinectSensor = KinectSensor.GetDefault();
    this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
    this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
    // create the colorFrameDescription from the ColorFrameSource using Bgra format
    FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
    // Create a pixel buffer to hold the frame's image data as a byte array
    this.pixels = new byte[colorFrameDescription.Width * colorFrameDescription.Height * colorFrameDescription.BytesPerPixel];
    // open the sensor
    this.kinectSensor.Open();
    InitializeComponent();
}

private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
    using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
    {
        if (colorFrame != null)
        {
            FrameDescription colorFrameDescription = colorFrame.FrameDescription;
            if (colorFrame.RawColorImageFormat == ColorImageFormat.Bgra)
                colorFrame.CopyRawFrameDataToArray(pixels);
            else
                colorFrame.CopyConvertedFrameDataToArray(this.pixels, ColorImageFormat.Bgra);

            //Initialize Emgu CV image then assign byte array of pixels to it
            Image<Bgr, byte> img = new Image<Bgr, byte>(colorFrameDescription.Width, colorFrameDescription.Height);
            img.Bytes = pixels;

            imgBox.Image = img;//Show image in Emgu.CV.UI.ImageBox
        }
    }
}

转换后的图像在缩放超过 25% 后损坏。请看下面的截图-

50% 缩放 -

25% 缩放 -

12.5% 缩放 -

【问题讨论】:

    标签: image kinect emgucv


    【解决方案1】:

    应该是Bgra,你可以从“pixels”字节数组中确认。

    编辑: 由于 Kinect 的色框强度为 0,图像将不可见,所以我添加了此代码来解决问题,希望有更好(更快)的方法来解决。

    private void FixIntensity(byte[] p)
        {
            int i = 0;
            while (i < p.Length)
            {
                p[i+3] = 255;
                i += 4;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 2012-05-25
      • 2013-10-25
      • 2017-01-27
      • 1970-01-01
      • 2020-04-15
      • 1970-01-01
      相关资源
      最近更新 更多