none
Depth data convert to Image<Bgr, Byte> in a windows store project RRS feed

  • Question

  • Hi,

    i use EmguCv to process depth data from Kinect v2. Now i want to do it in a windows store 8.1 app. In older project i use these code to convert from writable bitmap:

                BitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(depthBitmap));
                MemoryStream ms = new MemoryStream();
                encoder.Save(ms);
                Bitmap b = new Bitmap(ms);
    
                Image<Bgr, Byte> openCVImg = new Image<Bgr, Byte>(b);

    I the project i miss the bitmap class, i search the whole day for a solution...

    Thx for any hlp

    René

    Friday, February 13, 2015 3:14 PM

Answers

  • The answer with help from Canming Huang (Thx):

    private Image<Bgr, Byte> Array2IImage(byte[] pixelArray)
    {
        GCHandle dataHandle = GCHandle.Alloc(pixelArray, GCHandleType.Pinned);
        try
        {
            using (Image<Bgra, Byte> image = new Image<Bgra, byte>(this.pixelWidth, this.pixelHeight, this.pixelWidth * this.cbytesPerPixel, dataHandle.AddrOfPinnedObject()))
            {
               return image.Convert<Bgr, Byte>();
            }
        }
        finally
        {
            dataHandle.Free();
        }
    }

    • Marked as answer by dutzend Saturday, February 14, 2015 8:41 AM
    Saturday, February 14, 2015 8:40 AM