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


Probability = PixelNumberSmall * ProbabilitySmall * ProbabilitySmall + PixelNumberBig * ProbabilityBig * ProbabilityBig
If ProbabilityMaxValue Then
MaxValue = https://www.04ip.com/post/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 = https://www.04ip.com/post/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 MinGrayValueSrcData(0, i, j) Then MinGrayValue = https://www.04ip.com/post/SrcData(0, i, j)
If MaxGrayValueSrcData(0, i, j) Then MaxGrayValue = https://www.04ip.com/post/SrcData(0, i, j)
Next
Next
NewThreshold = (MinGrayValue + MaxGrayValue) / 2
While ThresholdNewThreshold And Iteration100
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应该能够实现,不过时间和正确率不算可观 。
而且使用起来也应该有诸多限制 。
先把传到程序的图片做一个RGB处理,很简单 。黑变白,白变黑,其vb.net图片文字识别他的全变黑就可以vb.net图片文字识别了 。然后利用现有的字库经行逐点对比,字体颜是白色 。
这里用该会有个概率 。假设如果X%的像素点相等,那就输出这个字 。
加速度的话 , 把已经输出的字符,做成一个表,在进行匹配的时候,同时匹配这个表,如果匹配出来的话,就放弃与字库的匹配 , 输出这个字 。
字体必须要是标准的 。字号必须的相等的 。没这么简单,很复杂 , 

推荐阅读