Sei sulla pagina 1di 5

Imports AForge.

Video
Imports AForge.Video.DirectShow
Imports AForge.Video.FFMPEG
Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel

Public Class Form1


Dim Puerto As Array
Delegate Sub SetTextCallBack(ByVal [text] As String)
Dim CAMARA As VideoCaptureDevice 'CAMARA QUE ESTAMOS USANDO
Dim BMP As Bitmap 'PARA GENERACION DE IMAGENES
Dim ESCRITOR As New VideoFileWriter() 'GUARDA LAS IMAGENES EN MEMORIA

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles


MyBase.Load
Puerto = IO.Ports.SerialPort.GetPortNames
ComboBox1.Items.AddRange(Puerto)
Button2.Enabled = False
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom ' POR SI OLVIDAMOS AJUSTAR EL
PICTUREBOX
scrollX.Value = 45
scrollY.Value = 45

End Sub

Private Sub ButtonCAMARA_Click(sender As System.Object, e As System.EventArgs)


Handles ButtonCAMARA.Click
Dim CAMARAS As VideoCaptureDeviceForm = New VideoCaptureDeviceForm()
'DIALOGO CAMARAS DISPONIBLES
If CAMARAS.ShowDialog() = DialogResult.OK Then
CAMARA = CAMARAS.VideoDevice 'CAMARA ELEGIDA
AddHandler CAMARA.NewFrame, New NewFrameEventHandler(AddressOf CAPTURAR)
' EJECUTARA CADA VEZ QUE SE GENERE UNA IMAGEN
CAMARA.Start() 'INICIA LA PRESENTACION DE IMAGENES EN EL PICTUREBOX
End If
End Sub

Private Sub ButtonVIDEO_Click(sender As System.Object, e As System.EventArgs)


Handles ButtonVIDEO.Click
If ButtonVIDEO.BackColor = Color.Black Then 'NO ESTA GRABANDO VIDEO
SaveFileDialog1.DefaultExt = ".avi" ' GUARDARA COMO ARCHIVO AVI
If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK
Then
Dim ANCHO As Integer = CAMARA.VideoResolution.FrameSize.Width
'DEFINE EL ANCHO DEL FOTOGRAMA
Dim ALTO As Integer = CAMARA.VideoResolution.FrameSize.Height '
DEFINE EL ALTO DEL FOTOGRAMA
'CREA EL ARCHIVO PARA LOS DATOS CON LOS PARAMETROS DE GUARDADO
ESCRITOR.Open(SaveFileDialog1.FileName, ANCHO, ALTO, 20,
VideoCodec.Default, 300 * 1000)
ESCRITOR.WriteVideoFrame(BMP) 'EMPIEZA A GUARDAR DATOS
ButtonVIDEO.BackColor = Color.Red 'PARA QUE SEPAMOS QUE ESTA
GRABANDO
End If
Else
ButtonVIDEO.BackColor = Color.Black ' ESTA GRABANDO
ESCRITOR.Close() 'DEJA DE GUARDAR DATOS
End If
End Sub

Private Sub CAPTURAR(sender As Object, eventArgs As NewFrameEventArgs)


If ButtonVIDEO.BackColor = Color.Black Then 'SI NO ESTA GRABANDO ......
BMP = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'PONE LOS DATOS EN EL
BITMAP
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'LOS
PRESENTA EN EL PICTURE BOX
Else ' SI ESTAS GRABANDO...
Try
BMP = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'PON LOS DATOS EN
EL BITMAP
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap) 'LOS
PRESENTA EN EL PICTURE BOX
ESCRITOR.WriteVideoFrame(BMP) 'LOS GUARDA EN LA MEMORIA
Catch ex As Exception
End Try
End If
End Sub

Private Sub ButtonFOTO_Click(sender As System.Object, e As System.EventArgs)


Handles ButtonFOTO.Click
CAPTURA.PictureBox1.Image = PictureBox1.Image 'COPIA LA IMAGEN QUE HAY EN EL
PICTUREBOX EN EL PICTUREBOX DEL FORMULARIO CAPTURA
CAPTURA.Show() 'MUESTRA EL FORMULARIO CAPTURA
End Sub

Private Sub ButtonCERRAR_Click(sender As System.Object, e As System.EventArgs)


Handles ButtonCERRAR.Click
SerialPort1.Close()
Me.Close() 'ESTE BOTON NO HACE FALTA PERO QUEDA ELEGANTE

End Sub

Private Sub Form1_FormClosing(sender As Object, e As


System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
CAMARA.Stop() 'CIERRA LA CAMARA
ESCRITOR.Close() 'DEJA DE GUARDAR DATOS.
Catch ex As Exception
End Try
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Try
SerialPort1.PortName = ComboBox1.Text
SerialPort1.BaudRate = ComboBox2.Text
SerialPort1.Open()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation)
End Try
If SerialPort1.IsOpen = True Then
Button2.Enabled = True
MsgBox("Conectado al puerto Com", MsgBoxStyle.Information, vbOK)
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
Dim intX, intY As Integer
Dim c(55) As Char
Dim strval As String
strval = ""
blclick = False
While Not blclick
Application.DoEvents()
While (Chr(SerialPort1.ReadChar()) <> "X" And SerialPort1.IsOpen = True)

