📄 mainapp.vb
字号:
face_w = face_bx - face_tx
face_h = face_by - face_ty
If (DETECTION_MODE = DETECTIONMODE_BODY) Then
If (face_w > 2) Then
origin_x = ((face_tx + (face_w / 2)) * 100) / (IMAGE_WIDTH / reductionFactor_x)
origin_y = (face_by * 100) / (IMAGE_HEIGHT / reductionFactor_y)
End If
End If
If (DETECTION_MODE = DETECTIONMODE_FACES) Then
origin_x = 50
origin_y = 50
bodyWidth = IMAGE_WIDTH / 5
End If
If (bodyWidth > 0) And (face_w > 2) Then
'clear the picturebox image
If (DETECTION_MODE = DETECTIONMODE_FACES) Then
pic.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
Else
pic.BackColor = ColorTranslator.FromWin32(RGB(backgroundColour_red, backgroundColour_green, backgroundColour_blue))
End If
gr.Clear(pic.BackColor)
scaleBody = 0.5 + ((bodyWidth / CSng(IMAGE_WIDTH / reductionFactor_x)) * 2)
scaleBody = scaleBody * 0.3 / scale_x
scaleBody = (prev_scalebody * 0.6) + (scaleBody * 0.4)
centre_x = CInt((prev_centre_x * 0.6) + (((pic.Width * origin_x * (0.3 / scale_x)) / 100.0#) * 0.4))
shoulderWidth = CInt(((pic.Width / 2) / 5) * scaleBody)
upperArmLength = CInt(((pic.Width / 2) / 2) * scaleBody)
lowerArmLength = CInt((upperArmLength * 2 / 3) * scaleBody)
neck_y = CInt((prev_neck_y * 0.6) + (((pic.Height * origin_y * (0.3 / scale_y)) / 80.0#) * 0.4))
bodyHeight = CInt((pic.Height * scaleBody) / 3)
prev_centre_x = centre_x
prev_neck_y = neck_y
prev_scalebody = scaleBody
If (DETECTION_MODE = DETECTIONMODE_BODY) Then
leftShoulderAngle = (2 * 3.1415927) - ((3.1415927 * 1 / 8) + ((100 - leftShoulderElevation) * 3.1415927 / 260))
leftelbow_x = centre_x + (upperArmLength * Math.Sin(leftShoulderAngle))
leftelbow_y = neck_y + (upperArmLength * Math.Cos(leftShoulderAngle))
leftWristAngle = leftShoulderAngle - (leftElbowElevation * 3.1415927 / 100) + (3.1415927 / 8)
leftwrist_x = leftelbow_x + (lowerArmLength * Math.Sin(leftWristAngle))
leftwrist_y = leftelbow_y + (lowerArmLength * Math.Cos(leftWristAngle))
rightShoulderAngle = ((3.1415927 * 1 / 8) + ((100 - rightShoulderElevation) * 3.1415927 / 260))
rightelbow_x = centre_x + (upperArmLength * Math.Sin(rightShoulderAngle))
rightelbow_y = neck_y + (upperArmLength * Math.Cos(rightShoulderAngle))
rightWristAngle = rightShoulderAngle + (rightElbowElevation * 3.1415927 / 100) - (3.1415927 / 8)
rightwrist_x = rightelbow_x + (lowerArmLength * Math.Sin(rightWristAngle))
rightwrist_y = rightelbow_y + (lowerArmLength * Math.Cos(rightWristAngle))
End If
'legs
PenWidth = (40 * scaleBody * drawScale * scale_x)
PenColour = ColorTranslator.FromWin32(bottom_colour)
gr.DrawLine(New Pen(PenColour, PenWidth), centre_x, neck_y + bodyHeight, centre_x, pic.Height)
'body
PenWidth = (40 * scaleBody * drawScale * scale_x)
PenColour = ColorTranslator.FromWin32(top_colour)
gr.DrawLine(New Pen(PenColour, PenWidth), centre_x, CInt(neck_y - ((bodyHeight / 20) * scale_y)), centre_x, neck_y + bodyHeight)
'head
headPenWidth = (30 * scaleBody * drawScale * scale_x)
PenColour = ColorTranslator.FromWin32(skin_colour)
w = headPenWidth * 1.5
h = headPenWidth * 1.5
tx = CInt(centre_x - (w / 2))
by = CInt(neck_y - (bodyHeight / 2))
ty = CInt(neck_y - (bodyHeight / 1.2))
cy = ty + ((by - ty) / 2)
gr.FillEllipse(New SolidBrush(PenColour), tx, ty, w, h)
'eyes
PenWidth = (4 * scaleBody * drawScale * scale_x)
w = PenWidth * 1.5
h = PenWidth * 1.5
PenColour = Color.Black
If (Not invalidFace) Then
gazeShift = CInt((prev_gazeShift * 0.6) + ((gazeDirection * scaleBody / 4 * scale_x * 0.8) * 0.4))
tiltshift = CInt((prev_tiltShift * 0.6) + ((headTilt * scaleBody * scale_y * 0.1) * 0.4))
prev_gazeShift = gazeShift
prev_tiltShift = tiltshift
eyebrow_vert = eyebrowsVertical
gazeDir = gazeDirection
mouth_open = MouthOpen
End If
tx = CInt(centre_x - (bodyHeight / 7) + gazeShift)
ty = CInt(neck_y - (bodyHeight / 2.0) + tiltshift)
x = CInt(tx - (w / 2))
y = CInt(ty - (h / 2))
If (eyebrow_vert < 10) Then eyebrow_vert = 10
drawEye(x, y, w * 1.5, gazeDir / 3, 0, (100 - eyebrow_vert) / 1.5)
yy = CInt(y - (scaleBody * drawScale * scale_y * (1 + (eyebrow_vert * 0.08))))
If (yy > y - (h / 20)) Then yy = y - (h / 20)
eb1 = (eyebrow_vert * 0.3)
eb2 = ((100 - eyebrow_vert) * 0.4)
drawEyebrow(x, yy, w * 2 * ((gazeDir / 2) + 5) / 80, eb1, eb2, True)
tx = CInt(centre_x + (bodyHeight / 7) + gazeShift)
ty = CInt(neck_y - (bodyHeight / 2.0) - tiltshift)
x = CInt(tx - (w / 2))
y = CInt(ty - (h / 2))
drawEye(x, y, w * 1.5, gazeDir / 3, 0, (100 - eyebrow_vert) / 1.5)
yy = CInt(y - (scaleBody * drawScale * scale_y * (1 + (eyebrow_vert * 0.08))))
If (yy > y - (h / 20)) Then yy = y - (h / 20)
eb1 = (eyebrow_vert * 0.3)
eb2 = ((100 - eyebrow_vert) * 0.4)
drawEyebrow(x, yy, w * 2 * (55 - (gazeDir / 2)) / 80, eb1, eb2, False)
'nose
PenWidth = (5 * scaleBody * drawScale)
PenColour = Color.Pink
tx = CInt(centre_x + (gazeShift * 1.2))
ty = CInt(neck_y - (bodyHeight / 2.6))
w = PenWidth / 2
h = PenWidth / 2
gr.FillEllipse(New SolidBrush(PenColour), CInt(tx - (w / 2)), CInt(ty - (h / 2)), w, h)
PenColour = ColorTranslator.FromWin32(skin_colour)
tx = CInt(centre_x + (gazeShift * 1.2))
ty = CInt(neck_y - (bodyHeight / 2.3))
gr.FillEllipse(New SolidBrush(PenColour), CInt(tx - (w / 2)), CInt(ty - (h / 2)), w, h)
'mouth
tx = CInt(centre_x + (gazeShift * 0.7) - (((bodyHeight / 10) * mouthWidth) / 100))
ty = CInt(neck_y - (bodyHeight / 4.5))
drawMouth(tx, ty, CInt((bodyHeight / 1) * mouthWidth / 100), mouth_open, 30)
'arms
PenWidth = (14 * scaleBody * drawScale * scale_x)
PenColour = ColorTranslator.FromWin32(top_colour)
gr.DrawLine(New Pen(PenColour, PenWidth), leftelbow_x, leftelbow_y, CInt(centre_x - shoulderWidth), neck_y)
gr.DrawLine(New Pen(PenColour, PenWidth), leftwrist_x, leftwrist_y, leftelbow_x, leftelbow_y)
gr.DrawLine(New Pen(PenColour, PenWidth), CInt(centre_x + shoulderWidth), neck_y, rightelbow_x, rightelbow_y)
gr.DrawLine(New Pen(PenColour, PenWidth), rightelbow_x, rightelbow_y, rightwrist_x, rightwrist_y)
'hands
handMultiplier = (100 + ((leftHandSize - (((face_w / 2) * 100) / IMAGE_WIDTH)) * 1)) / 100
If (handMultiplier < 1) Then handMultiplier = 1
PenWidth = (10 * scaleBody * drawScale * handMultiplier * scale_x)
PenColour = ColorTranslator.FromWin32(skin_colour)
w = headPenWidth / 1.6
h = headPenWidth / 1.6
gr.FillEllipse(New SolidBrush(PenColour), CInt(leftwrist_x - (w / 2)), CInt(leftwrist_y - (h / 2)), w, h)
handMultiplier = (100 + ((rightHandSize - (((face_w / 2) * 100) / IMAGE_WIDTH)) * 1)) / 100
If (handMultiplier < 1) Then handMultiplier = 1
PenWidth = (10 * scaleBody * drawScale * handMultiplier * scale_x)
w = headPenWidth / 1.6
h = headPenWidth / 1.6
gr.FillEllipse(New SolidBrush(PenColour), CInt(rightwrist_x - (w / 2)), CInt(rightwrist_y - (h / 2)), w, h)
pic.Refresh()
End If
Catch
End Try
End Sub
#End Region
#Region "Main update function"
''' <summary>
''' Processes the given image
''' </summary>
''' <param name="input_img">The image to be processed</param>
Public Sub updateVision(ByRef input_img As Image)
Dim p, x, y, tx, ty, bx, by, w, h As Integer
Dim col As System.Drawing.Color
updating_image = True
If (Not image_initialised) Then
image_initialised = True
Call RChbp_enableLearning(True)
Call RChbp_setDetectionMode(DETECTION_MODE)
End If
bmp = Nothing
bmp = input_img 'picCapture.Image
'define a subsampled small image
bmp_small = Nothing
bmp_small = New Bitmap(bmp.GetThumbnailImage(IMAGE_WIDTH, IMAGE_HEIGHT, AddressOf ThumbNailAbort, Nothing))
'transfer data from the small image into the DLL
'This is very cumbersome, but at present I can't find any easy way to pass an array of bytes
For y = 0 To IMAGE_HEIGHT - 1
For x = 0 To IMAGE_WIDTH - 1
col = bmp_small.GetPixel(x, y)
RChbp_updateImage(x, y, CInt(IMAGE_WIDTH), CInt(IMAGE_HEIGHT), col.R, col.G, col.B)
Next
Next
updating_image = False
picOutput.Image = Nothing
picOutput.Image = bmp_small
'update routine within the DLL
RChbp_update2(0, CInt(IMAGE_WIDTH), CInt(IMAGE_HEIGHT))
'identify the person
identifyPerson()
End Sub
#End Region
#Region "Functions for displaying stuff on the screen"
''' <summary>
''' Show an image of the face region detected using the openCV system
''' </summary>
''' <param name="pic">picture box control in which to draw the face</param>
Public Sub showFace(ByVal pic As PictureBox)
Dim PenColour As System.Drawing.Color
Dim rect As System.Drawing.Rectangle
Dim r, g, b As Byte
Dim x, y As Integer
For y = 0 To FACE_IMAGE_SIZE - 1
For x = 0 To FACE_IMAGE_SIZE - 1
RChbp_getFaceImagePixel(x, y, r, g, b)
PenColour = ColorTranslator.FromWin32(RGB(r, g, b))
rect.X = pic.Width / FACE_IMAGE_SIZE * x / 2
rect.Y = pic.Height / FACE_IMAGE_SIZE * y / 2
rect.Width = pic.Width / FACE_IMAGE_SIZE
rect.Height = pic.Height / FACE_IMAGE_SIZE
gr.FillRectangle(New SolidBrush(PenColour), rect)
Next
Next
pic.Refresh()
End Sub
''' <summary>
''' Show an image within the given picture box control
''' </summary>
''' <param name="pic">picture box control in which to draw the face</param>
''' <param name="imageIndex">An index number corresponding to the type of image to be displayed</param>
Public Sub showImage(ByVal pic As PictureBox, ByVal imageIndex As Integer)
Dim PenColour As System.Drawing.Color
Dim rect As System.Drawing.Rectangle
Dim r, g, b As Byte
Dim x, y As Integer
For y = 0 To SMALL_IMAGE_SIZE - 1
For x = 0 To SMALL_IMAGE_SIZE - 1
RChbp_getImagePixel(imageIndex, x, y, r, g, b)
PenColour = ColorTranslator.FromWin32(RGB(r, g, b))
rect.X = pic.Width / SMALL_IMAGE_SIZE * x / 2
rect.Y = pic.Height / SMALL_IMAGE_SIZE * y / 2
rect.Width = pic.Width / SMALL_IMAGE_SIZE
rect.Height = pic.Height / SMALL_IMAGE_SIZE
gr.FillRectangle(New SolidBrush(PenColour), rect)
Next
Next
pic.Refresh()
End Sub
''' <summary>
''' Select a display mode from the menu
''' </summary>
''' <param name="index">An index number corresponding to the type of image to be displayed</param>
Public Sub selectDisplaymode(ByVal index As Integer)
MenuItem2.Checked = False
MenuItem3.Checked = False
MenuItem4.Checked = False
MenuItem5.Checked = False
MenuItem6.Checked = False
MenuItem7.Checked = False
MenuItem8.Checked = False
MenuItem11.Checked = False
gr = Graphics.FromImage(picAvatar.Image)
Select Case index
Case 0
MenuItem2.Checked = True
DETECTION_MODE = DETECTIONMODE_BODY
showFaceImage = False
showProcessedImage = False
showPortrait = False
'Me.picAvatar.Image = blank_img
CamSettings.DisplayMode = 0
Case 1
MenuItem3.Checked = True
DETECTION_MODE = DETECTIONMODE_FACES
showFaceImage = False
showProcessedImage = False
showPortrait = False
'Me.picAvatar.Image = blank_img
CamSettings.DisplayMode = 1
Case 2
MenuItem4.Checked = True
DETECTION_MODE = DETECTIONMODE_FACES
showFaceImage = True
showProcessedImage = False
showPortrait = False
'Me.picAvatar.Image = blank_img
picAvatar.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
gr.Clear(picAvatar.BackColor)
CamSettings.DisplayMode = 2
Case 3
MenuItem5.Checked = True
showFaceImage = False
showProcessedImage = True
showPortrait = False
processedImageID = 0
'Me.picAvatar.Image = blank_img
picAvatar.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
gr.Clear(picAvatar.BackColor)
CamSettings.DisplayMode = 3
Case 4
MenuItem6.Checked = True
showFaceImage = False
showProcessedImage = True
showPortrait = False
processedImageID = 2
CamSettings.DisplayMode = processedImageID
'Me.picAvatar.Image = blank_img
picAvatar.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
gr.Clear(picAvatar.BackColor)
CamSettings.DisplayMode = 4
Case 5
MenuItem7.Checked = True
showFaceImage = False
showProcessedImage = True
showPortrait = False
processedImageID = 5
'Me.picAvatar.Image = blank_img
picAvatar.BackColor = ColorTranslator.FromWin32(RGB(255, 255, 255))
gr.Clear(picAvatar.BackColor)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -