delay 3000
Dim intX, intY, 序号
KeepCapture
dim 文件名="调试"
dim n=0
dim a= 数字识别(0,0,0,0,"111111-111111",0.9,0,0.8)
showmessage a
输出 a
ReleaseCapture
function 数字识别(x1,y1,x2,y2,颜色,相似度,噪音,距离相似度)
/*
作者:永远:qq:2381393524
功能:规整数字识别
参数:x1,y1,x2,y2:范围
噪音:整数:分割参数,符合颜色数量高于噪音才会分割
距离相似度:范围1-0:越低越容易找到数字
返回值:识别后的数字
*/
dim 特征(9),b,c,d,n,e,I,标记(9),距离(9),结果,下标
dim x,y
x=24:y=35
dim 点阵(9)
点阵(0)="0,000000000111111100000000|000000011111111111000000|000000111111111111110000|000001111111001111111000|000011111000000011111000|000111110000000001111100|000111100000000000111110|001111100000000000011110|001111000000000000011111|001111000000000000001111|011110000000000000001111|011110000000000000001111|011110000000000000000111|011110000000000000000111|011110000000000000000111|111100000000000000000111|111100000000000000000111|111100000000000000000111|111100000000000000000111|111100000000000000000111|111100000000000000000111|011110000000000000000111|011110000000000000000111|011110000000000000001111|011110000000000000001111|011111000000000000001111|001111000000000000011111|001111000000000000011110|000111100000000000111110|000111110000000000111100|000011111000000001111100|000011111100000111111000|000001111111111111110000|000000011111111111100000|000000001111111110000000|"
点阵(1)="1,000000000000000001111110|000000000000011111111111|000000000111111111111111|000000011111111111111111|000111111111111111111111|011111111111100001111111|111111111110000001111111|111111100000000001111111|111000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|000000000000000001111111|"
点阵(2)="2,000000001111111111000000|000000111111111111110000|000011111111111111111000|000111111100000011111100|000111110000000000111110|001111100000000000011110|001111000000000000001111|011110000000000000001111|011110000000000000001111|011110000000000000001111|000000000000000000001111|000000000000000000001111|000000000000000000001111|000000000000000000001111|000000000000000000011110|000000000000000000111110|000000000000000001111100|000000000000000001111000|000000000000000011110000|000000000000000111100000|000000000000001111000000|000000000000111110000000|000000000001111100000000|000000000011111000000000|000000000111110000000000|000000001111000000000000|000000011110000000000000|000000111100000000000000|000001111000000000000000|000011110000000000000000|000111100000000000000000|001111000000000000000000|011111111111111111111111|111111111111111111111111|111111111111111111111111|"
点阵(3)="3,000000001111111110000000|000000111111111111100000|000001111111111111111000|000011111100000111111100|000111110000000001111100|001111100000000000111110|001111000000000000011110|001111000000000000011110|000000000000000000011110|000000000000000000011110|000000000000000000011110|000000000000000000011110|000000000000000000111100|000000000000000001111100|000000000000000111111000|000000001111111111110000|000000001111111111000000|000000001111111111110000|000000000000000000111110|000000000000000000011111|000000000000000000001111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|111100000000000000000111|111100000000000000000111|011110000000000000001111|011111000000000000011111|001111100000000000111111|000111111000000011111110|000011111111111111111100|000001111111111111111000|000000011111111111100000|"
点阵(4)="4,000000000000000011111000|000000000000000111111000|000000000000001111111000|000000000000001111111000|000000000000011111111000|000000000000111101111000|000000000000111101111000|000000000001111001111000|000000000011111001111000|000000000011110001111000|000000000111100001111000|000000001111100001111000|000000001111000001111000|000000011110000001111000|000000111110000001111000|000000111100000001111000|000001111000000001111000|000001111000000001111000|000011110000000001111000|000111100000000001111000|000111100000000001111000|001111000000000001111000|011111000000000001111000|011110000000000001111000|111111111111111111111111|111111111111111111111111|111111111111111111111111|111111111111111111111111|000000000000000001111000|000000000000000001111000|000000000000000001111000|000000000000000001111000|000000000000000001111000|000000000000000001111000|000000000000000001111000|"
点阵(5)="5,001111111111111111111110|001111111111111111111110|001111111111111111111110|001111111111111111111110|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011100000000110000000000|011100001111111111100000|011100111111111111111000|011101111111111111111100|011111111000000011111110|011111100000000000111111|011110000000000000001111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|000000000000000000000111|111000000000000000000111|111100000000000000000111|111110000000000000001111|011111000000000000011111|001111100000000000111110|001111110000000001111110|000111111111111111111100|000001111111111111111000|000000111111111111100000|"
点阵(6)="6,000000000111111110000000|000000011111111111100000|000000111111111111111000|000001111110000111111100|000011111000000001111110|000111110000000000011110|000111100000000000011111|001111100000000000001111|001111000000000000000000|001111000000000000000000|011110000000000000000000|011110000000000000000000|011110000000000000000000|011110000111111111000000|011100001111111111110000|011100011111111111111000|111100111110000011111100|111101111000000000111110|111111100000000000001111|111111000000000000001111|111111000000000000000111|011111000000000000000111|011110000000000000000111|011110000000000000000111|011110000000000000000111|011111000000000000000111|001111000000000000000111|001111000000000000001111|001111100000000000001111|000111110000000000011110|000011111000000000111110|000011111100000011111100|000001111111111111111000|000000011111111111110000|000000001111111111000000|"
点阵(7)="7,111111111111111111111111|111111111111111111111111|111111111111111111111111|111111111111111111111111|000000000000000000000111|000000000000000000001111|000000000000000000001111|000000000000000000111110|000000000000000000111110|000000000000000001111100|000000000000000001111100|000000000000000011111000|000000000000000011111000|000000000000000111110000|000000000000000111110000|000000000000001111000000|000000000000001111000000|000000000000011110000000|000000000000011110000000|000000000000111100000000|000000000000111100000000|000000000001111000000000|000000000001111000000000|000000000011110000000000|000000000011110000000000|000000000111100000000000|000000000111100000000000|000000001111000000000000|000000001111000000000000|000000111110000000000000|000000111110000000000000|000001111100000000000000|000001111100000000000000|000011111000000000000000|000011111000000000000000|"
点阵(8)="8,000000001111111110000000|000000111111111111100000|000001111111111111111000|000011111100000111111000|000111110000000001111100|000111100000000000111110|001111100000000000011110|001111000000000000011110|001111000000000000011110|001111000000000000011110|001111000000000000011110|000111100000000000011110|000111100000000000111110|000011110000000001111100|000011111100000111111000|000000111111111111110000|000000011111111111100000|000001111111111111110000|000111110000000000111110|001111100000000000011111|011111000000000000001111|011110000000000000001111|011110000000000000000111|111100000000000000000111|111100000000000000000111|111100000000000000000111|011100000000000000000111|011110000000000000000111|011110000000000000001111|011111000000000000001111|001111100000000000011111|000111111000000001111110|000011111111111111111100|000001111111111111111000|000000011111111111100000|"
点阵(9)="9,000000011111111110000000|000001111111111111100000|000011111111111111110000|000111111100001111111000|001111100000000001111100|001111000000000000111110|011110000000000000011110|011110000000000000011111|111100000000000000001111|111100000000000000001111|111100000000000000001111|111100000000000000000111|111100000000000000000111|111100000000000000001111|111100000000000000001111|111100000000000000001111|011110000000000000011111|011111000000000000011111|001111110000000011111011|000111111111111111110011|000001111111111111100111|000000111111111110000111|000000000111111000000111|000000000000000000000111|000000000000000000000111|000000000000000000001111|000000000000000000001111|011110000000000000001111|011110000000000000011110|011111000000000000111110|001111100000000001111100|000111110000000011111000|000011111111111111110000|000001111111111111100000|000000011111111111000000|"
n=1
//提取点阵
i=0
for each arr in 点阵
b=split(arr,",")
标记(i)=b(0)
特征(i)=b(1)
i=i+1
next
//先分割
dim a=分割yx(x1,y1,x2,y2,颜色,相似度,噪音)
for n=1 to int(a(0,0))
//归一化
SnapShot "/sdcard/调试/"&n&".png", int(a(0,n)),int(a(1,n)),int(a(2,n)),int(a(3,n))
c=归一化(int(a(0,n)),int(a(1,n)),int(a(2,n)),int(a(3,n)),颜色,相似度,x,y)
//获取距离
i=0
for each arr in 特征
距离(i)=字符距离(c,arr)
i=i+1
next
下标=最小值(距离,1)
e=1-(int(距离(下标))/(x*y))
if e>=距离相似度 then
结果=结果&标记(下标)
end if
next
数字识别=结果
end function
function 归一化(x1,y1,x2,y2,颜色,相似度,x,y)
dim c,xx,yy,xxx,yyy
xx=x2-x1
yy=y2-y1
for yyy=0 to y-1
for xxx=0 to x-1
c=c& CmpColor(x1+xxx*(xx/x),y1+yyy*(yy/y),颜色,相似度)+1
next
c=c&"|"
next
归一化=c
end function
function 字符距离(字符1,字符2)
dim a,b,c,n,aa(),bb(),cc()
dim i,k
n=0
i=1
k=1
a=len(字符1)
b=len(字符2)
if a>b then
c=a
else
c=b
end if
for c
//判断字符是否一样
if mid(字符1,k,1)<>mid(字符2,k,1) then
n=n+1
end if
k=k+1
next
字符距离=n
end function
function 最小值(sz,返回方式)
for each arr in sz
next
//功能:输入数组数字返回最小值
//参数:sz:数组类型
//参数:返回方式:0代表返回数组的值,1代表返回数组的下标
//备注:多个最小值返回下标最小的最小值
dim 返回值=int(sz(0))
if 返回方式=0 then
for each arr in sz
if arr<返回值 then
返回值=arr
end if
next
else
dim i=0
dim n=0
for i=0 to ubound(sz)
if int(sz(i))<int(返回值) then
返回值=sz(i)
n=i
end if
next
返回值=n
end if
最小值=返回值
end function
Function min(arr)
Dim mins=9999999
For i = 0 To UBOUND(arr)
If mins > CInt(arr(i)) Then
mins=CInt(arr(i))
End If
Next
min=mins
End Function
Function Splits(str)
Dim arr()
For i = 1 To utf8.len(str)
arr(i - 1) = utf8.Mid(str, i, 1)
Next
Splits=arr
End Function
function 分割x(x1,y1,x2,y2,颜色,相似度,噪音)
/*
功能:垂直投影分割,分割成n个范围
参数:x1,y1,x2,y2:分割范围
颜色:支持多个颜色"|"偏色"-"
相似度:颜色相似度
噪音:符合颜色高于噪音才会分割
返回值:二维数组:格式:返回值(x1y1x2y2,索引)
返回值(0,0)是分割范围的数量,也就是最大下标
*/
Dim 颜色数量,xx,yy,xx1,yy1,起点,终点,intx,inty,intxx,intyy
dim 起点1,终点1,x11,y11,范围(3,0)
dim n=1
dim m=","
if x1=0 and y1=0 and x2=0 and y2=0 then
x2 =GetScreenX()
y2 = GetScreenY()
end if
起点1=0
终点1=0
起点=0
终点=0
for i=0 to x2-x1
颜色数量 = GetColorNum(x1, y1, x1, y2, 颜色,相似度)
if 颜色数量>噪音 and 起点=0 then
起点=1
xx=x1
elseif 颜色数量<=噪音 and 起点=1 then
终点=1
xx1=x1-1
end if
if 起点=1 and 终点=1 then
FindColor(xx,y1,xx1,y2, 颜色,0, 相似度, intX, intY)
FindColor(xx,y1,xx1,y2, 颜色,2, 相似度, intxX, intyY)
范围(0,n)=xx:范围(1,n)=inty:范围(2,n)=xx1:范围(3,n)=intyy
n=n+1:起点=0:终点=0
end if
x1=x1+1
next
范围(0,0)=n-1
分割x=范围
end function
function 分割yx(x1,y1,x2,y2,颜色,相似度,噪音)
Dim 颜色数量,xx,yy,xx1,yy1,起点,终点,intx,inty,intxx,intyy
dim 起点1,终点1,x11,y11,范围(3,0)
dim n=1
dim m=","
if x1=0 and y1=0 and x2=0 and y2=0 then
x2 =GetScreenX()
y2 = GetScreenY()
end if
起点1=0
终点1=0
起点=0
终点=0
for i=0 to y2-y1
颜色数量 = GetColorNum(x1, y1, x2, y1, 颜色,相似度)
if 颜色数量>噪音 and 起点=0 then
起点=1
yy=y1
elseif 颜色数量<=噪音 and 起点=1 then
终点=1
yy1=y1-1
end if
if 起点=1 and 终点=1 then
dim 返回结果=分割x(x1,yy,x2,yy1,颜色,相似度,噪音)
for k=1 to 返回结果(0,0)
范围(0,n)=返回结果(0,k):范围(1,n)=返回结果(1,k):范围(2,n)=返回结果(2,k):范围(3,n)=返回结果(3,k)
n=n+1
next
起点=0
终点=0
end if
y1=y1+1
next
范围(0,0)=n-1
分割yx=范围
end function
function 输出(内容)
Dim 路径
路径 = "/sdcard/调试.txt"
'Dir.Delete(路径)
if IsArray(内容)=true then
for each s in 内容
File.Append 路径, "\n"&s
next
else
TracePrint 内容
File.Append 路径, "\n"&内容
end if
end function