189 8069 5689

包含vb.net图片文字识别的词条

用VB将图片转换文字

用VB应该能够实现,不过时间和正确率不算可观。

目前创新互联已为上千家的企业提供了网站建设、域名、雅安服务器托管绵阳服务器托管、企业网站设计、漾濞网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

而且使用起来也应该有诸多限制。

先把传到程序的图片做一个RGB处理,很简单。黑变白,白变黑,其他的全变黑就可以了。然后利用现有的字库经行逐点对比,字体颜是白色。

这里用该会有个概率。假设如果X%的像素点相等,那就输出这个字。

加速度的话,把已经输出的字符,做成一个表,在进行匹配的时候,同时匹配这个表,如果匹配出来的话,就放弃与字库的匹配,输出这个字。

字体必须要是标准的。字号必须的相等的。没这么简单,很复杂,

1L,没有什么不可能的,OCR又什么了?单靠VB就不行了?照你这样说,难道只用汇编就不能做3D程序?不是属于什么什么的,就像X器官不只是你一个人有一样。

2L,既然有了自定义字库,那就不会是手写了吧?

3L,VB不是先不先进,只是你对VB的认识也就那么肤浅而已。

你这个说法失之偏颇了吧?就像1L一样。先进?那我就用最老的举例吧,单用汇编就不能做3D引用程序?

没有汇编,哪来电脑的今天?

就像今天你手头没有VB,数据库你怎么来?

VB是语言,语言不是算法。

4L,我挺你

vb 部分截屏之后识别图片上的文字

主要是先要将图片转换为字节数组

'存放格式为(*, *, *),从左下角开始:

'第一维:0-蓝色分量,1-绿色分量,2-红色分量,

'第二维:列;第三维:行

全部步骤如下

1、用DibGet获取图片数据

2、用ColorToBlackAndWhite(或ColorToGray+OtsuColorToBlackAndWhite)将图片数据转换为黑白数据

3、用DibPut将数据恢复到一个PictureBox中

4、截取各个数字到单独的PictureBox中

5、将数字图片转换为图片数据,并与标准数据(0-9)对比,相似度最高的为准(比如与1的相似度为75%,与2的相似度为85%,则此数字为2)

有问题Hi

'图像输出的过程:

Public Sub DIBPut(ByVal IdDestination As Long, ByRef ImageData() As Byte)

Dim LineBytes As Long

Dim Width As Long, Height As Long

Width = UBound(ImageData, 2) + 1

Height = UBound(ImageData, 3) + 1

On Error GoTo ErrLine

Done = False

With bi24BitInfo.bmiHeader

.biWidth = Width

.biHeight = Height

LineBytes = ((Width * Bits + 31) And HFFFFFFE0) \ 8

.biSizeImage = LineBytes * Height

End With

SetDIBitsToDevice IdDestination, 0, 0, Width, Height, 0, 0, 0, Height, ImageData(0, 0, 0), bi24BitInfo, 0

Done = True

Exit Sub

ErrLine:

MsgBox Err.Description

End Sub

'灰度处理SrcData(0 to 2, 0 to 宽度-1, 0 to 高度-1)

Public Sub ColorToGray(ByRef SrcData() As Byte, ByRef DestData() As Byte, _

Optional Left As Long = -1, Optional Top As Long = -1, _

Optional Right As Long = -1, Optional Bottom As Long = -1)

Dim i As Long, j As Long, k As Long

Dim red As Byte, green As Byte, blue As Byte

Dim Color As Long, newcolor As Long

Dim Width As Long, Height As Long

Width = UBound(SrcData, 2) + 1

Height = UBound(SrcData, 3) + 1

If Left = -1 Then Left = 0

If Top = -1 Then Top = 0

If Right = -1 Then Right = Width - 1

If Bottom = -1 Then Bottom = Height - 1

For j = Left To Right

For k = Height - Bottom - 1 To Height - Top - 1

blue = SrcData(0, j, k)

green = SrcData(1, j, k)

red = SrcData(2, j, k)

newcolor = CLng(0.299 * CDbl(red) + 0.585 * CDbl(green) + 0.114 * CDbl(blue)) '

newcolor = newcolor * 65793

red = newcolor Mod 256

