Add pytesseract OCR, click_text interact action, and interact verify endpoint
All checks were successful
python-syntax / syntax-check (push) Successful in 6s
All checks were successful
python-syntax / syntax-check (push) Successful in 6s
This commit is contained in:
@@ -35,6 +35,50 @@ def main():
|
||||
print("region:", payload["meta"]["region"])
|
||||
print("grid:", payload["meta"].get("grid", {}))
|
||||
|
||||
see_ocr = requests.post(
|
||||
f"{BASE_URL}/see",
|
||||
headers=headers,
|
||||
json={"screen": SCREEN, "ocr": True, "with_grid": False, "ocr_min_confidence": 40},
|
||||
timeout=30,
|
||||
)
|
||||
see_ocr.raise_for_status()
|
||||
ocr_items = see_ocr.json()["data"]["meta"].get("ocr", [])
|
||||
print("ocr_items:", len(ocr_items))
|
||||
|
||||
if ocr_items:
|
||||
label = ocr_items[0]["text"]
|
||||
click_text = requests.post(
|
||||
f"{BASE_URL}/interact",
|
||||
headers=headers,
|
||||
json={
|
||||
"screen": SCREEN,
|
||||
"action": {"action": "click_text", "click_text": {"text": label, "match": "exact", "occurrence": "first"}},
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
click_text.raise_for_status()
|
||||
click_data = click_text.json()["data"]
|
||||
target = click_data["resolved_target"]
|
||||
verify = requests.post(
|
||||
f"{BASE_URL}/interact/verify",
|
||||
headers=headers,
|
||||
json={
|
||||
"action": {"screen": SCREEN, "action": {"action": "click", "target": {"mode": "pixel", "x": target["x"], "y": target["y"]}}},
|
||||
"verify": {
|
||||
"type": "ocr_text_near_point",
|
||||
"text": label,
|
||||
"x": target["x"],
|
||||
"y": target["y"],
|
||||
"radius": 150,
|
||||
"screen": SCREEN,
|
||||
},
|
||||
"timeout_ms": 1500,
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
verify.raise_for_status()
|
||||
print("verify:", verify.json()["data"]["verified"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user