Search code examples
c#emgucvopencv3.0gige-sdk

Create a Mat from a PvBuffer in C# using eBUS SDK and EmguCV


I'm using EmguCV 3.4.1 and the eBUS SDK. I have video coming in over GigE and I would like to convert the PvBuffer to a MAT so I can use OpenCV to create a display a histogram.


Solution

  • I followed a similar style to how you create a Mat in C++. Unfortunately this solution requires marking the project as unsafe.

        unsafe private Mat convertPvBufferToMat(PvBuffer aBuffer)
        {
            PvImage lImage = aBuffer.Image;
            lImage.Alloc(lImage.Width, lImage.Height, PvPixelType.Mono16);
            int[] sizes = new int[2] { (int)lImage.Height, (int)lImage.Width };
            Mat aMat = new Mat(sizes, DepthType.Cv16U, (IntPtr)lImage.DataPointer);
    
            return aMat;
        }
    

    I'm taking images from an infared camera outputing 16 bit grayscale images.