UWSCにてマクロを作成していましたが、今更UWSCも古いなと思い
興味があった Python へ自分が欲しいなと思った関数を移植してみました
もっと効率のいい関数はあるかもしれないので参考程度にお願いします
Note自体初心者の為、コードは残しますが、見づらかったらすいません
詳しく書きすぎると怒られるのでこの関数 + αで自動化等をくみ上げてください
何か追加でほしい関数や質問等があればコメントを頂ければ出来る限り対応します
import cv2
import subprocess
# Python版 chkimg関数
def chkimg(template_path, target_path, threshold=0.95):
template = cv2.imread(template_path)
target = cv2.imread(target_path)
result = cv2.matchTemplate(target, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= threshold:
return True
else:
return False
# 使用例
template_path = "template.png" # チェックする画像のテンプレート
target_path = "target.png" # チェック対象の画像
if chkimg(template_path, target_path, threshold=1):
print("画像が一致しました。")
else:
print("画像が一致しません。")
threshold=0.95 判定する値 0 ~ 1
UWSCと差はないくらいの動きをすると思いますので
探していた方は是非お試しください
戻り値にはTrueかFalseしか返しません
# 起動中のNoxデバイスIDを取得する関数
def get_running_nox_device_id():
nox_adb_process = subprocess.Popen(["nox_adb", "devices"], stdout=subprocess.PIPE, text=True)
nox_adb_output, _ = nox_adb_process.communicate()
# NoxデバイスIDを取得
lines = nox_adb_output.strip().split('\n')[1:] # ヘッダー行をスキップ
devices = []
for line in lines:
parts = line.split('\t')
if len(parts) == 2 and parts[1] == 'device':
devices.append(parts[0])
return devices
# 使用例
running_device_ids = get_running_nox_device_id()
if running_device_ids:
# 最初のデバイスIDを使用する場合
device_id = running_device_ids[0]
print(f"利用可能なNoxデバイスID: {running_device_ids}")
# nox_adbコマンドを送信する関数
def doscmd(command, shell=True):
try:
result = subprocess.run(command, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result
except subprocess.CalledProcessError as e:
return e
def adb(cmd):
return doscmd(cmd)
直接コマンドを投げれるように変更
DOS側に直接投げてもいいがわかりやすく ADB という関数にした
# 使用例
_cmd = nox_adb ・・・・・
adb(_cmd)