コンテンツにスキップ
ステージングサーバー
開発サーバー

.NETプログラマーズガイド#

このトピックでは、Basler blazeカメラ固有の情報について説明します。pylon .NET APIの包括的な概要を網羅することを目的としたものではありません。

pylonを初めて使用する場合は、まずpylon .NETプログラマーガイドをお読みになり、pylon .NET APIに慣れることをBaslerではお勧めしています。

.NETプログラミングサンプル#

blazeカメラのプログラミングサンプルが含まれるフォルダを開くには、Winキーを押してBaslerフォルダに移動し、blaze Samplesを選択します。エクスプローラウィンドウが開きます。.NETプログラミングサンプルはDotNetフォルダ内にあります。

サンプルの構築方法#

情報

サンプルのビルドを行う前に、サンプルが含まれているフォルダを、読み取りおよび書き込み権限のある任意の場所にコピーしてください。

サンプル用のVisual Studioソリューションおよびプロジェクトファイルが提供されています。Visual Studio 2017以降を使用してソリューションを開き、サンプルをビルドできます。

.NETアプリケーションの構築方法#

C#またはVisual Basic .NETを使用してBasler blazeカメラを操作するには、プロジェクトのアセンブリ参照リストに Basler.Pylon および Basler.Pylon.Blaze アセンブリを追加する必要があります。

アセンブリを追加するには:

  1. Visual Studioのソリューションエクスプローラでプロジェクトを右クリックし、[追加] > [プロジェクト参照]を選択します。
    [参照マネージャー]ウィンドウが開きます。
  2. [参照]ボタンをクリックします。
  3. %Program Files%\Basler\pylon 8\Development\Assemblies\Basler.Pylon\x64フォルダに移動します。
  4. Basler.Pylon.dllを選択し、[追加]ボタンをクリックします。
  5. [参照]ボタンをクリックします。
  6. %Program Files%\Basler\pylon 8\Development\Assemblies\Basler.Pylon.Blaze\AnyCpuフォルダに移動します。
  7. Basler.Pylon.Blaze.dllを選択し、[追加]ボタンをクリックします。

Basler.Pylonアセンブリのプロセッサアーキテクチャ

32ビットプラットフォーム向けのアセンブリを選択するか、64ビットプラットフォーム向けのものを選択するかは問題ではありません。アセンブリはグローバルアセンブリキャッシュ (GAC) にインストールされているため、.NETアセンブリローダーはアプリケーションのビルド対象のアーキテクチャに一致するものを自動的に選択します。

アプリケーションのビルド時に潜在的なアーキテクチャの不一致に関する警告が表示されるのを回避するため、BaslerではVisual Studioのプロジェクトファイルを手動で編集してこのような警告を非表示にすることを推奨しています。これを行うには、次の手順に従います。

  1. ソリューションエクスプローラーでプロジェクトを右クリックし、[プロジェクトのアンロード]を選択します。
  2. プロジェクトを再度右クリックし、[プロジェクトの編集]を選択します。
    プロジェクトのXMLファイルがエディターウィンドウで開きます。
  3. XMLファイル内で、 Basler.Pylon アセンブリが参照されている場所(つまり、次のようなフラグメント)に移動して検索します。

    <ItemGroup>
    ....
    <Reference Include="Basler.Pylon, Version=1.2.0.0, Culture=neutral,
        PublicKeyToken=e389355f398382ab, processorArchitecture=AMD64" />/
    
  4. の上 ItemGroup 要素に、次のXMLフラグメントを追加します。

    <PropertyGroup>
    <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
    </PropertyGroup>
    

    要素を追加した後、プロジェクトファイルには次のようなセグメントが含まれている必要があります。

    <PropertyGroup>
        <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
    </PropertyGroup>
    <ItemGroup>
    ....
    <Reference Include="Basler.Pylon">
        <HintPath>..\..\..\..\..\..\Program Files\Basler\pylon\Development\Assemblies\Basler.Pylon\x64\Basler.Pylon.dll</HintPath>
    </Reference>
    <Reference Include="Basler.Pylon.Blaze">
        <HintPath>..\..\..\..\..\..\Program Files\Basler\pylon\Development\Assemblies\Basler.Pylon.Blaze\AnyCpu\Basler.Pylon.Blaze.dll</HintPath>
    </Reference>
    ....
    </ItemGroup>
    
  5. 編集が完了したら、プロジェクトを右クリックして[プロジェクトの再読み込み]を選択し、プロジェクトを再読み込みします。
    確認メッセージが表示されたら、プロジェクトファイルを閉じて保留中の変更を保存することを承認します。

