求一个简单的图像思路 谢谢大家
上面有几张图,每张图都有数字,但有个问题,他是居中显示的,如果是居左或者居右的话我还有办法
还有就是,这些数字有可能是1,2,3位数的,不能通过 位置颜色识别的方法来识别
请各位老师给我个思路,谢谢,我之前发的贴子根据您们的思路已完成,再一次感谢 --------------------编程问答-------------------- 我想起一个方案,大家说下行不行
我先抓3位数大小的图,不管是不是3位
然后二值化,看左边第一位有没有数据(通特征码),如果没有,就说明是个两个数
依此累推
但这样,我觉得是不是太累了,求更好的方法 --------------------编程问答-------------------- 真正居中的话,扫中间,统计水平投影就可以了嘛。 --------------------编程问答-------------------- 国庆节都出去耍去了,没人理我。。 555555555 --------------------编程问答-------------------- 没人了吗 各位老师 --------------------编程问答--------------------
VERSION 5.00--------------------编程问答-------------------- 没看懂,好像楼主没有说需求。。。。不知道楼上的是怎么知道答案的。。。。 --------------------编程问答-------------------- 扫描一下,调到左边或者右边。
Begin VB.Form Form1
Caption = "numeye by zhao4zhong1@163.com"
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
补充:VB , 基础类