Imatest IT/.NET 收購庫

介紹

Imatest IT/.NET 影像擷取庫是一個 .NET 動態連結程式庫 (DLL),它使開發人員能夠直接從支援的裝置擷取影像。擷取程式庫傳回的影像隨後可以傳遞給Imatest IT/.NET函式庫,以便由 Imatest 強大的影像品質分析例程進行分析。 Imatest IT/.NET 影像擷取庫支援與Imatest Master相同的裝置和介面:

參考 Imatest IT/.NET 收購庫

新增 Imatest.IT 和 Imatest.Acquisition DLL 的引用

要使用Imatest IT/.NET 採集庫,首先需要將Imatest.IT.dll加入到您的 .NET 專案中。在專案的解決方案資源管理器中,右鍵單擊“引用”資料夾,然後選擇“新增參考...”

.NET 收購庫 - 新增引用

這將開啟參考文獻管理器。點擊視窗左側的「瀏覽」 ,然後點擊底部的「瀏覽...」按鈕。

DotNet收購 - 參考管理員 - 瀏覽

導覽至C:\Program Files\Imatest\v2021.1\IT\libs\library\.NET ,選擇Imatest.IT.dll ,然後按一下「新增」 (您不需要將IT.dll新增至您的專案)。

DotNet 收購 - 參考管理員 - 瀏覽 Imatest.IT.dll

Imatest.IT.dll已新增為專案中的參考。

DotNet 收購 - 參考管理器 Imatest.IT dll 已新增

按一下「確定」關閉引用管理器。現在,您應該在解決方案資源管理器中看到兩個新的參考: Imatest.Acquisition和Imatest.IT 。

DotNet收購 - 新增參考資料


激活 Imatest IT/.NET

在使用Imatest IT/.NET之前,即使您使用的是試用版,也需要啟動您的安裝程式。要激活,請執行位於C:\Program Files\Imatest\v2021\IT\bin\licensemanager.exe 的Imatest IT 許可證管理器,並按照此處的說明進行操作。

Using the Imatest IT/.NET Acquisition Library

The AcquisitionLibrary class

All of the functionality of the Imatest IT/.NET Acquisition Library is contained within the AcquisitionLibrary class. To use the library, you must first create an instance of the AcquisitionLibrary class. Although not required, we recommend wrapping the instance inside of a using() block, especially if you are using a floating license. The AcquisitionLibrary class implements IDisposable, and at the end of the using() block, the Dispose() method is called. This will release the current active seat back to the licensing server, allowing others to use it while the AcquisitionLibrary is not in use. If you choose not to use the using() block, then the Dispose() method will be called at the whim of the .NET garbage collector.

using (Library lib = new Library())
{
                
    /// Use lib to acquire images...
    ...
                
} /// Here, Dispose() will be called

Constant and Dynamic Device Objects

The Imatest IT/.NET Acquisition Library acquires images using objects of type Device. There are two types of Device objects, "constant" and "dynamic".

Constant Devices

Constant devices already exist as static objects within the Device class, and represent specific imaging devices or interfaces:
Imatest.Acquisition.Device.Epiphan // Epiphan frame grabbers
Imatest.Acquisition.Device.OmnivisionOVTA // Omnivision OVTA devices
Imatest.Acquisition.Device.ToshibaImaTuning // Toshiba ImaTuning devices
Imatest.Acquisition.Device.STMConduit // STM Conduit devices
Imatest.Acquisition.Device.GraphinEasyLab // Graphin EasyLab devices
Imatest.Acquisition.Device.ONSemiDevWare // ON Semi DevWare devices
Imatest.Acquisition.Device.AndroidCameraInterface // Android Camera Interface

Each of the constant devices has its own matching specific AcquireImageFrom*() method and ImatestAcquireOptions class (see the Examples below).

Dynamic Devices and Library.ListDevices()