blazeカメラを開いてアクセスする#

pylon .NET APIには、すべてのカメラタイプに対応する単一の Camera クラスが用意されています。特定のカメラデバイスを選択するために、オーバーロードされたコンストラクターを利用できます。

blazeカメラオブジェクトを作成して開くには、3つのステップが必要です。

  1. アクセスするカメラのカメラオブジェクトを作成します。

  2. デフォルト設定を適用するblaze固有のパラメータ設定を登録します。blaze設定イベントハンドラークラスの詳細については、事前定義されたカメラパラメータ設定のセクションを参照してください。

  3. アプリケーションで次のメソッドを呼び出します。 Open() メソッドを使用して、カメラデバイスとの接続を確立します。

次の例は、これら3つのステップを示しています。

using Basler.Pylon;
using Basler.Pylon.Blaze;

// ...

var filter = new Dictionary<string, string> {
    { CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass }
};
using (var camera = new Camera(filter, CameraSelectionStrategy.FirstFound))
{
    // Set up the camera for continuously grabbing point clouds.
    camera.CameraOpened += BlazeConfigurations.AcquirePointCloudsContinuously;

    // Open the connection to the camera device.
    camera.Open();

    // Use the camera.

    // Close the connection.
    camera.Close();
}
Imports Basler.Pylon
Imports Basler.Pylon.Blaze

' ...

Dim filter = New Dictionary(Of String, String) From {
    {CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass}
}
Using camera = New Camera(filter, CameraSelectionStrategy.FirstFound)
    ' Set up the camera for continuously grabbing point clouds.
    AddHandler camera.CameraOpened,
        AddressOf BlazeConfigurations.AcquirePointCloudsContinuously

    ' Open the connection to the camera device.
    camera.Open()

    ' Use the camera.

    ' Close the connection.
    camera.Close()
End Using

最初に検出されたblazeカメラのカメラオブジェクトの作成#

イメージ Camera クラスには、カメラオブジェクトの作成元となったカメラデバイスのPropertyを指定するキーと値のペアのリストを渡すことができるコンストラクターが用意されています。

利用可能な最初のblazeカメラを開くには、デバイスタイプがblazeデバイスクラスと等しいことを指定するだけで十分です。

var filter = new Dictionary<string, string> {
    { CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass }
};
using (var camera = new Camera(filter, CameraSelectionStrategy.FirstFound))
{
}
Dim filter = New Dictionary(Of String, String) From {
    {CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass}
}
Using camera = New Camera(filter, CameraSelectionStrategy.FirstFound)

End Using

特定のblazeカメラのカメラオブジェクトの作成#

シリアル番号を指定するなどして特定のblazeカメラを開くには、blazeカメラ用のpylonデバイスクラス識別子を渡すことに加えて、 CreateFirstDevice()に対して、さらにPropertyを指定することができます。

次のコードスニペットは、シリアル番号によってblazeカメラを開く方法を示しています。

// Specify device class and serial number.
var filter = new Dictionary<string, string>
{
    { CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass },
    { CameraInfoKey.SerialNumber, "20399956" }
};
using (var camera = new Camera(filter, CameraSelectionStrategy.Unambiguous))
{
}
Dim filter = New Dictionary(Of String, String) From {
    {CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass},
    { CameraInfoKey.SerialNumber, "20399956" }
}
Using camera = New Camera(filter, CameraSelectionStrategy.FirstFoundUnambiguous)

