Use VintaSoft Imaging .NET SDK con la biblioteca Emgu CV (Open CV)

Categoría del blog: Imaging.NET

25.02.2022

VintaSoft Imaging .NET SDK proporciona la funcionalidad para trabajar con imágenes. El SDK permite crear, cargar, procesar, imprimir y guardar imágenes.

El SDK ofrece más de 110 comandos para el procesamiento de imágenes, que permiten:

El SDK utiliza la clase Vintasoft.Imaging.VintasoftImage para trabajar con un Imagen. El método Vintasoft.Imaging.VintasoftImage.OpenPixelManipulator permite bloquear los datos de la imagen y acceder a ellos mediante la clase Vintasoft.Imaging.PixelManipulator. La propiedad Vintasoft.Imaging.PixelManipulator.Scan0 permite obtener el puntero al inicio de los datos de la imagen en la memoria no administrada. El puntero al inicio de los datos de imagen en memoria no administrada puede ser utilizado por cualquier otra biblioteca .NET que funcione con imágenes almacenadas en memoria no administrada. Por ejemplo, una imagen creada dentro del SDK puede procesarse utilizando la biblioteca Emgu CV, un contenedor .NET multiplataforma para la biblioteca de procesamiento de imágenes Open CV.

Aquí se muestra el código C#, que demuestra cómo crear una imagen usando VintaSoft Imaging .NET SDK (crear un objeto Vintasoft.Imaging.VintasoftImage), procesar la imagen con la biblioteca Open CV y ​​guardar la imagen procesada en un archivo TIFF usando 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");
    }
}