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

使用vb截屏幕,然后识别截图里面的文字。谁有思路可以说一下。其实就是网页上面FLASH上面的文字,就是一个时间显示。如何读取FLASH上面的时间?我想了半天,最后确定一个... 使用vb截屏幕,然后识别截图里面的文字。谁有思路可以说一下。
其实就是网页上面FLASH上面的文字,就是一个时间显示。如何读取FLASH上面的时间?
我想了半天,最后确定一个可行的思路,先截屏,然后再把截下来的图识别成数字。
截屏搜了半天使用lhdc = GetDC(0) '获取屏幕DC
BitBlt Picture1.hDC, 0, 0, 80000, 80000, lhdc, 0, 0, SRCCOPY
已经解决了。
但是是这个获取的图片如何识别成文字呢?谁有好的思路可以说一下。
还有把图片如何变成黑白的?
因为时间上面的背景是变的,显示的时间数字是白色的。如何把图片上白色的保存下来其他颜色全部变成黑色?
这些问题,谁知道都说说
谢谢了。
展开
 我来答
行深慎独k
推荐于2016-04-14 · TA获得超过726个赞
知道小有建树答主
回答量:393
采纳率:87%
帮助的人:149万
展开全部
主要是先要将图片转换为字节数组
'存放格式为(*, *, *),从左下角开始:
'第一维: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
pals
2010-09-01 · TA获得超过1044个赞
知道小有建树答主
回答量:1307
采纳率:0%
帮助的人:341万
展开全部
获取鼠标当前位置的文字,这个功能已经有很多源程序了,可以直接搜索得到。

可是你要求获得图片中的文字。图片中的文字已经不是文字,而是图片中的一些点了。所以无法直接识别,需要使用图文识别技术。

但这里你可以绕开图文识别,直接识别屏幕上的文字,即截图前的文字,或屏幕上鼠标当前位置的文字,而不是图片中的文字。至于如何截图中的位置与屏蔽上的位置进行转换,这应该不是很难的事了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
阿斯顿户
2010-08-30
知道答主
回答量:30
采纳率:0%
帮助的人:0
展开全部
好复杂.不懂
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2019-02-20
展开全部
在平时工作和学习生活中,一旦碰到一些需要拷贝一下来的图片上的文字,通常你会怎么做呢?
如果图片上都是,密密麻麻的文字,这你建议你试试用软件来帮助到你快速提取图片上的文字,不然一个个的敲打太麻烦了,其实现在手机上已经有很多图片文字识别的软件,具体操作方法如下:
比如说“迅捷ocr文字识别工具”为例:打开ocr--极速识别--添加文件--开始识别,需要这四步便可完成。
希望可以帮助到你。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式