All other supported devices are discovered at runtime using the AcquisitionLibrary.ListDevices() method (these are "dynamic" devices). The ListDevices() method returns a List<Device> collection of all of devices currently connected to the computer. Any of these Device objects can then be passed into the AcquisitionLibrary.AcquireFromToolboxDevice() method (see the Examples below).

The below code snippet fetches all of the available dynamic devices and prints their names to the console, along with each of their default and supported image formats:

var otherDevices = lib.ListDevices();
                
foreach(Imatest.Acquisition.Device device in otherDevices)
{
    Console.Out.WriteLine(device.DeviceName);
    Console.Out.WriteLine(string.Format("Default Format: {0}", device.DefaultFormat));
    Console.Out.WriteLine("Supported Formats:");

    foreach(string format in device.SupportedFormats)
    {
        Console.Out.WriteLine(string.Format("    {0}", format));
    }
}

When acquiring from a dynamic device, you can supply any of the supported formats as the VideoFormat property of the ImatestAcquireToolboxDeviceOptions object, or use the Device.DefaultFormat property (see the Examples below).

配置設備

某些裝置可能需要使用Imatest 主裝置管理員進行額外設定(詳情請參閱此處)。如果您已設定裝置並將其設定儲存至 JSON 檔案(例如ImageAcqToolboxSettings.json ),則該檔案必須與您正在使用的 INI 檔案位於同一目錄下。

取得影像

映像透過Library類別中的AcquireFrom*()方法載入。常量設備有各自特定的載入方法(例如AcquireFromEpiphan() 、 AcquireFromOmnivisionOVTA()等),而動態設備則共用一個通用方法(例如 AcquireFromToolboxDevice() )。每個AcquireFrom*()方法都接受一個特定於其設備的ImatestAcquireOptions物件(例如ImatestAcquireEpiphanOptions 、 ImatestAcquireOmnivisionOVTAOptions 、 ImatestAcquireToolboxDeviceOptions等)。每個選項物件必須至少設定Filename和Extension屬性,以及其他特定於裝置的選項。以下提供了填入各種ImatestAcquireOptions物件的範例。

所有對AcquireFrom*()方法的呼叫都會傳回一個ImatestAcquireResult物件。 ImatestAcquireResult 類別包含一個布林值Success屬性,如果擷取過程中沒有出現錯誤,則該屬性為 true,否則為 false。 ImatestAcquireResult.Image 屬性是一個ImatestImage對象,可以直接傳遞給任何Imatest IT/.NET影像分析模組方法。有關使用Imatest IT/.NET分析方法的更多信息,請參閱此處。

Examples

Acquiring from a Dynamic Device

This example demonstrates loading an image from a dynamic device object and passing it to the Imatest IT/.NET Stepchart module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        var otherDevices = lib.ListDevices();

        Device device = otherDevices[0];

        ImatestAcquireToolboxDeviceOptions toolboxDeviceOptions = new ImatestAcquireToolboxDeviceOptions();

        toolboxDeviceOptions.Extension = "bmp";
        toolboxDeviceOptions.Filename = "test_image.bmp";
        toolboxDeviceOptions.VideoFormat = device.DefaultFormat;

        ImatestAcquireResult acqResult = lib.AcquireFromToolboxDevice(device, toolboxDeviceOptions);
        
        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Stepchart.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring using an Epiphan Device