End Using

ユーザー定義の名前でblazeカメラを開くには、次の行を使用します。

// Specify device class and serial number.
var filter = new Dictionary<string, string>
{
    { CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass },
    { CameraInfoKey.UserDefinedName, "Top" }
};
using (var camera = new Camera(filter, CameraSelectionStrategy.Unambiguous))
{
}
Dim filter = New Dictionary(Of String, String) From {
    {CameraInfoKey.DeviceType, DeviceType.BaslerGenTlBlazeDeviceClass},
    { CameraInfoKey.UserDefinedName, "Top" }
}
Using camera = New Camera(filter, CameraSelectionStrategy.FirstFoundUnambiguous)

End Using

User-Defined Names

を使用して、カメラにユーザー定義名を割り当てることができます。 DeviceUserID パラメータ。これを行うには、blaze Viewer、pylon IP Configurator、またはpylon APIを使用します。

camera.Parameters[PLBlaze.DeviceUserID].SetValue("MyCamera");
camera.Parameters(PLBlaze.DeviceUserID).SetValue("MyCamera")

IPアドレスによるデバイスの作成

現在、IPアドレスを指定してデバイスを作成することはできません。

特定のIPアドレスを持つカメラを作成して開くには、まずすべてのカメラを列挙し、返されたリストを反復処理し、IPアドレスやその他のネットワーク関連情報を照会する前に各カメラを開く必要があります。

目的のblazeカメラが見つからない場合は、Propertyに正しい値を使用しているかどうかを確認し、カメラとネットワークアダプターのIP設定を確認してください。ネットワークの設定の詳細については、ネットワーク設定トピックを参照してください。

事前定義されたカメラパラメータ設定#

blaze カメラの場合、 BlazeConfigurations クラスが存在します。このクラスのメソッドを CameraOpened イベントに追加できます。これを行うには、カメラを開く前に Open() メソッドを呼び出します。カメラが開かれると、設定メソッドが自動的に呼び出され、それに応じてカメラの設定が変更されます。

例:

// Set up the camera for continuously grabbing point clouds.
camera.CameraOpened += BlazeConfigurations.AcquirePointCloudsContinuously;
' Set up the camera for continuously grabbing point clouds.
AddHandler camera.CameraOpened,
AddressOf BlazeConfigurations.AcquirePointCloudsContinuously

イメージ BlazeConfigurations は、以下の設定メソッドを提供します。

  • AcquirePointCloudsContinuously
    データを連続して取得します。深度データはポイントクラウドとして表現されます。
  • AcquireDepthMapsContinuously
    データを連続して取得します。深度データはデプスマップとして表現されます。

pylon の設定イベントハンドラーの詳細については、pylon .NET プログラマーズガイドの定義済みカメラパラメータ設定セクションを参照してください。

深度データの解釈#

Range データコンポーネントに保存される深度データの形式については、測定結果の処理トピックを参照してください。

カメラへの接続#

カメラオブジェクトを作成し、設定イベントハンドラーを登録した後、次のメソッドを呼び出すことでカメラとの接続が確立されます: CBlazeInstantCamera::Open() メソッド。

接続は、次のメソッドが呼び出されるまで維持されます: CBlazeInstantCamera::Close() メソッドが呼び出されます。 Camera クラスのデストラクタは、明示的に呼び出されていない場合、自動的に Close() を呼び出します。カメラオブジェクトのライフサイクルを明示的に制御するため、Basler では上記のコードスニペットに示すように、using ステートメント内でカメラオブジェクトを使用することを推奨しています。

カメラがハートビートリクエストを定期的に受信しない場合、カメラは接続を閉じます。ハートビートリクエストの欠落は、アプリケーションがクラッシュした場合やデバッガーによって中断された場合に発生します。詳細については、アプリケーションのデバッグと GigE Vision ハートビートの制御セクションを参照してください。

