local ts = require("ts")
local StringHelper = {}
--[[
utf-8编码规则
单字节 - 0起头
1字节 0xxxxxxx 0 - 127
多字节 - 第一个字节n个1加1个0起头
2 字节 110xxxxx 192 - 223
3 字节 1110xxxx 224 - 239
4 字节 11110xxx 240 - 247
可能有1-4个字节
--]]
function StringHelper.GetBytes(char)
if not char then
return 0
end
local code = string.byte(char)
if code < 127 then
return 1
elseif code <= 223 then
return 2
elseif code <= 239 then
return 3
elseif code <= 247 then
return 4
else
-- 讲道理不会走到这里^_^
return 0
end
end
function StringHelper.Sub(str, startIndex, endIndex)
local tempStr = str
local byteStart = 1 -- string.sub截取的开始位置
local byteEnd = -1 -- string.sub截取的结束位置
local index = 0 -- 字符记数
local bytes = 0 -- 字符的字节记数
startIndex = math.max(startIndex, 1)
endIndex = endIndex or -1
while string.len(tempStr) > 0 do
if index == startIndex - 1 then
byteStart = bytes+1;
elseif index == endIndex then
byteEnd = bytes;
break;
end
bytes = bytes + StringHelper.GetBytes(tempStr)
tempStr = string.sub(str, bytes+1)
index = index + 1
end
return string.sub(str, byteStart, byteEnd)
end
personlist = {"四八六不六","五郎","阿宝","山葵","美莎","宝儿不黏人"}
function parsePeople(index)
x,y,xx,yy = 99, 487, 266, 518
x1,y1,xx1,yy1 = 280,487,447,518
x2,y2,xx2,yy2 = 461,487,628,518
x3,y3,xx3,yy3 = 642,487,809,518
x4,y4,xx4,yy4 = 823,487,990,518
x5,y5,xx5,yy5 = 1004,487,1171,518
temp = ""
if index == 1 then
temp = ocrText(x,y,xx,yy,1)
temp = ocrText(x,y,xx,yy,1)
end
if index==2 then
temp = ocrText(x1,y1,xx1,yy1,1)
end
if index==3 then
temp = ocrText(x2,y2,xx2,yy2,1)
end
if index==4 then
temp = ocrText(x3,y3,xx3,yy3,1)
end
if index==5 then
temp = ocrText(x4,y4,xx4,yy4,1)
end
if index==6 then
temp = ocrText(x5,y5,xx5,yy5,1)
end
temp = temp:trim()
dstIndex =0
i=1
while personlist[i] do
j=1
kkk=0
--dialog(utf8.len(temp))
--dialog(StringHelper.Sub(temp,1,1))
while j<=utf8.len(temp) do
hh = StringHelper.Sub(temp,j,j)
--dialog(hh)
if string.find(personlist[i],hh)~=nil then
kkk = kkk+1
end
j=j+1
end
if kkk/utf8.len(personlist[i])>0.57 then
dstIndex=i
break
end
i=i+1
end
if dstIndex > 0 then
return personlist[dstIndex]
else
return nil
end
end
init(1)
whitelist = "四八六不六"
--mSleep(10000)
result =parsePeople(1)
if result ~= nil then
dialog(result,0)
end
result =parsePeople(2)
if result ~= nil then
dialog(result,0)
end
result =parsePeople(3)
if result ~= nil then
dialog(result,0)
end
result =parsePeople(4)
if result ~= nil then
dialog(result,0)
end
result =parsePeople(5)
if result ~= nil then
dialog(result,0)
end
ro经验
最新推荐文章于 2024-07-30 17:01:09 发布