AForgeのVideoSourcePlayer コントロールを使用して、USB接続のカメラの画像を画面に表示方法を記載します。
VideoSourcePlayerは、AForge.Controls.dll に入っています。
コントロールのインストール手順
1.NugetでAForge.Controlsをインストールします。
2.ツールボックスの適当なところで右クリック「アイテムの選択(I)…」を選択
3.「.NET Framework コンポーネント」タブの「参照(B)…」ボタンを押して、「AForge.Controls.dll」を選択し「開く(O)」で読み込みます。
4.ツールボックスに「VideoSourcePlayer」というコントロールが追加されます。
VideoSourcePlayer コントロールによるUSBカメラ画像表示
フォームに ボタン2つ と VideoSourcePlayer コントロールを配置します。
'ビデオデバイス開始
Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
'ビデオキャプチャデバイスを選択するダイアログを生成
Dim VForm = New VideoCaptureDeviceForm()
'ビデオデバイス選択ダイアログを開く
If VForm.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
VideoSourcePlayer1.VideoSource = VForm.VideoDevice 'デバイスを設定
VideoSourcePlayer1.Start() 'ビデオキャプチャ開始
End If
End Sub
'ビデオデバイス停止
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
If Not VideoSourcePlayer1.VideoSource Is Nothing & VideoSourcePlayer1.VideoSource.IsRunning Then
VideoSourcePlayer1.VideoSource.SignalToStop() 'ビデオデバイスの停止
VideoSourcePlayer1.VideoSource.WaitForStop() '完全に停止するまで待つ
VideoSourcePlayer1.VideoSource = Nothing
End If
End Sub
[…] こちらに、VB.NETでAForge.Videoを使用してビデオキャプチャを行うサンプルコードがあります1。 […]