哼,VB的速度也是很牛逼的,VB很萌的,乃们不要再黑VB了
dd2010/07/17软件综合 IP:广东
今天特别高兴特别蛋疼,于是把mean shift花了2小时移植到VB上[我知道大部分时间我都在debug]

Mean Shift 算法 在XXXXXT上跑,320 x 240,跟踪窗口30 x 30,CPU T6570,内存2G,Win7

实时跟踪绰绰有余

ms1.png

虽然在下一秒……

ms3.png
+500  科创币    小俊    2010/07/17 优秀
来自:计算机科学 / 软件综合
53
已屏蔽 原因:{{ notice.reason }}已屏蔽
{{notice.noticeContent}}
~~空空如也
dd 作者
14年6个月前 IP:未同步
237039
放出代码

Public Class MeanShift

    Const HISTOGRAM_LENGTH As Integer = 4096

    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 = XXXXXXXx(0, currentY - trackWinHeight / 2) To Math.Min(currentY + trackWinHeight / 2, imgHeight - 1)
            For i As Integer = XXXXXXXx(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

            Next
        Next

        For i As Integer = 0 To HISTOGRAM_LENGTH
            histogram(i) /= pxValue
        Next

        Return pxValue

    End Function

    Public Function MeanShiftProcessSp(ByVal frame() As Byte)

        Dim weights(HISTOGRAM_LENGTH) As Double

        Dim newX As Double = 0.0
        Dim newY As Double = 0.0

        For i As Integer = 0 To HISTOGRAM_LENGTH

            If currentHistogram(i) > 0.0 Then
                weights(i) = tempHistogram(i) / currentHistogram(i)

            Else
                weights(i) = 0
            End If

        Next

        Dim sumOfWeights As Double = 0.0

        For j As Long = XXXXXXXx(0, currentY - trackWinHeight / 2) To Math.Min(currentY + trackWinHeight / 2, imgHeight - 1)
            For i As Integer = XXXXXXXx(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

                Dim ptr As Integer = 256 * r + 16 * g + b

                newX += weights(ptr) * i
                newY += weights(ptr) * j

                sumOfWeights += weights(ptr)

            Next
        Next


        If sumOfWeights <> 0 Then

            currentX = Int(newX / sumOfWeights) + 0.5
            currentY = Int(newY / sumOfWeights) + 0.5

        End If

        Return Nothing
    End Function

    Public Function MeanShiftTrackProcess(ByVal frame() As Byte, ByVal frameNumber As Integer)

        If frameNumber = 0 Then
            XXXXXlcHistogramSp(frame, tempHistogram)
        Else

            Dim stopThreshold As Integer = 10
            Dim counter As Integer = 0

            While counter < stopThreshold
                XXXXXlcHistogramSp(frame, currentHistogram)
                Me.MeanShiftProcessSp(frame)
                counter += 1
            End While

            Me.DrawTrackBox(frame)

        End If

        Return Nothing
    End Function

    Public Sub DrawTrackBox(ByVal frame() As Byte)


        For i As Integer = currentX To Math.Min(imgWidth, currentX + trackWinWidth)

            frame(currentY * imgWidth * 3 + i * 3 + 0) = 0
            frame(currentY * imgWidth * 3 + i * 3 + 1) = 0
            frame(currentY * imgWidth * 3 + i * 3 + 2) = 255

            frame(Math.Min(imgHeight - 1, currentY + trackWinHeight) * imgWidth * 3 + i * 3 + 0) = 0
            frame(Math.Min(imgHeight - 1, currentY + trackWinHeight) * imgWidth * 3 + i * 3 + 1) = 0
            frame(Math.Min(imgHeight - 1, currentY + trackWinHeight) * imgWidth * 3 + i * 3 + 2) = 255
        Next

        For j As Integer = currentY To Math.Min(imgHeight - 1, currentY + trackWinHeight)

            frame(j * imgWidth * 3 + currentX * 3 + 0) = 0
            frame(j * imgWidth * 3 + currentX * 3 + 1) = 0
            frame(j * imgWidth * 3 + currentX * 3 + 2) = 255

            frame(j * imgWidth * 3 + Math.Min(imgWidth - 1, currentX + trackWinWidth) * 3 + 0) = 0
            frame(j * imgWidth * 3 + Math.Min(imgWidth - 1, currentX + trackWinWidth) * 3 + 1) = 0
            frame(j * imgWidth * 3 + Math.Min(imgWidth - 1, currentX + trackWinWidth) * 3 + 2) = 255
        Next
    End Sub

End Class
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
dd作者
14年6个月前 IP:未同步
237049
引用第2楼ltl于2010-07-17 22:13发表的  :
VB就是渣!!!


欢迎来晒下限

嘛  反正mean shift算法我cpp  Delphi  vb三个版本都写过了,我有姿势我自嚎
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
dd作者
14年6个月前 IP:未同步
237125
那啥,我就是93

还有那啥,php天空中国 貌似乃上次折腾个取色都
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
dd作者
13年4个月前 IP:未同步
323424
谁能帮我把这贴删掉。。。 = -
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
dd作者
13年4个月前 IP:未同步
323461
各位少侠请放过我吧。。。。我已经金盆洗手不干了 。。。我再也不敢了 Orz 我错了我不会写程序我是2B
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
上级专业
同级专业
dd
学者 笔友
文章
44
回复
347
学术分
1
2006/10/31注册,6年11个月前活动
暂无简介
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
支持的图片格式:jpg, jpeg, png
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}