C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.85365 の関連記事表示

<< 0 >>
■85365  Re[14]: カメラ台数を増やす
□投稿者/ Jitta -(2017/10/15(Sun) 09:03:05)
    2017/10/15(Sun) 13:02:21 編集(投稿者)
    2017/10/15(Sun) 13:01:00 編集(投稿者)

    Imports AForge.Video
    Imports AForge.Video.DirectShow

    Public Class Form1
    Dim _videoDevices1 As FilterInfoCollection
    Dim _videoDevices As FilterInfoCollection

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    '保存先の指定
    TextBox1.Text = "C:\tic\"
    'スイッチを使用禁止にする
    ' ComboBox1.Enabled = False
    Button2.Enabled = False
    Button3.Enabled = False
    Button4.Enabled = False
    Button5.Enabled = False
    'ビデオデバイス一覧を表示する
    _videoDevices = New FilterInfoCollection(FilterCategory.VideoInputDevice)

    ComboBox1.Items.Clear()
    If _videoDevices.Count <> 0 Then
    For Each device In _videoDevices
    ComboBox1.Items.Add(device.Name)
    Next
    ComboBox1.SelectedIndex = 0
    End If

    '※ _videoDevices と同じなので不要
    _videoDevices1 = New FilterInfoCollection(FilterCategory.VideoInputDevice)

    ComboBox2.Items.Clear()
    '※ _videoDevices1 を使っていなければおかしい
    '※ こういうところが「何がしたいの?」とわからなくさせる。
    '※ 「0 ではない」ではなく、「2以上なら」では?
    '※ comboBox2 に表示させる条件、モノが不明
    '※ 「カメラが2台以上あるとき」で、「2台以上ある」のは確定なのか。
    '※ ここで初期値としたいのは「ComboBox1 とは違うもの」なのか。
    '※ などの仕様が不明。
    If _videoDevices.Count <> 0 Then
    For Each device In _videoDevices
    ComboBox2.Items.Add(device.Name)
    Next
    '※ こちらは 「ComboBox2.SelectedIndex = 1」 では?
    ComboBox2.SelectedIndex = 0
    End If
    End Sub

    Dim _videoSource As VideoCaptureDevice = Nothing
    Private ReadOnly cameraControl1 As Object
    Private ReadOnly dt As Object
    Private formatteddate As String
    Private intNUM As Integer

    > わからんところ↓ビデオデバイスを画像をのComboBox2で
    > 選択された2代目カメラPictureBox3出力されないところ。
    '※ 「選択された2台目のカメラがPictureBox3に出力されない」?

    'ビデオデバイス取得画像表示
    Private Sub Video_NewFrame(sender As Object, eventArgs As NewFrameEventArgs)
    Dim img = DirectCast(eventArgs.Frame.Clone(), Bitmap)
    PictureBox1.Image = img

    'ビデオデバイス取得画像表示
    ' Private Sub Video_NewFrame1(sender As Object, eventArgs As NewFrameEventArgs)
    ' Dim img1 = DirectCast(eventArgs1.Frame.Clone(), Bitmap)
    ' PictureBox3.Image = img1
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    > ここでボタンを押すとComboBox1が例えばaのPictureBox1に接続表示
    > で、ComboBox1で選択された2代目がPictureBox3に出力されるようにしたいのですが
    > なかなかうまくいかないです。↓

    'USBビデオデバイスに接続表示
    '※ なぜ ComboBox2 の状態は調べないのですか?
    '※ ComboBox は、「選択していない」状態が選べます。
    '※ また、「Combo」は、DropdownList と TextBox のコンボ(組み合わせ)を意味します。
    '※ カメラを示さない文字列が入力されていたら、どうしますか。
    If ComboBox1.Items.Count = 0 Then
    Return
    End If

    '※ ここから「スイッチを使用可能にする」までの行は、何をしていますか。
    '※ その意味を知ってください。
    '※ プログラムは、「計画、予定、内容」を意味します。
    '※ 「プログラムを作る」は、コードを書くことではなく、コンピュータの動作予定を作ることです。
    '※ 今回のメインはここです。ここが何をしているのか、理解してください。
    '※ 今のプログラムは、
    '※ 「ComboBox1 に選択されているカメラと接続する」
    '※ 「接続したカメラからフレームの入力があれば Me.Video_NewFrame を実行するようにする」
    '※ 「接続したカメラからの入力を開始する」
    '※ です。これが、どのようになればいいのか、コードの前にプログラムを作ってください。
    '※ プログラム=何を、どのような順で実行するか、ができなければ、コードは書けません。
    Dim MonikerString = _videoDevices(ComboBox1.SelectedIndex).MonikerString '最初のビデオデバイスを使用

    _videoSource = New VideoCaptureDevice(MonikerString)
    AddHandler _videoSource.NewFrame, AddressOf Me.Video_NewFrame
    _videoSource.Start()

    'スイッチを使用可能にする
    Button2.Enabled = True
    Button3.Enabled = True
    Button4.Enabled = True
    Button5.Enabled = True
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'USBビデオデバイス停止
    If _videoSource Is Nothing Then
    Return
    End If

    If _videoSource.IsRunning Then
    _videoSource.SignalToStop() 'ビデオデバイスの停止
    _videoSource.WaitForStop() '完全に停止するまで待つ
    _videoSource = Nothing
    End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ' 自身のフォームを閉じる
    Me.Close()
    End
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    ' カウンタ
    Label2.Text = Label2.Text + 1
    '保存先を指定してjpgファぃるに保存する
    Dim ro As String = TextBox1.Text

    Dim dt = DateTime.Now
    formatteddate = dt.ToString("yyyy年MM月dd日hh時mm秒ss分")

    Dim fileName As String = ro + formatteddate + ".jpg"
    Label3.Text = formatteddate

    ' MessageBox.Show(fileName)
    '※ PictureBox1 と PictureBox2 の方法が違うのはなぜ?
    PictureBox1.Image.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg)

    '
    ' FileStream を開く
    '※ Stream は using 文を使ってください。
    Dim hStream As New System.IO.FileStream(fileName, System.IO.FileMode.Open)

    ' FileStream から画像を読み込んで表示
    Me.PictureBox2.Image = Image.FromStream(hStream)

    ' FileStream を閉じる (正しくは オブジェクトの破棄を保証する を参照)
    hStream.Close()
    End Sub

    Private Function vrnINPUT() As String
    Throw New NotImplementedException()
    End Function

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    'カウンタ内容を0にリセットする
    Label2.Text = "0"
    End Sub
    End Class


    > わからんところ↓ビデオデバイスを画像をのComboBox2で
    > 選択された2代目カメラPictureBox3出力されないところ。

    わからないところ↓ComboBox2 で選択された2台目のカメラ
    の画像が、PictureBox3 に出力されないところ。


    > ここでボタンを押すとComboBox1が例えばaのPictureBox1に接続表示
    > で、ComboBox1で選択された2代目がPictureBox3に出力されるようにしたいのですが
    > なかなかうまくいかないです。↓

    ここでボタンを押すと、ComboBox1 に選択されている a のカメラに接続され、
    PictureBox1 に表示させたい。また、ComboBox2 で選択されている2台目を、
    PictureBox3 に表示させたい。


    仕様:
    PCに、カメラが2台接続されている。
    アプリの画面には、ビデオ映像を表示する箇所(PictureBox)が2つある。
    それぞれの PictureBox に表示させるカメラを DropdownList で選ぶ。
    ボタンを押すと、選択されているそれぞれのカメラに接続し、画像を表示する。

    今できていること:
    カメラが1台の時、1つのPictureBox に表示させることはできている。

    できていないこと:
    2つのカメラに同時に接続する。
     ComboBox1 で選択したカメラを PictureBox1 に表示することしかできていない。
     ComboBox2 で選択したカメラを PictureBox3 に表示させたい。
記事No.85265 のレス /過去ログ146より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -