|
300精币
例子是用py调用这个DLL文件的,DLL文件32位的。下面是PY调用的例子 import ctypes import os import sys # 创建句柄 key = "SNKJaURwbfuhcaQaCMJVhdByPZMVsZdqRUMjfWrxY1A5" # 字符串 key_bytes = key.encode ( #设置模型文件路径 onnx = "d://SNTrack.onnx" # 字符串 onnx_bytes = onnx.encode ( # 假设 DLL 文件名为 SNSDK.dll sn_sdk = ctypes.WinDLL ( # 定义 SN_RESULT 结构体 class SN_RESULT (ctypes.Structure): _fields_ = [ ("code", ctypes.c_int), ("message", ctypes.c_char * 4096)] # 定义 SN_POINT 结构体 class SN_POINT (ctypes.Structure): _fields_ = [ ("x", ctypes.c_int), ("y", ctypes.c_int)] # 定义 SN_POINT_PARAMS 结构体 class SN_POINT_PARAMS (ctypes.Structure): _fields_ = [ ("point", SN_POINT), ("delayTime", ctypes.c_int)] # 定义函数原型 sn_sdk.apiSNCreateHandle.argtypes = [ctypes.POINTER (ctypes.c_char),ctypes.POINTER (ctypes.c_char), ctypes.POINTER (SN_RESULT)] sn_sdk.apiSNCreateHandle.restype = ctypes.c_void_p sn_sdk.apiSNGetVersion.argtypes = [ctypes.c_void_p, ctypes.POINTER (ctypes.c_char)] sn_sdk.apiSNGetVersion.restype = SN_RESULT sn_sdk.apiSNMouseMove.argtypes = [ctypes.c_void_p, SN_POINT, SN_POINT, ctypes.POINTER (SN_POINT_PARAMS)] sn_sdk.apiSNMouseMove.restype = SN_RESULT # 根据实际情况调整 sn_sdk.apiSNDestroyHandle.argtypes = [ctypes.c_void_p] sn_sdk.apiSNDestroyHandle.restype = SN_RESULT result = SN_RESULT () # 创建 SN_RESULT 实例 handle = sn_sdk.apiSNCreateHandle (key_bytes, onnx_bytes,ctypes.byref (result)) if result.code != 0: message = result.message.decode ( print ("Result message:", message) else: print ("Handle created successfully") # 获取版本号 version = ctypes.create_string_buffer (4096) version_result = sn_sdk.apiSNGetVersion (handle, version) if version_result.code != 0: message = result.message.decode ( print ("Result message:", message) else: message = result.message.decode ( print ("Result message:", version.value.decode ()) # 获取轨迹 # 定义开始和结束坐标 start_point = SN_POINT (100, 100) end_point = SN_POINT (800, 800) # 假设返回的轨迹点数量 num_points = 4096 # 创建一个数组来接收轨迹点 points_array = (SN_POINT_PARAMS * num_points) () # 调用 apiSNMouseMove 函数 move_result = sn_sdk.apiSNMouseMove (handle, start_point, end_point, points_array) # 检查结果 if move_result.code != 0: message = result.message.decode ( print ("Result message:", message) else: # 遍历并打印每个点 for i in range (num_points): if points_array[i].point.x == -1 and points_array[i].point.y == -1: break # 轨迹结束 print (f"Point {i}: ({points_array[i].point.x}, {points_array[i].point.y},{points_array[i].delayTime})") # X坐标 ,Y坐标 ,延时时间 # 释放句柄 destroy_result = sn_sdk.apiSNDestroyHandle (handle) if destroy_result.code != 0: message = result.message.decode ( print ("Result message:", message) else: print ("Handle destroyed successfully")
下面是 我自己弄的半成品 有错误会报错 求助大佬帮忙修改下 大量金币奉上
|
|