パラメータへのアクセス#

pylon .NET API を使用したカメラパラメータへのアクセス方法について理解するには、pylon .NET プログラマーズガイドのパラメータアクセスセクションを参照してください。

pylon .NET API は、Visual Studio の IntelliSense のサポートを受けながらカメラパラメータにアクセスするための便利な方法として、パラメータリストを提供します。

blaze カメラの場合、 PLBlaze パラメータリスト。

以下のコードスニペットは、次を使用してパラメータを設定および取得する方法を示しています。 PLBlaze パラメータリスト。

// Set the operating mode of the camera. The choice you make here
// affects the working range of the camera, i.e., the Minimum Working
// Range and Maximum Working Range parameters.
var oldOperatingMode = camera.Parameters[PLBlaze.OperatingMode].GetValue();
camera.Parameters[PLBlaze.OperatingMode].SetValue(PLBlaze.OperatingMode.LongRange);

// Exposure time of the camera. If the operating mode is changed, the
// exposure time is set to the recommended default value.
camera.Parameters[PLBlaze.ExposureTime].SetValue(750); // us

// Enable and configure image filtering.

// The spatial noise filter uses the values of neighboring pixels to
// filter out noise in an image.
camera.Parameters[PLBlaze.SpatialFilter].SetValue(true);

// The temporal noise filter uses the values of the same pixel at
// different points in time to filter out noise in an image.
camera.Parameters[PLBlaze.TemporalFilter].SetValue(true);
camera.Parameters[PLBlaze.TemporalFilterStrength].SetValue(220);

// The outlier removal removes pixels that differ significantly from
// their local environment.
camera.Parameters[PLBlaze.OutlierRemoval].SetValue(true);

// Some properties have restrictions.
// We use API functions that automatically perform value corrections.
// Alternatively, you can use GetInc() / GetMin() / GetMax() to make sure you
// set a valid value.
camera.Parameters[PLBlaze.ConfidenceThreshold].SetValue(
    321,
    IntegerValueCorrection.Nearest
);

// Not all functions are available in older cameras.
// Therefore, we must use "Try" functions that only perform the action
// when parameters are writable. Otherwise, we would get an exception.
camera.Parameters[PLBlaze.MultiCameraChannel].TrySetValue(1);

Console.WriteLine("Operating Mode           : {0}",
    camera.Parameters[PLBlaze.OperatingMode].GetValue());
Console.WriteLine("Exposure Time            : {0}",
    camera.Parameters[PLBlaze.ExposureTime].GetValue());
Console.WriteLine("Spatial Filter           : {0}",
    camera.Parameters[PLBlaze.SpatialFilter].GetValue());
Console.WriteLine("Temporal Filter          : {0}",
    camera.Parameters[PLBlaze.TemporalFilter].GetValue());
Console.WriteLine("Temporal Filter Strength : {0}",
    camera.Parameters[PLBlaze.TemporalFilterStrength].GetValue());
Console.WriteLine("Outlier Removal          : {0}",
    camera.Parameters[PLBlaze.OutlierRemoval].GetValue());
Console.WriteLine("Confidence Threshold     : {0}",
    camera.Parameters[PLBlaze.ConfidenceThreshold].GetValue());
if (camera.Parameters[PLBlaze.MultiCameraChannel].IsReadable)
{
    Console.WriteLine("Multi-Camera Channel     : {0}",
        camera.Parameters[PLBlaze.MultiCameraChannel].GetValue());
}

// Restore the old operating mode.
camera.Parameters[PLBlaze.OperatingMode].SetValue(oldOperatingMode);
' Set the operating mode of the camera. The choice you make here
' affects the working range of the camera, i.e., the Minimum Working
' Range and Maximum Working Range parameters.
Dim oldOperatingMode = camera.Parameters(PLBlaze.OperatingMode).GetValue()
camera.Parameters(PLBlaze.OperatingMode).SetValue(PLBlaze.OperatingMode.LongRange)

