不求甚解

此博客为个人学习之用,如与其他作品雷同,纯属巧合。
随笔 - 156, 文章 - 1, 评论 - 2, 阅读 - 10万

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

注:仅供个人学习和娱乐

软件

umi截图插件,excel,按键精灵,神梦dll

神梦dll:https://files.cnblogs.com/files/wxp100/%E7%A5%9E%E6%A2%A6dll.zip?t=1721007482&download=true

umi:https://github.com/hiroi-sora/Umi-OCR

思路

先移动一段距离通过计算斜率,做方向对比,换算成角度,判断最终转向

脚本

复制代码
Function 对接umiocr(图片路径)
    Dim URL,JsonData,json,username,password,base64
    URL = "http://192.168.1.40:1224/api/ocr"
    Import "SmHTTP.dll"  
    Set SmHTTP = CreateObject("SMWH.SmHTTP")
    base64=Plugin.SMWH.Base64_File(图片路径)
    JsonData = SmHTTP.JsonData( _   
    "base64",base64 , _
    "Content-Type", "application/json" _
    )   
    json = SmHTTP.HTTP_POST(URL, JsonData)
    //TracePrint json
    If SmHTTP.GetStatus() = 200 Then 
        If SmHTTP.GetJSON(json, "code")=100 Then 
            Dim 文本左上x, 文本左上y, 文本右上x, 文本右上y, 识别的文本
            文本左上x=SmHTTP.GetJSON(json, "data[0]['box'][0][0]")
            文本左上y=SmHTTP.GetJSON(json, "data[0]['box'][0][1]")
            文本右上x=SmHTTP.GetJSON(json, "data[0]['box'][2][0]")
            文本右上y=SmHTTP.GetJSON(json, "data[0]['box'][2][1]")
            识别的文本 = SmHTTP.GetJSON(json, "data[0]['text']")
            //对接umiocr="识别的文本:" & 识别的文本 & ",文本范围:" & 文本左上x & "," & 文本左上y & "," & 文本右上x & "," & 文本右上y
            对接umiocr= 识别的文本 
        Else 
            对接umiocr=-1
        End If
    Else 
        对接umiocr=-1
    End If
End Function

Function 判断方向(x1,y1,x2,y2)
Dim pi
pi = 3.14159265359
If x2 <> x1 Then 
斜率 = (y2 - y1) / (x2 - x1)
End If
a = Atn(斜率) / pi * 180
//TracePrint x1&"  "&y1&"  "&x2&"  "&y2
If y2 - y1 < 0 Then 
    If x2 - x1 > 0 Then 
        // 此时目的地在角色的东北方
        a = a + 270
    ElseIf x2 - x1 < 0 Then 
        // 此时目的地在角色的西北方
        a = a + 90
    ElseIf x2 - x1 = 0 Then
        // 此时目的地在角色的上方
        a = 180
    End If
ElseIf y2 - y1 > 0 Then 
    If x2 - x1 > 0 Then 
        // 此时目的地在角色的东南方
        a = a + 270
    ElseIf x2 - x1 < 0 Then 
        // 此时目的地在角色的西南方
        a = a + 90
    ElseIf x2 - x1 = 0 Then
        // 此时目的地在角色的下方
        a = 0
    End If
ElseIf y2 - y1 = 0 Then
    If x2 - x1 > 0 Then 
        // 此时目的地在角色的右方
        a = 270
    ElseIf x2 - x1 < 0 Then 
        // 此时目的地在角色的左方
        a= 90
    End If
End If
判断方向=a
End Function


//转一圈2秒,转一度需要2000/360
旋转一度用时 =2000/360
Sub 调整人物角度(目标方向, 移动方向)
角度 = abs(目标方向 - 移动方向)
If 角度 > 10 Then 
If 目标方向>移动方向 Then
    KeyDown "Right", 1
    Delay 角度 * 旋转一度用时
    KeyUp "Right", 1
Else 
    KeyDown "left", 1
    Delay 角度 * 旋转一度用时
    KeyUp "left", 1
End If
End If
End sub

//获取所有目的坐标数据
Call Plugin.Office.OpenXls("C:\Users\wxp\Desktop\test1.xlsx")
Dim line
line=1
Do
data = Plugin.Office.ReadXls(1, line, 1)
If data <>"" Then 
    line = line + 1
    Else 
    Exit Do
End If
Loop
ReDim array_x(line-2), array_y(line-2)
For i=0 to line-2
array_x(i) = Plugin.Office.ReadXls(1, i+1, 1)
array_y(i) = Plugin.Office.ReadXls(1, i+1, 2)
Next
Call Plugin.Office.CloseXls()


//移动坐标x_x,m_y  初始坐标i_x,i_y  目标坐标t_x,t_y  
Dim m_x, m_y, i_x, i_y, t_x, t_y, count
count = 0
t_x=array_x(count)
t_y=array_y(count)


//获取初始坐标
Call Plugin.Pic.PrintScreen(9, 27, 108, 53, "D:\按键精灵\temp\jt.bmp")
坐标 = 对接umiocr("D:\按键精灵\temp\jt.bmp")
i_x=left(坐标,4) 
i_y=right(坐标,4) 

//初始距离
Dim d
//判断移动后距离
d=Sqr((i_x-t_x)*(i_x-t_x)+(i_y-t_y)*(i_y-t_y))
Do
If (d > 0.25) Then 
dim 目标方向
目标方向 = 判断方向(t_x,t_y,i_x,i_y)
KeyDown "up", 1
Delay 1200
KeyUp "up", 1
Call Plugin.Pic.PrintScreen(9, 27, 108, 53, "D:\按键精灵\temp\jt.bmp")
坐标 = 对接umiocr("D:\按键精灵\temp\jt.bmp")
m_x = left(坐标, 4)
m_y = right(坐标, 4)
d=Sqr((m_x-t_x)*(m_x-t_x)+(m_y-t_y)*(m_y-t_y))
dim 移动方向
移动方向 = 判断方向(m_x,m_y,i_x,i_y)
//TracePrint "目标方向:" & 目标方向 & "移动方向:" & 移动方向
call 调整人物角度 (目标方向,移动方向)
i_x = m_x
i_y = m_y

ElseIf (d < 0.25)
TracePrint "距离:"&d&"目标移动到位"
If count < line-2 Then 
count=count+1
t_x = array_x(count)
t_y = array_y(count)
i_x = m_x
i_y = m_y
d=Sqr((i_x-t_x)*(i_x-t_x)+(i_y-t_y)*(i_y-t_y))
TracePrint "移动坐标次数:" & count
Else 
Exit Do
End If
End If
loop
复制代码

ps:

  • 坐标截图:“D:\按键精灵\temp\jt.bmp”
  • 坐标移动位置记录:“C:\Users\wxp\Desktop\test1.xlsx“

 

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
点击右上角即可分享
微信分享提示