[原创]采用3线法和像素判别法来识别验证码
采用3线法和像素判别法来识别数字验证码地址http://passport.
所谓3线法(不知道以前有没有这样做,这个是我偶然想到的)就是竖线1条,横线两条,判断于图像的交点,用交点个数来做数字的代号,代号如有相同,则采用像素判别(比较大小)来区分
当然该方法有很大潜力改进,我今天无意间想到,就写出来供大家研究
Private check(1 To 3) As Integer
Private num(0 To 5) As Integer
Private Sub Command1_Click()
Dim i As Integer
Dim x, y, a, b, m, n As Integer
Dim blue As Integer
Dim clr, p As Long
Dim dis1, dis2, temp, clm As Integer
For i = 0 To 5
Select Case i ‘6个数字分别分段识别
Case 0
dis1 = 0
dis2 = 230
clm = 150
Case Else
temp = dis2
dis2 = dis2 + 180
dis1 = temp
clm = clm + 180
End Select
a = 0
For y = 0 To 450 ’画竖线得交点
clr = Picture1.Point(clm, y)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then
If b = 0 Then
a = a + 1
b = 1
End If
Else
b = 0
End If
Next y
check(1) = a
a = 0
For x = dis1 To dis2 ‘范围画2横向线,得交点
clr = Picture1.Point(x, 170)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then
If b = 0 Then
a = a + 1
b = 1
End If
Else
b = 0
End If
Next x
check(2) = a
a = 0
For x = dis1 To dis2
clr = Picture1.Point(x, 240)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then
If b = 0 Then
a = a + 1
b = 1
End If
Else
b = 0
End If
Next x
check(3) = a
If check(1) = 4 And check(2) = 2 And check(3) = 2 Then ’用check做交点编码,找相应的数字,如果编码相同则判断蓝色像素的多少来区分
p = 0
For m = dis1 To dis2 Step 4
For n = 0 To 450 Step 4
clr = Picture1.Point(m, n)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then p = p + 1
Next n
Next m
If p < 1300 Then
num(i) = 0
Else
num(i) = 8
End If
End If
If check(1) = 4 And check(2) = 1 And check(3) = 1 Then
p = 0
For m = dis1 To dis2 Step 4
For n = 0 To 450 Step 4
clr = Picture1.Point(m, n)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then p = p + 1
Next n
Next m
If p < 1010 Then
num(i) = 2
Else
num(i) = 3
End If
End If
If check(1) = 3 And check(2) = 1 And check(3) = 1 Then
p = 0
For m = dis1 To dis2 Step 4
For n = 0 To 450 Step 4
clr = Picture1.Point(m, n)
blue = (clr \ &H10000) Mod &H100
If blue < 254 Then p = p + 1
Next n
Next m
If p < 950 Then
num(i) = 7
Else
num(i) = 4
End If
End If
If check(1) = 2 And check(2) = 1 And check(3) = 1 Then num(i) = 1
If check(1) = 5 And check(2) = 1 And check(3) = 1 Then num(i) = 5
If check(1) = 5 And check(2) = 1 And check(3) = 2 Then num(i) = 6
If check(1) = 4 And check(2) = 2 And check(3) = 1 Then num(i) = 9
Next i
MsgBox num(0) & num(1) & num(2) & num(3) & num(4) & num(5)
End Sub
Private Sub Timer1_Timer() ‘更新图片
Picture1.Picture = LoadPicture(".\验证图片\验证码" & Text1.Text & ".gif ")
End Sub
[[it] 本帖最后由 我是菜鸟哦 于 2008-10-13 20:41 编辑 [/it]]
验证码识别.rar
(22.79 KB)