| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 817 人关注过本帖
标题:请帮我解释下这段VB代码
取消只看楼主 加入收藏
lanhaihe99
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-3-17
收藏
 问题点数:0 回复次数:1 
请帮我解释下这段VB代码
这是一段关于图象匹配的代码.就是有pic1 pic2 两个图象框.Command后看两个图象 匹配的情况.代码如下:


Private Sub Command2_Click()
Dim K As Integer, L As Integer, a As Integer, B As Integer, i As Integer, j As Integer
Dim c, Cmax As Single
Dim Xm As Integer, Ym As Integer
Dim Xn As Integer, Yn As Integer
Screen.MousePointer = 11
'MainForm.Picq2.Cls: MainForm.Pich2.Cls

Me.Picture1.Cls: Me.Picture2.Cls
L = 1
a = 100: B = 100

For i = 50 To Me.Picture2.ScaleWidth - 51 Step 2
For j = 50 To Me.Picture2.ScaleHeight - 51 Step 2
c = MCrn(a, B, i, j)
If i = 50 And j = 50 Then
Cmax = c: Xm = i: Ym = j
ElseIf Cmax < c Then Cmax = c: Xm = i: Ym = j
End If
Next
Next i
'计算出匹配点位置 (Xm,Ym) 误差为正负2像素

For i = Xm - 1 To Xm + 1
For j = Ym - 1 To Ym + 1
c = MCrn(a, B, i, j)
If i = Xm - 1 And j = Ym - 1 Then
Cmax = c: Xn = i: Yn = j
ElseIf Cmax < c Then
Cmax = c: Xn = i: Yn = j
End If
Next j
Next i

' (Xn,Yn) 为整像素位置



Screen.MousePointer = 0



Me.Picture1.Circle (a, B), 2, vbRed
Me.Picture2.Circle (Xn, Yn), 2, vbRed
' Label1.Caption = Xm & ", " & Ym
End Sub

我看不太明白.高手解释下,特别是c = MCrn(a, B, i, j)和Cmax = c: Xm = i: Ym = j两行.
搜索更多相关主题的帖子: Integer Dim 代码 图象 MainForm 
2008-05-04 09:45
lanhaihe99
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-3-17
收藏
得分:0 
找到MCrn 了
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
'相关系数函数
Public Function MCrn(ByVal ix As Integer, ByVal iy As Integer, ByVal gx As Integer, ByVal gy As Integer) As Single
Dim norma, normb, c As Double
Dim m, n As Integer: Dim gray1, gray2 As Double
norma = 0: normb = 0: c = 0
For m = -5 To 5 Step 1
    For n = -5 To 5 Step 1
       'gray1 = GetPixel(Form1.Picture1.hdc, ix + m, iy + n) And &HFF
       'gray2 = GetPixel(Form1.Picture2.hdc, gx + m, gy + n) And &HFF
       ''计算范围
       gray1 = Form1.Picture1.Point(ix + m, iy + n) And &HFF
       gray2 = Form1.Picture2.Point(gx + m, gy + n) And &HFF
       norma = norma + gray1 * gray1
       normb = normb + gray2 * gray2
       c = c + gray1 * gray2
    Next n
Next m
norma = Sqr(norma): normb = Sqr(normb)
MCrn = c / (norma * normb)
End Function
大家帮我看下什么意思
2008-05-04 10:08
快速回复:请帮我解释下这段VB代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020387 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved