level 6
93°
楼主
Public Class MeanShift
Const HISTOGRAM_LENGTH As Integer = 6000
Private imgWidth As Integer
Private imgHeight As Integer
Private trackWinWidth As Integer
Private trackWinHeight As Integer
Private currentX As Integer
Private currentY As Integer
Private currentHistogram(HISTOGRAM_LENGTH) As Double
Private tempHistogram(HISTOGRAM_LENGTH) As Double
' ---------------------------------------------------
Public Sub InitMeanShiftTracker(ByVal firstFrame() As Byte, ByVal frameWidth As Integer, ByVal frameHeight As Integer, _
ByVal targetPosX As Integer, ByVal targetPosY As Integer, ByVal targetWidth As Integer, ByVal targetHeight As Integer)
imgWidth = frameWidth
imgHeight = frameHeight
currentX = targetPosX
currentY = targetPosY
trackWinHeight = targetHeight
trackWinWidth = targetWidth
End Sub
Public Function CalcHistogramSp(ByVal frame() As Byte, ByVal histogram() As Double) As Integer
Dim pxValue As Integer = 0
For i As Integer = 0 To HISTOGRAM_LENGTH
histogram(i) = 0
Next
For j As Long = Math.Max(0, currentY - trackWinHeight / 2) To Math.Min(currentY + trackWinHeight / 2, imgHeight - 1)
For i As Integer = Math.Max(0, currentX - trackWinWidth / 2) To Math.Min(currentX + trackWinWidth / 2, imgWidth - 1)
Dim r As Integer = frame(j * imgWidth * 3 + i * 3) / 16
Dim g As Integer = frame(j * imgWidth * 3 + i * 3 + 1) / 16
Dim b As Integer = frame(j * imgWidth * 3 + i * 3 + 2) / 16
histogram(Int(256 * r + 16 * g + b)) += 1
pxValue += 1
2010年07月18日 03点07分
1
Const HISTOGRAM_LENGTH As Integer = 6000
Private imgWidth As Integer
Private imgHeight As Integer
Private trackWinWidth As Integer
Private trackWinHeight As Integer
Private currentX As Integer
Private currentY As Integer
Private currentHistogram(HISTOGRAM_LENGTH) As Double
Private tempHistogram(HISTOGRAM_LENGTH) As Double
' ---------------------------------------------------
Public Sub InitMeanShiftTracker(ByVal firstFrame() As Byte, ByVal frameWidth As Integer, ByVal frameHeight As Integer, _
ByVal targetPosX As Integer, ByVal targetPosY As Integer, ByVal targetWidth As Integer, ByVal targetHeight As Integer)
imgWidth = frameWidth
imgHeight = frameHeight
currentX = targetPosX
currentY = targetPosY
trackWinHeight = targetHeight
trackWinWidth = targetWidth
End Sub
Public Function CalcHistogramSp(ByVal frame() As Byte, ByVal histogram() As Double) As Integer
Dim pxValue As Integer = 0
For i As Integer = 0 To HISTOGRAM_LENGTH
histogram(i) = 0
Next
For j As Long = Math.Max(0, currentY - trackWinHeight / 2) To Math.Min(currentY + trackWinHeight / 2, imgHeight - 1)
For i As Integer = Math.Max(0, currentX - trackWinWidth / 2) To Math.Min(currentX + trackWinWidth / 2, imgWidth - 1)
Dim r As Integer = frame(j * imgWidth * 3 + i * 3) / 16
Dim g As Integer = frame(j * imgWidth * 3 + i * 3 + 1) / 16
Dim b As Integer = frame(j * imgWidth * 3 + i * 3 + 2) / 16
histogram(Int(256 * r + 16 * g + b)) += 1
pxValue += 1