' Exposure time of the camera. If the operating mode is changed, the
' exposure time is set to the recommended default value
camera.Parameters(PLBlaze.ExposureTime).SetValue(750) ' us

' Enable and configure image filtering.

' The spatial noise filter uses the values of neighboring pixels to
' filter out noise in an image.
camera.Parameters(PLBlaze.SpatialFilter).SetValue(True)

' The temporal noise filter uses the values of the same pixel at
' different points in time to filter out noise in an image.
camera.Parameters(PLBlaze.TemporalFilter).SetValue(True)
camera.Parameters(PLBlaze.TemporalFilterStrength).SetValue(220)

' The outlier removal removes pixels that differ significantly from
' their local environment
camera.Parameters(PLBlaze.OutlierRemoval).SetValue(True)

' Some properties have restrictions.
' We use API functions that automatically perform value corrections.
' Alternatively, you can use GetInc() / GetMin() / GetMax() to make sure you set
' a valid value.
camera.Parameters(PLBlaze.ConfidenceThreshold).SetValue(
    321,
    IntegerValueCorrection.Nearest
)

' Not all functions are available in older cameras.
' Therefore, we must use "Try" functions that only perform the action
' when parameters are writable. Otherwise, we would get an exception.
camera.Parameters(PLBlaze.MultiCameraChannel).TrySetValue(1)

Console.WriteLine("Operating Mode           : {0}",
    camera.Parameters(PLBlaze.OperatingMode).GetValue())
Console.WriteLine("Exposure Time            : {0}",
    camera.Parameters(PLBlaze.ExposureTime).GetValue())
Console.WriteLine("Spatial Filter           : {0}",
    camera.Parameters(PLBlaze.SpatialFilter).GetValue())
Console.WriteLine("Temporal Filter          : {0}",
    camera.Parameters(PLBlaze.TemporalFilter).GetValue())
Console.WriteLine("Temporal Filter Strength : {0}",
    camera.Parameters(PLBlaze.TemporalFilterStrength).GetValue())
Console.WriteLine("Outlier Removal          : {0}",
    camera.Parameters(PLBlaze.OutlierRemoval).GetValue())
Console.WriteLine("Confidence Threshold     : {0}",
    camera.Parameters(PLBlaze.ConfidenceThreshold).GetValue())

If camera.Parameters(PLBlaze.MultiCameraChannel).IsReadable Then
    Console.WriteLine("Multi-Camera Channel     : {0}",
        camera.Parameters(PLBlaze.MultiCameraChannel).GetValue())
End If

' Restore the old operating mode.
camera.Parameters(PLBlaze.OperatingMode).SetValue(oldOperatingMode)

データの取得#

pylon .NET API を使用したデータ取得方法について理解するには、pylon .NET プログラマーズガイドの画像の取得セクションを参照してください。

pylon では、取得した画像が GrabResults と呼ばれるデータ構造として表現されます。2D カメラによって取得された GrabResults には、単一のグレー値またはカラー画像が含まれます。

blaze カメラによって取得された GrabResults には、複数のコンポーネントが含まれます。デフォルトでは、各 GrabResult に強度画像、信頼度マップ、および深度情報が保存されます。

Range コンポーネントに設定された Pixel Format に応じて、深度データを 2D デプスマップまたは 3D ポイントクラウドとして表現できます。

情報

カメラに深度情報をポイントクラウドとデプスマップの両方として同時に送信させることはできません。

デプスマップからポイントクラウドを計算する方法については、測定結果の処理トピックで説明されています。

グラブーループ#

pylonは、グラブループを設定するためのさまざまなアプローチをサポートし、メモリバッファを処理するためのさまざまなストラテジを提供します。

詳細については、pylon .NET プログラマーズガイドの画像の取得セクションを参照してください。

以下のコードサンプルは、一般的なグラブーループを示しています。

// Open the connection to the camera device.
camera.Open();

// The MaxNumBuffer parameter can be used to control the amount of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(3);

// Start grabbing.
camera.StreamGrabber.Start();

// Grab a number of images.
for (int i = 0; i < 10; ++i)
{
  // Wait for an image and then retrieve it. A timeout of 1000 ms is used.
  IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(
      1000,
      TimeoutHandling.ThrowException
  );
  using (grabResult) // Make sure that the grab buffers are reused for
                     // grabbing as soon we run out of scope.
  {
    // Image grabbed successfully?
    if (grabResult.GrabSucceeded)
    {
      // Access the data.
      // ....
    }
    else
    {
      Console.WriteLine("Error: {0} {1}",
      grabResult.ErrorCode, grabResult.ErrorDescription);
    }
  }
}
// Stop grabbing.
camera.StreamGrabber.Stop();
' Open the connection to the camera device.
camera.Open()

' The MaxNumBuffer parameter can be used to control the amount of buffers
' allocated for grabbing. The default value of this parameter is 10.
camera.Parameters(PLCameraInstance.MaxNumBuffer).SetValue(3)

' Start grabbing.
camera.StreamGrabber.Start()

' Grab a number of images.
For i As Integer = 0 To 10 - 1
  ' Wait for an image and then retrieve it. A timeout of 1000 ms is used.
  Dim grabResult As IGrabResult = camera.StreamGrabber.RetrieveResult(
    1000,
    TimeoutHandling.ThrowException
  )

  Using grabResult
    ' Image grabbed successfully?
    If grabResult.GrabSucceeded Then
      ' Access the data.
      ' ....
    Else
      Console.WriteLine("Error: {0} {1}",
        grabResult.ErrorCode,
        grabResult.ErrorDescription)
    End If
  End Using
Next

' Stop grabbing.
camera.StreamGrabber.Stop()

コンポーネントへのアクセス#

GrabResultの個々のコンポーネントにアクセスするには、 IDataContainer および IDataComponent クラス。コンテナには1つ以上のコンポーネントを格納できます。コンテナを使用して、コンポーネントの数を照会したり、特定のコンポーネントを取得したりできます。コンテナ内の各コンポーネントには、深度値などの実際のデータと、そのメタデータが保持されます。

設定するピクセルのカラーコンポーネントを指定するには、 IGrabResult::GetDataContainer() メソッドを使用すると、GrabResultの IDataContainer.

pylonが複数のコンポーネントを含むGrabResultsへのアクセスを提供する方法の詳細については、pylon .NETプログラマーガイドのマルチコンポーネントグラブ結果セクションを参照してください。

例:

IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(
  1000,
  TimeoutHandling.ThrowException
);
using (grabResult)
{
  // Image grabbed successfully?
  if (grabResult.GrabSucceeded)
  {
    // Access the components.
    // The container and the components should always be used in combination
    // with using statements. This ensures that the underlying grab buffers
    // are reused for grabbing new data as soon as the variables go out
    // of scope. Omitting the using statements and relying on the garbage
    // collector instead will cause buffer underruns resulting in missed data.
    using (var container = grabResult.Container)
    using (var rangeComponent = container[0])
    using (var intensityComponent = container[1])
    using (var confidenceComponent = container[2])
    {
      var pointCloudData = rangeComponent.PixelData as float[];
      var intensityData = intensityComponent.PixelData as UInt16[];
      var confidenceData = confidenceComponent.PixelData as UInt16[];

      // Access the center pixel.
      var u = (uint)(rangeComponent.Width / 2);
      var v = (uint)(rangeComponent.Height / 2);
      var idx = v * rangeComponent.Width + u;
      var intensity = intensityData[idx];
      var confidence = confidenceData[idx];
      // There is a triple (x,y,z) of floats per pixel.
      var x = pointCloudData[3 * idx];
      var y = pointCloudData[3 * idx + 1];
      var z = pointCloudData[3 * idx + 2];

      if (confidence != 0) // Alternatively: if (z != 0)
      {
        // Valid depth data
        Console.WriteLine("x={0}, y={1}, z={2}, intensity={3}, confidence = {4}",
            x, y, z, intensity, confidence);
      }
      else
      {
        Console.WriteLine("No depth data available for pixel ({0},{1}), intensity={2}",
        u, v, intensity);
      }
  }
  else
  {
      Console.WriteLine("Error: {0} {1}",
        grabResult.ErrorCode, grabResult.ErrorDescription);
  }
}
Dim grabResult As IGrabResult =
  camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException)