This example demonstrates loading an image from an Epiphan device and passing it to the Imatest IT/.NET Colorcheck module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireEpiphanOptions epiphanOptions = new ImatestAcquireEpiphanOptions();

        epiphanOptions.EpiphanChannel = 0;
        epiphanOptions.Extension = "bmp";
        epiphanOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromEpiphan(epiphanOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Colorcheck.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from an Omnivision OVTA Device

This example demonstrates loading an image from an Omnivision OVTA device and passing it to the Imatest IT/.NET SFRplus module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireOmnivisionOVTAOptions omnivisionOptions = new ImatestAcquireOmnivisionOVTAOptions();

        omnivisionOptions.Extension = "bmp";
        omnivisionOptions.Filename = "test_image.bmp";
        omnivisionOptions.IniFilePath = Path.Combine(rootDir, "imatest-v2.ini");

        ImatestAcquireResult acqResult = lib.AcquireFromOmnivisionOVTA(omnivisionOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.SFRplus.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from a Toshiba ImaTuning Device

This example demonstrates loading an image from a Toshiba ImaTuning device and passing it to the Imatest IT/.NET Blemish module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireToshibaImaTuningOptions toshibaOptions = new ImatestAcquireToshibaImaTuningOptions();

        toshibaOptions.Extension = "bmp";
        toshibaOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromToshibaImaTuning(toshibaOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Blemish.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from an STM Conduit Device

This example demonstrates loading an image from an STM Conduit device and passing it to the Imatest IT/.NET Wedge module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireSTMConduitOptions stmConduitOptions = new ImatestAcquireSTMConduitOptions();

        stmConduitOptions.Extension = "bmp";
        stmConduitOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromSTMConduit(stmConduitOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Wedge.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from a Graphin EasyLab Device

This example demonstrates loading an image from a Graphin EasyLab device and passing it to the Imatest IT/.NET SFRreg module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireGraphinEasyLabOptions graphinEasyLabOptions = new ImatestAcquireGraphinEasyLabOptions();

        graphinEasyLabOptions.Extension = "bmp";
        graphinEasyLabOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromGraphinEasyLab(graphinEasyLabOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.SFRreg.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from an ON Semi DevWare Device

This example demonstrates loading an image from an ON Semi DevWare device and passing it to the Imatest IT/.NET eSFRISO module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireONSemiDevWareOptions onSemiDevWareOptions = new ImatestAcquireONSemiDevWareOptions();

        onSemiDevWareOptions.Extension = "bmp";
        onSemiDevWareOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromONSemiDevWare(onSemiDevWareOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.eSFRISO.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from an Android Camera Interface Device

This example demonstrates loading an image from an Android Camera Interface device and passing it to the Imatest IT/.NET Random module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireAndroidCameraInterfaceOptions androidOptions = new ImatestAcquireAndroidCameraInterfaceOptions();

        androidOptions.Extension = "bmp";
        androidOptions.Filename = "test_image.bmp";

        ImatestAcquireResult acqResult = lib.AcquireFromAndroidCameraInterface(androidOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Random.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

Acquiring from a File

This example demonstrates loading an image from a file and passing it to the Imatest IT/.NET Stepchart module for testing, then printing the results to the console.

    using (Library lib = new Library())
    {
        DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

        string rootDir = currentDirectory.Parent.Parent.Parent.FullName;

        ImatestAcquireFromFileOptions fromFileOptions = new ImatestAcquireFromFileOptions();

        fromFileOptions.Extension = "bmp";
        fromFileOptions.Filename = "test_image.bmp";
        fromFileOptions.ImageFilePath = @"C:\Program Files\Imatest\v4.5\IT\samples\images\stepchart_example.jpg";
        fromFileOptions.IniFilePath = Path.Combine(rootDir, "imatest-v2.ini");

        ImatestAcquireResult acqResult = lib.AcquireFromFile(fromFileOptions);

        if (acqResult.Success)
        {
            ImatestImage img = acqResult.Image;

            string jsonResult = lib.Stepchart.JSON(rootDir, img);

            Console.Out.Write(jsonResult);
        }
        else
        {
            throw new Exception("Could not acquire image from device.");
        }
    }

筆記

  • 在呼叫AcquireFrom*()方法之前,設備必須由各自的控制軟體正確初始化。
  • 如果設備需要使用Imatest IS 設備管理員儲存的設置,則需要將相應的設備設置 JSON 檔案包含在 Imatest INI 檔案中。