End While
For i = 0 To 55
c(i) = Chr(SerialPort1.ReadChar)
If (c(i) = "\n") Then
Exit For
End If
Next

If (c(1) = "-" And c(3) = "." And c(8) = "-" And c(10) = ".") Then
intX = -Val(c(2))
intY = -Val(c(9))
End If
If (c(1) = "-" And c(3) = "." And c(8) = "-" And c(10) <> ".") Then
intX = -Val(c(2))
intY = -(Val(c(9)) * 10 + Val(c(10)))
End If
If (c(1) = "-" And c(3) = "." And c(8) <> "-" And c(9) = ".") Then
intX = -Val(c(2))
intY = Val(c(8))
End If
If (c(1) = "-" And c(3) = "." And c(8) <> "-" And c(9) <> ".") Then
intX = -Val(c(2))
intY = Val(c(8)) * 10 + Val(c(9))
End If

If (c(1) = "-" And c(3) <> "." And c(9) = "-" And c(11) = ".") Then
intX = -(Val(c(2)) * 10 + Val(c(3)))
intY = -Val(c(10))
End If
If (c(1) = "-" And c(3) <> "." And c(9) = "-" And c(11) <> ".") Then
intX = -(Val(c(2)) * 10 + Val(c(3)))
intY = -(Val(c(10)) * 10 + Val(c(11)))
End If
If (c(1) = "-" And c(3) <> "." And c(9) <> "-" And c(10) = ".") Then
intX = -(Val(c(2)) * 10 + Val(c(3)))
intY = Val(c(9))
End If
If (c(1) = "-" And c(3) <> "." And c(9) <> "-" And c(10) <> ".") Then
intX = -(Val(c(2)) * 10 + Val(c(3)))
intY = Val(c(9)) * 10 + Val(c(10))
End If
If (c(1) <> "-" And c(2) = "." And c(7) = "-" And c(9) = ".") Then
intX = Val(c(1))
intY = -Val(c(8))
End If
If (c(1) <> "-" And c(2) = "." And c(7) = "-" And c(9) <> ".") Then
intX = Val(c(1))
intY = -(Val(c(8)) * 10 + Val(c(9)))
End If
If (c(1) <> "-" And c(2) = "." And c(7) <> "-" And c(8) = ".") Then
intX = Val(c(1))
intY = Val(c(7))
End If
If (c(1) <> "-" And c(2) = "." And c(7) <> "-" And c(8) <> ".") Then
intX = Val(c(1))
intY = Val(c(7)) * 10 + Val(c(8))
End If

If (c(1) <> "-" And c(2) <> "." And c(8) = "-" And c(10) = ".") Then
intX = Val(c(1)) * 10 + Val(c(2))
intY = -Val(c(9))
End If
If (c(1) <> "-" And c(2) <> "." And c(8) = "-" And c(10) <> ".") Then
intX = Val(c(1)) * 10 + Val(c(2))
intY = -(Val(c(9)) * 10 + Val(c(10)))
End If
If (c(1) <> "-" And c(2) <> "." And c(8) <> "-" And c(9) = ".") Then
intX = Val(c(1)) * 10 + Val(c(2))
intY = Val(c(8))
End If
If (c(1) <> "-" And c(2) <> "." And c(8) <> "-" And c(9) <> ".") Then
intX = Val(c(1)) * 10 + Val(c(2))
intY = Val(c(8)) * 10 + Val(c(9))
End If

AX.Text = intY
AY.Text = intX
H.Text = c(15) + c(16) + c(17) + c(18) + c(19) + c(20) + c(21) + c(22) +
c(23) + c(24)
T.Text = c(27) + c(28) + c(29) + c(30) + c(31) + c(32) + c(33) + c(34) +
c(35) + c(36) + c(37)
GLP.Text = c(40) + c(41) + c(42) + c(43) + c(44) + c(45) + c(46) + c(47)
CO.Text = c(49) + c(50) + c(51) + c(52) + c(53) + c(54) + c(55)
scrollX.Value = 45 + (0.5 * intX)
scrollY.Value = 45 + (0.5 * -intY)
End While
If SerialPort1.IsOpen = False Then

End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
SerialPort1.Close()
blclick = True
End Sub
Private Sub Label5_Click(sender As Object, e As EventArgs) Handles labell.Click

End Sub

Private Sub Label5_Click_1(sender As Object, e As EventArgs) Handles


labelolo.Click

End Sub

Private Sub PictureBox2_Click(sender As Object, e As EventArgs)

End Sub

Private Sub T_Click(sender As Object, e As EventArgs) Handles T.Click

End Sub
End Class

Potrebbero piacerti anche