green = newcolor / 256 Mod 256 '(9798 * RValue + 19235 * GValue + 3735 * BValue) / 32768

blue = newcolor / 256 / 256

DestData(0, j, k) = blue

DestData(1, j, k) = green

DestData(2, j, k) = red

Next

Next

End Sub

'黑白处理DestData(0 to 2, 0 to 宽度-1, 0 to 高度-1)

'图片最下面两行总是无法参与变换????只好将采集的图片区域向下多延伸2个像素

Public Sub ColorToBlackAndWhite(ByRef SrcData() As Byte, ByRef DestData() As Byte)

Dim i As Long, j As Long, k As Long

Dim red As Byte, green As Byte, blue As Byte

Dim Color As Long, newcolor As Long

Dim Width As Long, Height As Long

Width = UBound(SrcData, 2) + 1

Height = UBound(SrcData, 3) + 1

For j = 0 To Width - 1

For k = 0 To Height - 1

blue = SrcData(0, j, k)

green = SrcData(1, j, k)

red = SrcData(2, j, k)

newcolor = CLng(0.3 * CDbl(red) + 0.59 * CDbl(green) + 0.11 * CDbl(blue))

' newcolor = CLng(0.39 * CDbl(red) + 0.5 * CDbl(green) + 0.11 * CDbl(blue))

If newcolor 127 Then newcolor = 255 Else newcolor = 0

red = newcolor

green = newcolor

blue = newcolor

DestData(0, j, k) = blue

DestData(1, j, k) = green

DestData(2, j, k) = red

Next

Next

End Sub

'黑白处理DestData(0 to 2, 0 to 宽度-1, 0 to 高度-1)

'图片最下面两行总是无法参与变换????只好将采集的图片区域向下多延伸2个像素

'OSTU算法可以说是自适应计算单阈值(用来转换灰度图像为二值图像)的简单高效方法。

'1978 OTSU年提出的最大类间方差法以其计算简单、稳定有效,一直广为使用。

Public Sub OtsuColorToBlackAndWhite(ByRef SrcData() As Byte, ByRef DestData() As Byte)

On Error Resume Next

Dim i As Long, j As Long, k As Long

Dim red As Byte, green As Byte, blue As Byte

Dim Color As Long, newcolor As Long

Dim Width As Long, Height As Long

Dim AllSum As Long, SumSmall As Long, SumBig As Long, PartSum As Long

Dim AllPixelNumber As Integer, PixelNumberSmall As Long, PixelNumberBig As Long

Dim ProbabilitySmall As Double, ProbabilityBig As Double, Probability As Double, MaxValue As Double

Dim BmpData() As Byte, Threshold As Byte

Dim Histgram(255) As Integer '图像直方图,256个点

Dim PixelNumber As Integer

Width = UBound(SrcData, 2) + 1

Height = UBound(SrcData, 3) + 1

PixelNumber = Width * Height

For i = 0 To Width - 1

For j = 0 To Height - 1

Histgram(SrcData(0, i, j)) = Histgram(SrcData(0, i, j)) + 1 '统计图像的直方图

Next

Next

For i = 0 To 255

AllSum = AllSum + i * Histgram(i) ' 质量矩

AllPixelNumber = AllPixelNumber + Histgram(i) ' 质量

Next

MaxValue = -1#

For i = 0 To 255

PixelNumberSmall = PixelNumberSmall + Histgram(i)

PixelNumberBig = AllPixelNumber - PixelNumberSmall

If PixelNumberBig = 0 Then Exit For

SumSmall = SumSmall + i * Histgram(i)

SumBig = AllSum - SumSmall

ProbabilitySmall = CDbl(SumSmall) / PixelNumberSmall

ProbabilityBig = CDbl(SumBig) / PixelNumberBig

' Probability = PixelNumberSmall * PixelNumberBig * (ProbabilityBig - ProbabilitySmall) * (ProbabilityBig - ProbabilitySmall)

Probability = PixelNumberSmall * ProbabilitySmall * ProbabilitySmall + PixelNumberBig * ProbabilityBig * ProbabilityBig

If Probability MaxValue Then

MaxValue = Probability

Threshold = i

End If

Next

For j = 0 To Width - 1

For k = 0 To Height - 1

If SrcData(0, j, k) = Threshold Then

