웹캠, opencv 및 emgucv를 사용하여 사진을 캡처 할 때 특별한 문제가 있습니다.캡쳐 한 장 찍기 전에 - 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 함수()는 일부 버튼있게 다음은 타이머를 사용하는 코드이다.
문제는 다음과 같습니다. 첫 번째 사진 찍기 - 그림 상자에 첫 번째 그림이 표시됩니다. 두 번째 사진 찍기 - 첫 번째 사진을 다시 보여줍니다. 세 번째 그림을 찍습니다 - 그림 상자는 두 번째 그림을 보여줍니다. 네 번째 사진을 찍습니다 - 그림 상자는 세 번째 사진을 보여줍니다. 어떤 도움 ... ... 촬영 후, 난 단지 색상을 인식하고 흰색에 그 색과 검은 색 사진의 나머지 부분을 (다른 사람이 설명을 필요로하는 경우) 표시하고 있습니다 는
감사합니다 너 나 줄 수있어! 나는 함수의 끝 부분에이 라인을 추가하는 경우 :
은 편집 = 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을 사용하기로 결정하고 완벽하게 작동하므로 해당 솔루션을 사용하려고합니다. 도움과 답장을 보내 주셔서 감사합니다. –