溫馨提示×

VisionPro C#如何測量尺寸

c#
小樊
192
2024-07-16 16:31:45
欄目: 編程語言

在VisionPro C#中,可以使用VisionPro的工具庫中的測量功能來測量尺寸。以下是一個簡單的示例代碼,用于測量圖像中一個目標區域的尺寸:

using System;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;

class Program
{
    static void Main()
    {
        // 創建一個圖像工具
        CogImage8Grey image = new CogImage8Grey();

        // 加載需要處理的圖像
        image.LoadFromFile("image.jpg");

        // 創建一個測量工具
        CogRectangleAffine tool = new CogRectangleAffine();

        // 設置測量工具的參數
        tool.RunParams.SetRunStatus(true);
        tool.GraphicDOFEnable = CogRectangleDOFConstants.All;

        // 對圖像進行測量
        tool.InputImage = image;
        tool.Run();

        // 獲取測量結果
        double width = tool.Width;
        double height = tool.Height;

        // 打印測量結果
        Console.WriteLine("Width: " + width);
        Console.WriteLine("Height: " + height);
    }
}

在上面的示例中,我們首先加載了一個圖像,并創建了一個矩形測量工具。然后設置了測量工具的參數,并對圖像進行測量。最后,我們獲取了測量結果,并打印出來。

請注意,以上示例是一個簡單的示例,實際應用中可能需要根據具體需求來調整代碼和參數。您可以參考VisionPro的文檔和示例代碼來進一步了解如何在VisionPro C#中測量尺寸。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女