
如何用VB去識別這個圖片中的數字?
uj5u.com熱心網友回復:
這問題就很難么?大神們,誰幫幫忙uj5u.com熱心網友回復:
用point陳述句。你需要采樣8個點,你可以算出坐標以及每個字符的寬度,分別是8段管的8條線。判斷它們有沒有。
然后再判斷是數字幾。
uj5u.com熱心網友回復:
僅供參考:VERSION 5.00
Begin VB.Form Form1
Caption = "numeye by [email protected]"
ClientHeight = 1395
ClientLeft = 60
ClientTop = 345
ClientWidth = 2055
LinkTopic = "Form1"
ScaleHeight = 93
ScaleMode = 3 'Pixel
ScaleWidth = 137
StartUpPosition = 3 '視窗預設
Visible = 0 'False
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 480
Top = 840
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
AutoRedraw = -1 'True
AutoSize = -1 'True
BackColor = &H80000005&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 375
Left = 120
ScaleHeight = 25
ScaleMode = 3 'Pixel
ScaleWidth = 81
TabIndex = 0
Top = 120
Width = 1215
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Left = 120
TabIndex = 1
Top = 840
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim FPFN As String 'FullPathFileName
Dim i As Integer
Dim t As Integer
Dim n As Integer
Dim x As Integer
Dim x1 As Integer
Dim y As Integer
Dim w As Integer
Dim h As Integer
Dim b As Long
Dim a As Boolean
Dim nm(9) As String
Dim s As String
Dim r As String
Private Sub Form_Load()
FPFN = Command$
If Left(FPFN, 1) = Chr(34) Then FPFN = Mid(FPFN, 2)
If Right(FPFN, 1) = Chr(34) Then FPFN = Left(FPFN, Len(FPFN) - 1)
If Not FileExists(FPFN) Then
logtofile "[" + FPFN + "] file not find!"
End 'form
End If
nm(0) = _
"--OOO---" + _
"-OO-OO--" + _
"-O---O--" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"OO---OO-" + _
"-O---O--" + _
"-OO-OO--" + _
"--OOO---"
nm(1) = _
"--OO----" + _
"OOOO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"--OO----" + _
"OOOOOO--"
nm(2) = _
"--OOOO--" + _
"-O--OOO-" + _
"O----OO-" + _
"-----OO-" + _
"-----OO-" + _
"-----O--" + _
"----OO--" + _
"----O---" + _
"---O----" + _
"--O----O" + _
"-OOOOOOO" + _
"OOOOOOO-"
nm(3) = _
"--OOOO--" + _
"-O--OOO-" + _
"O----OO-" + _
"-----OO-" + _
"----OO--" + _
"---OOO--" + _
"----OOO-" + _
"-----OO-" + _
"-----OO-" + _
"-----OO-" + _
"OO--OO--" + _
"OOOOO---"
nm(4) = _
"-----OO-" + _
"-----OO-" + _
"----OOO-" + _
"---O-OO-" + _
"--O--OO-" + _
"--O--OO-" + _
"-O---OO-" + _
"O----OO-" + _
"OOOOOOOO" + _
"-----OO-" + _
"-----OO-" + _
"-----OO-"
nm(5) = _
"--OOOO--" + _
"--OOOO--" + _
"-O------" + _
"-OOO----" + _
"OOOOO---" + _
"---OOO--" + _
"----OO--" + _
"-----O--" + _
"-----O--" + _
"-----O--" + _
"O---O---" + _
"OOOO----"
nm(6) = _
"-----OOO" + _
"---OOO--" + _
"--OO----" + _
"-OO-----" + _
"-O-OOO--" + _
"OOO--OO-" + _
"OO----OO" + _
"OO----OO" + _
"OO----OO" + _
"OO----OO" + _
"-OO--OO-" + _
"--OOOO--"
nm(7) = _
"-OOOOOOO" + _
"-OOOOOO-" + _
"O-----O-" + _
"-----O--" + _
"-----O--" + _
"-----O--" + _
"----O---" + _
"----O---" + _
"---O----" + _
"---O----" + _
"---O----" + _
"--O-----"
nm(8) = _
"--OOOO--" + _
"-OO---OO" + _
"OO----OO" + _
"OO----OO" + _
"-OOO-OO-" + _
"--OOO---" + _
"--OOOO--" + _
"-O---OO-" + _
"OO----OO" + _
"OO----OO" + _
"-OO--OO-" + _
"--OOOO--"
nm(9) = _
"--OOOO--" + _
"-OO--OO-" + _
"OO----OO" + _
"OO----OO" + _
"OO----OO" + _
"OO----OO" + _
"-OO---OO" + _
"--OOOOO-" + _
"-----OO-" + _
"----OO--" + _
"---OO---" + _
"OOO-----"
Timer1.Enabled = True
End Sub
Private Function recognize() As String
t = 3 '上面3行空白
w = 8 '每個數字寬8像素
h = 12 '每個數字高12像素
x1 = 0
r = "xxxx"
On Error GoTo RERR
Picture1.Picture = LoadPicture(FPFN)
For n = 0 To 3
Do
For y = 0 To h - 1
b = (Picture1.Point(x1, t + y)) And 255
If b < 127 Then Exit For
Next
If y <= h - 1 Then Exit Do
x1 = x1 + 1
If x1 >= 70 Then
Debug.Print "找不到下一個數字對應的x1"
recognize = r
Label1.Caption = r
Exit Function
End If
Loop
s = ""
For y = 0 To h - 1
For x = 0 To w - 1
'Debug.Print " "; Right("00000000" + Hex(Picture1.Point(n * w + x, t + y)), 8);
b = (Picture1.Point(x1 + x, t + y)) And 255
'Debug.Print " "; Right("00" + Hex(b), 2);
If b > 127 Then
Debug.Print "-";
s = s + "-"
Else
Debug.Print "O";
s = s + "O"
End If
'Picture1.PSet (x1 + x, t + y), RGB(255, 0, 0)
Next
Debug.Print
Next
Debug.Print
x1 = x1 + w
For i = 0 To 9
If nm(i) = s Then
Mid(r, n + 1, 1) = CStr(i)
End If
Next
Next
RERR:
recognize = r
Label1.Caption = r
Exit Function
End Function
Private Sub Timer1_Timer()
Dim f As Integer
On Error Resume Next
If LCase(Right(FPFN, 4)) = ".bmp" Then
f = FreeFile()
Open FPFN + ".txt" For Output As #f
Print #f, recognize()
Close #f
End
Else
logtofile "[" + FPFN + "] is not .bmp file!"
End If
End Sub
Public Function FileExists(filename) As Boolean
Dim msg As String
On Error GoTo CheckError
FileExists = (Dir(filename) <> "")
Exit Function
CheckError:
Const mnErrDiskNotReady = 71, mnErrDeviceUnavailable = 68
If (Err.Number = mnErrDiskNotReady) Then
msg = "將軟盤插入驅動器 "
msg = msg + ",然后關好驅動器門。"
If MsgBox(msg, vbExclamation + vbOKCancel) = vbOK Then
Resume
Else
FileExists = False
Exit Function
End If
ElseIf Err.Number = mnErrDeviceUnavailable Then
msg = "找不到: "
msg = msg + filename
MsgBox msg, vbExclamation
FileExists = False
Exit Function
Else
FileExists = False
Exit Function
'msg = "出現 #" + str(Err.Number)
'msg = msg + " 意外錯誤: " + Err.Description
'MsgBox msg, vbCritical
'End'Form
End If
FileExists = False
Exit Function
End Function
Private Sub logtofile(s As String)
Dim f As Integer
On Error Resume Next
f = FreeFile()
Open App.Path + "\numeye1.log" For Append As #f
Print #f, Format(Now, "YYYY-MM-DD hh:mm:ss") + " " + s
Close #f
End Sub
uj5u.com熱心網友回復:
1 對于不等寬字符,首先要切分字符。首先將寬度例外的 1 挑出來。2 因為是仿 7 段 LED 字符。在每一個“LED 段”的位置選一個點來檢測。然后,根據檢測結果的編碼查表得到數字。
LED 段的序號(表示的 Bit):
0
5 1
6
4 2
3
編碼表:
0: &H3F
1: &H06
2: &H5B
3: &H4F
4: &H66
5: &H6D
6: &H7D
7: &H07
8: &H7F
9: &H6F
uj5u.com熱心網友回復:
做了一個簡單驗證碼識別程式(VB6.0代碼)uj5u.com熱心網友回復:
可以考慮一下金山詞霸的螢屏取詞辦法uj5u.com熱心網友回復:
最新的詞霸可以從圖片中挖字了嗎?我記得以前的是用系統鉤子抓寫txt的api實作的uj5u.com熱心網友回復:
2樓好厲害!uj5u.com熱心網友回復:
找個免費的OCR的SDK就好了,比如tesseract-ocr什么的,不需要自己去取樣識別吧。uj5u.com熱心網友回復:
厲害的,真是大俠,佩服佩服!轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/123885.html
標籤:VBA
