VB获取简单图片中的数字

dengxin1234569 2014-03-23 04:47:12

如何用VB去识别这个图片中的数字?
...全文
1591 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
makerj 2014-04-16
  • 打赏
  • 举报
回复
厉害的,真是大侠,佩服佩服!
三楼の郎 2014-03-28
  • 打赏
  • 举报
回复
找个免费的OCR的SDK就好了,比如tesseract-ocr什么的,不需要自己去取样识别吧。
huangjinyuzi 2014-03-27
  • 打赏
  • 举报
回复
2楼好厉害!
yyfhz 2014-03-26
  • 打赏
  • 举报
回复
最新的词霸可以从图片中挖字了吗?我记得以前的是用系统钩子抓写txt的api实现的
贝隆 2014-03-26
  • 打赏
  • 举报
回复
可以考虑一下金山词霸的屏幕取词办法
of123 2014-03-24
  • 打赏
  • 举报
回复
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
赵4老师 2014-03-24
  • 打赏
  • 举报
回复
仅供参考:
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
threenewbee 2014-03-23
  • 打赏
  • 举报
回复
用point语句。 你需要采样8个点,你可以算出坐标以及每个字符的宽度,分别是8段管的8条线。判断它们有没有。 然后再判断是数字几。
dengxin1234569 2014-03-23
  • 打赏
  • 举报
回复
这问题就很难么?大神们,谁帮帮忙

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