Use VintaSoft Imaging .NET SDK with Emgu CV (Open CV) library

Blog category: Imaging.NET

February 25, 2022

VintaSoft Imaging .NET SDK provides the functionality to work with images. The SDK allows to create, load, process, print and save images.

The SDK offers more than 110 commands for image processing, which allow to:

The SDK uses Vintasoft.Imaging.VintasoftImage class to work with an image. Vintasoft.Imaging.VintasoftImage.OpenPixelManipulator method allows to lock the image data and get access to image data using Vintasoft.Imaging.PixelManipulator class. Vintasoft.Imaging.PixelManipulator.Scan0 property allows to get the pointer to the beginning of image data in unmanaged memory. The pointer to the beginning of image data in unmanaged memory can be used by any other .NET library, which can work with images stored in unmanaged memory. For example, an image created within the SDK can be processed using Emgu CV library - a cross platform .NET wrapper for the Open CV image-processing library.

Here is C# code, which demonstrates how to create an image using VintaSoft Imaging .NET SDK (create an Vintasoft.Imaging.VintasoftImage object), process the image with Open CV library and save the processed image to TIFF file using VintaSoft Imaging .NET SDK:
/// <summary>
/// Loads image from PNG file using VintaSoft Imaging .NET SDK,
/// inverts loaded image using Emgu CV (Open CV) library,
/// saves inverted image to a new PNG file using VintaSoft Imaging .NET SDK.
/// </summary>
static public void InvertVintasoftImageUsingEmguCV()
{
    // create VintasoftImage from PNG file
    using (Vintasoft.Imaging.VintasoftImage vintasoftImage = new Vintasoft.Imaging.VintasoftImage("source.png"))
    {
        // open pixel manipulator
        Vintasoft.Imaging.PixelManipulator pixelManipulator = vintasoftImage.OpenPixelManipulator();

        // create rectangle that defines region of interest on image
        System.Drawing.Rectangle imageROI = new System.Drawing.Rectangle(0, 0, vintasoftImage.Width, vintasoftImage.Height);
        // lock pixels of image
        pixelManipulator.LockPixels(imageROI, Vintasoft.Imaging.BitmapLockMode.ReadWrite);

        // create Emgu CV image from pointer to unmanaged memory
        using (Emgu.CV.Image emguCvImage =
            new Emgu.CV.Image(
                vintasoftImage.Width,
                vintasoftImage.Height,
                pixelManipulator.Stride,
                pixelManipulator.Scan0))
        {
            // invert image using Open CV and get new result image
            using (Emgu.CV.Image emguCvImage2 = emguCvImage.Not())
            {
                // copy inverted image back to the source image
                // (copy image data from unmanaged memory of emguCvImage2 object to unmanaged data of vintasoftImage/emguCvImage object)
                emguCvImage2.CopyTo(emguCvImage);
            }
        }

        // close pixel manipulator and specify that image data is changed
        vintasoftImage.ClosePixelManipulator(true);

        // save inverted image to new PNG file
        vintasoftImage.Save("result.png");
    }
}