Utilizza VintaSoft Imaging .NET SDK con la libreria Emgu CV (Open CV)

Categoria blog: Imaging.NET

25.02.2022

VintaSoft Imaging .NET SDK fornisce la funzionalità per lavorare con le immagini. L'SDK consente di creare, caricare, elaborare, stampare e salvare le immagini.

L'SDK offre più di 110 comandi per l'elaborazione delle immagini, che consentono di:

L'SDK utilizza Vintasoft.Imaging.VintasoftImage per lavorare con un'immagine. Il metodo Vintasoft.Imaging.VintasoftImage.OpenPixelManipulator consente di bloccare i dati dell'immagine e di accedervi utilizzando la classe Vintasoft.Imaging.PixelManipulator. La proprietà Vintasoft.Imaging.PixelManipulator.Scan0 consente di ottenere il puntatore all'inizio dei dati dell'immagine in modalità non gestita. Memoria. Il puntatore all'inizio dei dati dell'immagine nella memoria non gestita può essere utilizzato da qualsiasi altra libreria .NET, in grado di gestire immagini archiviate in tale memoria. Ad esempio, un'immagine creata all'interno dell'SDK può essere elaborata utilizzando la libreria Emgu CV, un wrapper .NET multipiattaforma per la libreria di elaborazione immagini Open CV.

Ecco il codice C# che mostra come creare un'immagine utilizzando VintaSoft Imaging .NET SDK (creare un oggetto Vintasoft.Imaging.VintasoftImage), elaborare l'immagine con la libreria Open CV e salvare l'immagine elaborata in un file TIFF utilizzando 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");
    }
}