📄 classvisionobject.cls
字号:
Dim redImage As New classImageProcessing
Dim greenImage As New classImageProcessing
Dim blueImage As New classImageProcessing
Const minStep = 10
NoOfProbabilities = 0
maxProbability = 0
'grab the scene
Set testScene = Nothing
Set testScene = New classImageProcessing
Call testScene.init(width, height)
Call testScene.update(scene, topX, topY, width, height)
'grab a red image
Call redImage.init(width, height)
redImage.processType = 1
Call redImage.update(scene)
Call redImage.applyThreshold(140)
'grab a green image
Call greenImage.init(width, height)
greenImage.processType = 2
Call greenImage.update(scene)
Call greenImage.applyThreshold(140)
'grab a blue image
Call blueImage.init(width, height)
redImage.processType = 3
Call blueImage.update(scene)
Call blueImage.applyThreshold(180)
'subtract the blue image from the red to reveal possile locations of faces
'possible areas are then further scrutinized
For i = 0 To width - 1
For j = 0 To height - 1
p1 = redImage.getPoint(i, j)
p2 = blueImage.getPoint(i, j)
p2 = greenImage.getPoint(i, j)
dp = (p1 * 2) - (p2 + p3)
If (dp < 0) Or (p1 = 0) Or (p2 > 210) Then
Call testScene.setPoint(i, j, 0)
End If
Next
Next
'kill
Set redImage = Nothing
Set blueImage = Nothing
Set greenImage = Nothing
For stretch = 0.6 To 1 Step 0.1
iWidth = imageWidth + (imageTranslation * 2)
iHeight = imageHeight + (imageTranslation * 2)
subImageWidth = width * stretch
subImageHeight = height
While (subImageWidth > iWidth) And (subImageHeight > iHeight)
w = Int((width / subImageWidth) * iWidth)
h = Int((height / subImageHeight) * iHeight)
'grab the scene and store it in an array
For x = 0 To w - 1
xx = ((x / iWidth) * subImageWidth)
For y = 0 To h - 1
yy = ((y / iHeight) * subImageHeight)
vector(x, y) = testScene.getPoint(xx, yy) / 255#
Next
Next
For x = 0 To w - iWidth - 1 Step LocatorStepSize
For y = 0 To h - iHeight - 1 Step LocatorStepSize
xx = ((x * width) / w) + (subImageWidth / 2)
yy = ((y * height) / h) + (subImageHeight / 2)
p1 = testScene.getPoint(xx, yy)
If (p1 > 0) Then
'set the network inputs
k = 0
For i = 0 To imageWidth - 1
For j = 0 To imageHeight - 1
p1 = VisionObjectTemplate.getPoint(i, j) / 255
p2 = vector(x + i, y + j)
dp = Abs(p1 - p2)
Call NNet.setInput(k, dp)
k = k + 1
Next
Next
Call NNet.feedForward
'get the decision
If (NNet.getClassification = CLASSIFICATION_VisionObject) Then
'show the current seek window
'If (Not IsMissing(seekPicture)) Then
' Call showNNimage(seekPicture)
'End If
Confidence = NNet.ClassificationConfidence
'confidence must be above a minimum level
If (Confidence > 0.95) Then
If (Confidence > maxProbability) Then
maxProbability = Confidence
End If
'store potential VisionObject locations
If (NoOfProbabilities < 10000) Then
VisionObjectProbability(NoOfProbabilities, 0) = topX + ((x * width) / w)
VisionObjectProbability(NoOfProbabilities, 1) = topY + ((y * height) / h)
VisionObjectProbability(NoOfProbabilities, 2) = subImageWidth
VisionObjectProbability(NoOfProbabilities, 3) = subImageHeight
VisionObjectProbability(NoOfProbabilities, 4) = Confidence
NoOfProbabilities = NoOfProbabilities + 1
End If
End If
End If
End If
Next
Next
'decrease size of subimage window
subImageWidth = subImageWidth - Shrinkage
subImageHeight = subImageHeight - Shrinkage
If (subImageWidth < iWidth) And (subImageHeight > iHeight) Then
subImageWidth = iWidth
End If
If (subImageHeight < iHeight) And (subImageWidth > iWidth) Then
subImageHeight = iHeight
End If
Wend
Next
'calculate probability matrix
Call calcProbabilityMatrix
End Function
Public Sub IdentifySkinWithinPicture(scene As PictureBox, topX As Integer, topY As Integer, width As Integer, height As Integer, Optional seekPicture As PictureBox)
'scans a picture and calculates the probability of a VisionObject
'existing at any given location
Dim x As Integer
Dim y As Integer
Dim w As Integer
Dim h As Integer
Dim i As Integer
Dim subImageWidth As Integer
Dim subImageHeight As Integer
Dim similarity As Single
Dim skinFound As Boolean
Dim minWidth As Integer
Dim minHeight As Integer
'grab the scene
Set testScene = Nothing
Set testScene = New classImageProcessing
Call testScene.init(width, height)
Call testScene.update(scene, topX, topY, width, height)
minWidth = width / 10
minHeight = height / 10
subImageWidth = width / 4
subImageHeight = height / 4
maxProbability = 0
NoOfProbabilities = 0
While (subImageWidth > minWidth) And (subImageHeight > minHeight)
w = width - subImageWidth
h = height - subImageHeight
For x = 0 To w - 1 Step LocatorStepSize
For y = 0 To h - 1 Step LocatorStepSize
'compare this area with the skin tones database
skinFound = False
i = 0
While (Not skinFound) And (i < NoOfSkinColours)
similarity = skinColourTemplate(i).colourSimilarity(scene, topX + x, topY + y, subImageWidth, subImageHeight)
If (similarity > 0.9) Then
If (similarity > maxProbability) Then
maxProbability = similarity
End If
'store potential VisionObject locations
If (NoOfProbabilities < 10000) Then
VisionObjectProbability(NoOfProbabilities, 0) = topX + x
VisionObjectProbability(NoOfProbabilities, 1) = topY + y
VisionObjectProbability(NoOfProbabilities, 2) = subImageWidth
VisionObjectProbability(NoOfProbabilities, 3) = subImageHeight
VisionObjectProbability(NoOfProbabilities, 4) = similarity
NoOfProbabilities = NoOfProbabilities + 1
End If
skinFound = True
End If
i = i + 1
Wend
Next
Next
'decrease size of subimage window
subImageWidth = subImageWidth - 5 'LocatorStepSize
subImageHeight = subImageHeight - 5 'LocatorStepSize
Wend
End Sub
Public Function IdentifyWithinPictureLinear(scene As PictureBox, topX As Integer, topY As Integer, width As Integer, height As Integer, Shrinkage As Integer, Optional seekPicture As PictureBox) As String
'scans a picture and calculates the probability of a VisionObject
'existing at any given location
Dim x As Long
Dim y As Long
Dim subImageWidth As Long
Dim subImageHeight As Long
Dim w As Integer
Dim h As Integer
Dim i As Integer
Dim j As Integer
Dim vector(1000, 1000) As Single
Dim iWidth As Integer
Dim iHeight As Integer
Dim Confidence As Single
Dim xx As Integer
Dim yy As Integer
Dim p1 As Single
Dim p2 As Single
Dim dp As Single
Dim edist As Double
Dim stretch As Single
Const minStep = 10
NoOfProbabilities = 0
maxProbability = 0
'grab the scene
Set testScene = Nothing
Set testScene = New classImageProcessing
Call testScene.init(width, height)
Call testScene.update(scene, topX, topY, width, height)
For stretch = 0.8 To 1.2 Step 0.1
iWidth = imageWidth + (imageTranslation * 2)
iHeight = imageHeight + (imageTranslation * 2)
subImageWidth = width * stretch
subImageHeight = height
While (subImageWidth > iWidth) And (subImageHeight > iHeight)
w = Int((width / subImageWidth) * iWidth)
h = Int((height / subImageHeight) * iHeight)
'grab the scene and store it in an array
For x = 0 To w - 1
xx = ((x / iWidth) * subImageWidth)
For y = 0 To h - 1
yy = ((y / iHeight) * subImageHeight)
vector(x, y) = testScene.getPoint(xx, yy) / 255#
Next
Next
For x = 0 To w - iWidth - 1 Step LocatorStepSize
For y = 0 To h - iHeight - 1 Step LocatorStepSize
edist = 0
For i = 0 To imageWidth - 1
For j = 0 To imageHeight - 1
p1 = VisionObjectTemplate.getPoint(i, j) / 255
p2 = vector(x + i, y + j)
dp = Abs(p1 - p2)
edist = edist + dp
Next
Next
edist = edist / (imageWidth * imageHeight)
'get the decision
If (edist < 0.2) Then
'show the current seek window
'If (Not IsMissing(seekPicture)) Then
' Call showNNimage(seekPicture)
'End If
Confidence = 1 - edist
If (Confidence > maxProbability) Then
maxProbability = Confidence
End If
'store potential VisionObject locations
If (NoOfProbabilities < 10000) Then
VisionObjectProbability(NoOfProbabilities, 0) = topX + ((x * width) / w)
VisionObjectProbability(NoOfProbabilities, 1) = topY + ((y * height) / h)
VisionObjectProbability(NoOfProbabilities, 2) = subImageWidth
VisionObjectProbability(NoOfProbabilities, 3) = subImageHeight
VisionObjectProbability(NoOfProbabilities, 4) = Confidence
NoOfProbabilities = NoOfProbabilities + 1
End If
End If
Next
Next
'decrease size of subimage window
subImageWidth = subImageWidth - Shrinkage
subImageHeight = subImageHeight - Shrinkage
Wend
Next
End Function
Public Sub showProbabilityMatrix(canvas As PictureBox)
Call ProbabilityMatrix.show(canvas)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -