Utilisez VintaSoft Imaging .NET SDK avec la bibliothèque Emgu CV (Open CV).

Catégorie du blog: Imagerie.NET

25.02.2022

VintaSoft Imaging .NET SDK fournit les fonctionnalités nécessaires pour travailler avec des images. Le SDK permet de créer, charger, traiter, imprimer et enregistrer des images.

Le SDK offre plus de 110 commandes pour le traitement d'images, qui permettent de:

Le SDK utilise la classe Vintasoft.Imaging.VintasoftImage pour manipuler une image. La méthode Vintasoft.Imaging.VintasoftImage.OpenPixelManipulator permet de verrouiller les données de l'image et d'y accéder via la classe Vintasoft.Imaging.PixelManipulator. La propriété Vintasoft.Imaging.PixelManipulator.Scan0 permet d'obtenir un pointeur vers le début des données d'image en mémoire non managée. Ce pointeur peut être utilisé par toute autre bibliothèque .NET capable de traiter des images stockées en mémoire non managée. Par exemple, une image créée avec le SDK peut être traitée avec la bibliothèque Emgu CV, un wrapper .NET multiplateforme pour la bibliothèque de traitement d'images OpenCV.

Voici un exemple de code C# qui montre comment créer une image à l'aide du VintaSoft Imaging .NET SDK (créer un objet Vintasoft.Imaging.VintasoftImage), traiter l'image avec la bibliothèque OpenCV et enregistrer l'image traitée dans un fichier TIFF à l'aide du 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");
    }
}