Using grabResult
  ' Image grabbed successfully?
  If grabResult.GrabSucceeded Then
    ' Access the components.
    ' The container and the components should always be used in combination with
    ' using statements. This ensures that the underlying grab buffers are reused
    ' for grabbing new data as soon as the variables go out of scope.
    ' Omitting the using statements and relying on the garbage collector instead
    ' will cause buffer underruns resulting in missed data.
    Using container = grabResult.Container,
      rangeComponent = container(0),
      intensityComponent = container(1),
      confidenceComponent = container(2)

      Dim pointCloudData = TryCast(rangeComponent.PixelData, Single())
      Dim intensityData = TryCast(intensityComponent.PixelData, UInt16())
      Dim confidenceData = TryCast(confidenceComponent.PixelData, UInt16())

      ' Access the center pixel.
      Dim u = CUInt((rangeComponent.Width / 2))
      Dim v = CUInt((rangeComponent.Height / 2))
      Dim idx = v * rangeComponent.Width + u
      Dim intensity = intensityData(idx)
      Dim confidence = confidenceData(idx)
      Dim x = pointCloudData(3 * idx)
      Dim y = pointCloudData(3 * idx + 1)
      Dim z = pointCloudData(3 * idx + 2)

      If confidence <> 0 Then ' Alternatively: if (z != 0)
        ' Valid depth data
        Console.WriteLine("x={0}, y={1}, z={2}, intensity={3}, confidence = {4}",
          x, y, z, intensity, confidence)
      Else
        Console.WriteLine("No depth data available for pixel ({0},{1}), intensity={2}",
          u, v, intensity)
      End If
    End Using
  Else
    Console.WriteLine("Error: {0} {1}", grabResult.ErrorCode,
      grabResult.ErrorDescription)
  End If
End Using

深度データの解釈#

Range データコンポーネントに保存される深度データの形式については、測定結果の処理トピックを参照してください。

アプリケーションのデバッグとGigE Visionハートビートの制御#

pylon 7.0以下を使用している場合の再接続の問題

アプリケーションがカメラとの接続を正常に切断する前に終了またはクラッシュした場合、ハートビートのタイムアウトが切れるまでカメラは接続を開いたままにします。ハートビートのタイムアウトが切れるまで、カメラはそれ以降の接続試行をすべて拒否します。アプリケーションを再起動するか、カメラへのアクセスを要求する別のアプリケーションを起動すると、デバイスが現在使用中であるというエラーを受け取ります。

これは通常、デバッガーを使用してアプリケーションを停止した場合や、アプリケーションが予期せず終了した場合に発生します。カメラを再度オープンするには、タイムアウトが経過するまで待つか、カメラをネットワークから一時的に切断する必要があります。

これを回避するには、デバッガーの制御下でアプリケーションを実行しているときに、環境変数を次のように設定することで、ハートビートタイムアウトの自動調整を上書きできます。 GEV_HEARTBEAT_TIMEOUT 目的のタイムアウト値をミリ秒単位で指定します。または、サンプルプログラムに示されているように、pylon APIを使用してアプリケーションでハートビートタイムアウトを設定することもできます。 DeviceRemovalCSharp および DeviceRemovalVB サンプルプログラム。