DestData(0, j, k) = 0

DestData(1, j, k) = 0

DestData(2, j, k) = 0

Else

DestData(0, j, k) = 255

DestData(1, j, k) = 255

DestData(2, j, k) = 255

End If

Next

Next

End Sub

'迭代法 (最佳阀值法)

'(1)求出图象的最大灰度值和最小灰度值,分别记为Zl和Zk,令初始阈值为:T=(Zl+Zk)/2

'(2)根据阈值TK将图象分割为前景和背景,分别求出两者的平均灰度值Z0和ZB:

'(3)令当前阈值Tk=(Z0+ZB)/2

'(4)若TK=TK+1, 则所得即为阈值,否则转2,迭代计算。

Public Sub BestThresholdColorToBlackAndWhite(ByRef SrcData() As Byte, ByRef DestData() As Byte)

Dim i As Long, j As Long, k As Long

Dim red As Byte, green As Byte, blue As Byte

Dim Color As Long, newcolor As Long

Dim Width As Long, Height As Long

Dim PixelNumber As Integer

Dim Threshold As Integer, NewThreshold As Integer, MaxGrayValue As Integer

Dim MinGrayValue As Integer, MeanGrayValue1 As Integer, MeanGrayValue2 As Integer

Dim IP1 As Long, IP2 As Long, IS1 As Long, IS2 As Long

Dim Iteration As Long, Histgram(255) As Integer

Width = UBound(SrcData, 2) + 1

Height = UBound(SrcData, 3) + 1

PixelNumber = Width * Height

'求出图像中的最小和最大灰度值,并 计算阈值初值为

MaxGrayValue = 0: MinGrayValue = 255

For i = 0 To Width - 1

For j = 0 To Height - 1

Histgram(SrcData(0, i, j)) = Histgram(SrcData(0, i, j)) + 1 '统计图像的直方图

If MinGrayValue SrcData(0, i, j) Then MinGrayValue = SrcData(0, i, j)

If MaxGrayValue SrcData(0, i, j) Then MaxGrayValue = SrcData(0, i, j)

Next

Next

NewThreshold = (MinGrayValue + MaxGrayValue) / 2

While Threshold NewThreshold And Iteration 100

Threshold = NewThreshold

'根据阈值将图像分割成目标和背景两部分,求出两部分的平均灰度值

For i = MinGrayValue To Threshold

IP1 = IP1 + Histgram(i) * i

IS1 = IS1 + Histgram(i)

Next

MeanGrayValue1 = CByte(IP1 / IS1)

For i = Threshold + 1 To MaxGrayValue

IP2 = IP2 + Histgram(i) * i

IS2 = IS2 + Histgram(i)

Next

MeanGrayValue2 = CByte(IP2 / IS2)

'求出新的阈值:

NewThreshold = (MinGrayValue + MaxGrayValue) / 2

Iteration = Iteration + 1

Wend

For j = 0 To Width - 1

For k = 0 To Height - 1

If SrcData(0, j, k) = Threshold Then

DestData(0, j, k) = 0

DestData(1, j, k) = 0

DestData(2, j, k) = 0

Else

DestData(0, j, k) = 255

DestData(1, j, k) = 255

DestData(2, j, k) = 255

End If

Next

Next

End Sub

VB窗口截图并将图片上文字识别成文字。

为何要采用截图功能去取窗口的句柄呢,可以用窗口标题去取句柄呀。

VB怎么获取图片上的文字?

这个得看具体网页才能分析 如果是图形形式的文字 你只能借助文字识别技术来操作 如果是文本 你可以获取网页对应的元素 取对象的text属性

vb编程识别图片中文字

识别图片里文字的方法,通常称为OCR(Optical

Character

Recognition,光学字符识别),需要利用非常复杂的模式识别算法才能实现。自己用VB开发OCR程序工作量太大。

可以考虑采用OCR插件,即在电脑上安装OCR控件,然后在VB程序中调用该控件。如WPS,紫光、汉王的OCR系统都带有可调用的控件,但都比较大,而且有使用限制。我曾经用过一个免费的91OCR控件,识别效果还马马虎虎可以。


本文标题:包含vb.net图片文字识别的词条
当前链接:http://jkwzsj.com/article/hpssip.html

其他资讯