📄 mainapp.vb
字号:
CamSettings.DisplayMode = 5
Case 6
MenuItem8.Checked = True
showFaceImage = False
showProcessedImage = True
showPortrait = False
processedImageID = 6
'Me.picAvatar.Image = blank_img
picAvatar.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
gr.Clear(picAvatar.BackColor)
CamSettings.DisplayMode = 6
Case 7
MenuItem11.Checked = True
DETECTION_MODE = DETECTIONMODE_FACES
showFaceImage = False
showProcessedImage = False
showPortrait = True
processedImageID = 7
CamSettings.DisplayMode = 7
End Select
CamSettings.Save()
End Sub
''' <summary>
''' Show a portrait (JPEG image) of the currently observed person
''' </summary>
Public Sub show_Portrait()
'show an image of the recognised person
Dim i As Integer
Dim b As Byte
Dim filename As String
Static cnt As Integer
If ((currentPersonID > 0) And (RChbp_faceDetected())) Then
cnt = 0
i = 0
b = 1
filename = ""
While ((i < 150) And (b <> 13) And (b <> 0))
b = RChbp_getPortrait(currentPersonID, i)
If (b <> 13) And (b <> 0) Then
filename = filename & Chr(b)
End If
i = i + 1
End While
If (filename <> "") Then
Dim pimg As Image = Image.FromFile(filename)
Me.picAvatar.Image = pimg
Me.picAvatar.Refresh()
If (CamSettings.speakNames) Then
speakName()
End If
End If
Else
If (cnt < PORTRAIT_TIMEOUT) Then
cnt = cnt + 1
Else
'clear the image if the person has not been observed for a period of time
Me.picAvatar.Image = blank_img
Me.picAvatar.Refresh()
prev_personNameStr = ""
End If
End If
End Sub
''' <summary>
''' Show a bounding box. This function is presently not used
''' </summary>
Public Sub showBoundingBox()
Dim x, y, w, h, tx, ty As Integer
Dim col As System.Drawing.Color
'show the bounding box
w = bb_bx - bb_tx
h = bb_by - bb_ty
tx = (bb_tx * picCapture.Image.Width) / IMAGE_WIDTH
ty = (bb_ty * picCapture.Image.Height) / IMAGE_HEIGHT
w = (w * picCapture.Image.Width) / IMAGE_WIDTH
h = (h * picCapture.Image.Height) / IMAGE_HEIGHT
Try
gr = Graphics.FromImage(picCapture.Image)
'Dim gr As Graphics = Graphics.FromImage(picCapture.Image)
gr.DrawRectangle(New Pen(Color.Green, 2), tx, ty, w, h)
Catch ex As Exception
End Try
End Sub
''' <summary>
''' Image refresh routine
''' </summary>
Public Sub RefreshImage(ByVal Frame As System.Windows.Forms.PictureBox)
Try
If (DISPLAY_CAMERA_IMAGE) Then
Me.picCapture.Image = Nothing
Me.picCapture.Image = Frame.Image
End If
CaptureInformation.CounterFrames += 1
Call updateVision(Frame.Image)
If (DISPLAY_CAMERA_IMAGE) Then
Me.picCapture.Refresh()
End If
If (Not showPortrait) Then
If (Not showFaceImage) Then
If (Not showProcessedImage) Then
showAvatar(picAvatar)
Else
showImage(picAvatar, processedImageID)
End If
Else
showFace(picAvatar)
End If
Else
'show a portrait
show_Portrait()
End If
initialised = True
Catch ex As Exception
End Try
End Sub
#End Region
#Region "Identifying the person name or ID and logging to a text file"
''' <summary>
''' Log the observed person to a text file
''' </summary>
''' <param name="personID">An ID number greater than zero corresponding to the person</param>
Public Sub logFace(ByVal personID As Integer)
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
Dim allowWrite As Boolean = True
Dim textLine As String
Dim personName As String
'get the name of the person (20 characters long)
'this is done in a very crude way, just because I can't find a good way to
'pass byte arrays from a DLL to vb.net
personName = getPersonName()
Try
'open the file and append to it
oWrite = oFile.AppendText(System.Windows.Forms.Application.StartupPath & "\facelog.txt")
Catch
allowWrite = False
End Try
If (allowWrite) Then
'write the details
textLine = Format$(Now, "dd/mm/yyyy") & ", " & Format$(Now, "dddd") & ", " & Format$(Now, "hh:mm:ss") & ", " & personID & ", " & personName & ","
oWrite.WriteLine(textLine)
'close the file
oWrite.Close()
End If
End Sub
''' <summary>
''' Get the ID number for the currently observed persona and log the event to a text file if necessary
''' </summary>
Public Sub identifyPerson()
Dim filename As String
Static init_ID As Boolean
'get the ID number of the person
currentPersonID = RChbp_getPersonID()
If (currentPersonID > 0) Then
'log the identity if necessary
If (CamSettings.createLog) Then
If ((currentPersonID <> prevPersonID) Or (Not init_ID)) Then
init_ID = True
logFace(currentPersonID)
End If
End If
prevPersonID = currentPersonID
End If
End Sub
#Region " C骴igo generado por el Dise馻dor de Windows Forms "
Private Sub initCamera()
'Call to AddCam to select an available camera
Dim AddCamera As New AddCam
AddCamera.ShowDialog(Me)
CaptureInformation.CaptureInfo.PreviewWindow = Me.picEye
'Define RefreshImage as event handler of FrameCaptureComplete
AddHandler CaptureInformation.CaptureInfo.FrameCaptureComplete, AddressOf RefreshImage
CaptureInformation.Counter = 1
CaptureInformation.CounterFrames = 1
Me.Show()
'Initialization of ConfWindow
CaptureInformation.ConfWindow = New CW
CaptureInformation.ConfWindow.Refresh()
CaptureInformation.ConfWindow.Show()
End Sub
Public Sub New()
MyBase.New()
InitializeComponent()
'initialise the camera
initCamera()
If (CamSettings.createLog) Then
MenuItem10.Checked = True
Else
MenuItem10.Checked = False
End If
If (CamSettings.speakNames) Then
MenuItem12.Checked = True
Else
MenuItem12.Checked = False
End If
blank_img = Me.picAvatar.Image.Clone
'select the appropriate display mode
selectDisplaymode(CamSettings.DisplayMode)
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Dise馻dor de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Dise馻dor de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Dise馻dor de Windows Forms.
'No lo modifique con el editor de c骴igo.
Friend WithEvents timGrab As System.Windows.Forms.Timer
Friend WithEvents picOutput As System.Windows.Forms.PictureBox
Friend WithEvents picEye As System.Windows.Forms.PictureBox
Friend WithEvents picCapture As System.Windows.Forms.PictureBox
Friend WithEvents mnuMotionDetection As System.Windows.Forms.MenuItem
Friend WithEvents mnuMain As System.Windows.Forms.MainMenu
Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
Friend WithEvents lblName As System.Windows.Forms.Label
Friend WithEvents picAvatar As System.Windows.Forms.PictureBox
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(MainApp))
Me.timGrab = New System.Windows.Forms.Timer(Me.components)
Me.picOutput = New System.Windows.Forms.PictureBox
Me.picEye = New System.Windows.Forms.PictureBox
Me.picCapture = New System.Windows.Forms.PictureBox
Me.mnuMain = New System.Windows.Forms.MainMenu
Me.mnuMotionDetection = New System.Windows.Forms.MenuItem
Me.mnuExit = New System.Windows.Forms.MenuItem
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem10 = New System.Windows.Forms.MenuItem
Me.lblName = New System.Windows.Forms.Label
Me.picAvatar = New System.Windows.Forms.PictureBox
Me.MenuItem12 = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
'
'timGrab
'
Me.timGrab.Enabled = True
'
'picOutput
'
Me.picOutput.Location = New System.Drawing.Point(88, 256)
Me.picOutput.Name = "picOutput"
Me.picOutput.Size = New System.Drawing.Size(144, 116)
Me.picOutput.TabIndex = 5
Me.picOutput.TabStop = False
Me.picOutput.Visible = False
'
'picEye
'
Me.picEye.Location = New System.Drawing.Point(328, 0)
Me.picEye.Name = "picEye"
Me.picEye.Size = New System.Drawing.Size(320, 236)
Me.picEye.TabIndex = 6
Me.picEye.TabStop = False
Me.picEye.Visible = False
'
'picCapture
'
Me.picCapture.Location = New System.Drawing.Point(0, 0)
Me.picCapture.Name = "picCapture"
Me.picCapture.Size = New System.Drawing.Size(320, 240)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -