私のウェブカメラopencvとemgucvを使って画像をキャプチャする際に特に問題があります。キャプチャを1つ取ってから表示する - VB - OpenCV
私は以前にこの機能を使用していましたが、いつもうまく機能しましたが、今はなぜピクチャボックスに以前撮った写真が表示されているのか分かりません。
私はプログラムを開始します - 私はボタンを押して、画像が撮られるまで数秒待っています - img = capturez.QueryFrame()を使って画像を撮ります - PictureBoxに画像を表示します。ここでは、コードされています
Private Sub startButton_Click() Handles startButton.Click
Dim timeToWait As Integer
PictureBox1.Image = Nothing
If globalGMT <> Nothing And globalLatitude <> Nothing And globalLongitude <> Nothing Then
'If TextBox_GMT.Text IsNot Nothing And TextBox_LAT.Text IsNot Nothing And TextBox_LON.Text IsNot Nothing Then
SunPosition(globalGMT, globalLatitude, globalLongitude, ELEVACIONDELSOL, AZIMUTDELSOL)
End If
startButton.Enabled = False
SetDefaultTimeButton.Enabled = False
SetParameters.Enabled = False
TextBoxTime.Text = System.DateTime.UtcNow
timeToWait = globalTimeLeft
For i = 0 To timeLeft
wait()
i += 1
timeToWait -= 1
timeLabel.Text = timeToWait & " seconds"
Next
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
For x = 0 To img.Width - 1
For y = 0 To img.Height - 1
Dim pixelColor As Bgr = img(y, x)
If (pixelColor.Blue >= 200 And pixelColor.Blue <= 255) And
(pixelColor.Green >= 200 And pixelColor.Green <= 255) And (pixelColor.Red >= 200 And pixelColor.Red <= 255) Then
pixelColor.Blue = 255
pixelColor.Green = 255
pixelColor.Red = 255
img(y, x) = pixelColor
Else
pixelColor.Blue = 0
pixelColor.Green = 0
pixelColor.Red = 0
img(y, x) = pixelColor
End If
Next
Next
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End Sub
機能待ち()は次のようになります。
Private Sub wait()
Dim seconds As Integer = 1
For i As Integer = 0 To seconds * 100
System.Threading.Thread.Sleep(10)
'Application.DoEvents()
Next
End Sub
たぶん、あなたはなぜあなたはそのためにタイマーを使用していない、尋ねることができますか?タイマーではまったく同じ問題があるからです。
'This function will start the activity of the form
Private Sub startButton_Click() Handles startButton.Click
Dim timeToWait As Integer
PictureBox1.Image = Nothing
If globalGMT <> Nothing And globalLatitude <> Nothing And globalLongitude <> Nothing Then
'If TextBox_GMT.Text IsNot Nothing And TextBox_LAT.Text IsNot Nothing And TextBox_LON.Text IsNot Nothing Then
SunPosition(globalGMT, globalLatitude, globalLongitude, ELEVACIONDELSOL, AZIMUTDELSOL)
End If
startButton.Enabled = False
SetDefaultTimeButton.Enabled = False
SetParameters.Enabled = False
TextBoxTime.Text = System.DateTime.UtcNow
StartButtonTimer.Start()
End Sub
'This function will start the timer of the form
Private Sub StartButtonTimer_Tick() Handles StartButtonTimer.Tick
Dim X As Integer
Dim Y As Integer
If timeLeft > 0 Then
timeLeft -= 1
timeLabel.Text = timeLeft & " seconds"
'DLE prueba tomar foto después del tiempo especificado - pongo a negro el fondo del picturebox
PictureBox1.BackColor = Color.Black
Else
'DLE prueba tomar foto después del tiempo especificado - hago foto de lo que ve la camara
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
For X = 0 To img.Width - 1
For Y = 0 To img.Height - 1
Dim pixelColor As Bgr = img(Y, X)
If (pixelColor.Blue >= 200 And pixelColor.Blue <= 255) And
(pixelColor.Green >= 200 And pixelColor.Green <= 255) And
(pixelColor.Red >= 200 And pixelColor.Red <= 255) Then
pixelColor.Blue = 255
pixelColor.Green = 255
pixelColor.Red = 255
img(Y, X) = pixelColor
Else
pixelColor.Blue = 0
pixelColor.Green = 0
pixelColor.Red = 0
img(Y, X) = pixelColor
End If
Next
Next
StartButtonTimer.Stop()
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End If
End Sub
関数SETFORM()のみいくつかのボタンが有効になります。ここでは、タイマーを使用してコードがあります。
問題は次のとおりです。 私は最初の画像を撮ります - 画像ボックスは最初の画像を表示します。 私は2番目の写真を撮る - ピクチャボックスは再び最初の写真を表示する。 私は第3の写真を撮る - ピクチャボックスは第2の写真を表示する。 私は4番目の写真を撮る - ピクチャボックスは3番目の写真を表示します。 ... ... 写真を撮影した後、私は色だけを認識していますし、(誰かがこの説明を必要とする場合)、黒に白や画像の残りの部分でその色を示し、任意の助け
感謝あなたは私を与えることができます!
編集:私は関数の最後に次の行を追加する場合:= capturez.QueryFrame((BGR、バイト)画像)として暗いイメージ、それがうまく機能:
...
...
Next
StartButtonTimer.Stop()
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End If
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
End Sub
エンドクラス
この最後の変数は何も使用しません。私はそれを使用せずに宣言しています。私はなぜこの行でうまくいくのか分かりませんし、消去するとうまくいきません。
は、クイック検索は、() '犯人としてOpenCV.QueryFrame'を指すヒットの多くを思い付きました。 One [solution](http://stackoverflow.com/a/7517099/2330053)は基本的に 'QueryFrame()'を連続的にポーリングすることを提案しています。 –
あなたの返信ありがとう!最終的に最後に新しいQUeryFrameを使用することにしました。完全に機能するので、私はそのソリューションを使用するつもりです。助けや返事をありがとう!ありがとう! –