pyvisauto - a vision-based automation tool
Project description
pyvisauto
pyvisauto is a Python visual automation tool. Inspired by Sikuli, pyvisauto provides Python-native easy-to-use abstractions for complex interactions with on-screen visual elements by wrapping OpenCV (specifically opencv-contrib-python-headless), pyautogui, pytesseract, and numpy.
Features include:
- OpenCV and numpy-driven image matching of on-screen elements
- TesseractOCR support
- Methods to find an image match (
find
), find all matches (find_all
), check if a match exists (exists
), wait until an image match occurs (wait
), and wait for an image match to disappear (wait_vanish
) - Methods to click and hover over regions and matches (
click
andhover
, respectively) with random x and y coordinates within the region - Sub-region and cached matching for faster performance
- Method to save screenshots of matches and regions to a file (
screenshot
)
Requirements
pyvisauto has been tested on Python 3.7. The opencv-contrib-python-headless
package limits availability to Python 2.7 and 3.4 ~ 3.7. While pyvisauto should be compatible with Python 3, Python 3.8 is currently not supported.
Installation and Usage
- Install OS-specific dependencies:
- Windows: No extra dependencies needed
- Linux:
python3-xlib
- OSX:
pyobjc-core
andpyobjc
, in that order
- Install pyvisauto using pip:
pip install pyvisauto
- Import pyvisauto:
import pyvisauto
- Read the Quick Start and API docs
Quick Start
-
Define a full-screen region and assign it to
r
:r = pyvisauto.Region()
-
Define a region with the upper-left corner at x: 50px and y: 100px, with a width of 500px and height of 300px and assign it to
r
:r = pyvisauto.Region(50, 100, 500, 300)
-
Find the image
asset1.png
in the defined region, with a similarity score of 0.9:match1 = r.find('asset1.png', 0.8)
-
If there has been no visual changes in the defined region, subsequent
find
actions can be expedited by passing incached=True
:match2 = r.find('asset2.png', 0.9, cached=True)
-
find_all
andexists
can be used in a similar fashion asfind
. -
Hover over a random point in the first returned match:
match1.hover()
-
Click a random point in the second returned match:
match2.click()
-
One can use
wait
andvanish
to wait for on-screen changes, detected by the presence or disappearance of an image on-screen, respectively:r.wait('wait_asset1.png', 30, 0.8)
The above code will wait for
wait_asset1.png
in the previously defined regionr
, with a minimum similarity score of 0.8, waiting a maximum of 30 seconds before throwing aFindFailed
exception.vanish
, on the other hand, throws aVanishFailed
exception. Both exceptions are defined in thepyvisauto
module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyvisauto-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 768bc48e6ae389e43535d1e7a7f503ab3e099b1b78f5d08cbab451bd7a66142c |
|
MD5 | ea27d3c03e903c12525a56d4a60af034 |
|
BLAKE2b-256 | 16e80b52443bc9e16166429b149f8d28f492e66838aa4bed4a1f4efbe4d69713 |