VintaSoft Imaging을 사용하세요. .NET SDK와 Emgu CV(Open CV) 라이브러리(

블로그 카테고리: 이미징.NET

2022/02/25

VintaSoft Imaging .NET SDK는 이미지 작업을 위한 기능을 제공합니다. SDK를 사용하면 이미지를 생성, 불러오기, 처리, 인쇄 및 저장할 수 있습니다.

SDK는 110개 이상의 이미지 처리 명령어를 제공하여 다음과 같은 작업을 수행할 수 있습니다.

SDK는 Vintasoft.Imaging.VintasoftImage 클래스를 사용하여 이미지를 처리합니다. Vintasoft.Imaging.VintasoftImage.OpenPixelManipulator 메서드를 사용하면 이미지 데이터를 잠그고 Vintasoft.Imaging.PixelManipulator 클래스를 사용하여 이미지 데이터에 접근할 수 있습니다. Vintasoft.Imaging.PixelManipulator.Scan0 속성을 사용하면 관리되지 않는 메모리에 저장된 이미지 데이터의 시작 부분을 가리키는 포인터를 얻을 수 있습니다. 이 포인터는 관리되지 않는 메모리에 저장된 이미지를 처리하는 다른 .NET 라이브러리에서 사용할 수 있습니다. 예를 들어, SDK에서 생성된 이미지는 OpenCV 이미지 처리 라이브러리의 크로스 플랫폼 .NET 래퍼인 Emgu CV 라이브러리를 사용하여 처리할 수 있습니다.

다음은 VintaSoft Imaging .NET SDK를 사용하여 이미지를 생성하는 방법(Vintasoft.Imaging.VintasoftImage 객체 생성), OpenCV 라이브러리를 사용하여 이미지를 처리하고 처리된 이미지를 VintaSoft Imaging .NET SDK를 사용하여 TIFF 파일로 저장하는 방법을 보여주는 C# 코드입니다.
/// <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");
    }
}