Skip to main content

A library used to do image recognition.

Project description

# RobotFramework-ImageRobot

  • [Updates](#updates)

  • [Introduction](#introduction)

  • [Requirements](#requirements)

  • [Image recognition](#image-recognition)

  • [Installation](#installation)

  • [Window focus](#window-focus)

  • [Mouse control](#mouse-control)

  • [Keyboard input](#keyboard-input)

## Now available on PyPI

Just use pip to install the package:

python -m pip install ImageRobot

You no longer need to copy nor clone the repository to get the package.

## Updates

  • Add “position” parameter to make it easier to click / move the mouse

  • Add new method “set_region_around_position”

  • Add region parameter to set_region_method()

  • Improve location when using set_region() method

## Introduction

The purpose of this module is to bring to Robot Framework user a way to do image recognition. This module has been created in 4 different parts: - Image recognition - Window focus - Mouse control - Keyboard input

With this module you will be able to do the basics of image recognition using Robot Framework.

The functions for the mouse control and the keyboard input are mostly wrapers from other libraries.

## Requirements

Python version: 3.6+

Modules required: - keyboard - numpy - opencv-python - pyautogui - pygetwindow - robotframework

## Installation

It can simply be installed using pip once the project has been cloned or downloaded:

python -m pip install ImageRobot

## Image recognition

Image recognition example in Robot Framework:

${img}= BuiltIn.Set Variable .${/}google.png ${pos}= ImageRobot.Search Image ${img}

In this example, your Robot will look for the image at the path “./google.png” and return the position on the screen where the image has been found.

If the image may appear because the loading takes time, you can use the “wait_until_image_appear” function which will wait a certain amount of time before going in timeout. Example:

${img}= BuiltIn.Set Variable .${/}google.png ${pos}= ImageRobot.Wait Until Image Appear ${img} timeout=30

If the image has not been found in the next 30 seconds, the Robot will show a failure message telling that it did not happen. Otherwise the “pos” variable will get the position of the image found.

You can highlight the image you are looking for with the “highlight image” function. If the image is found multiple times, it will draw a rectangle arround each.

ImageRobot.Highlight Image ${img}

This function will save the image on the disk. If too many screenshots already exist, it will throw an error telling to clean the repository. It happens when there is 999 screenshots in the repository from where the robot is launched.

If you need to find an image in a specific region, in order to optimize performance you can use the “set region” function. The screenshot will be taken for only the part until it has been released with “release region”.

ImageRobot.Set Region 0 0 500 500 ImageRobot.Highlight Image ${img} ImageRobot.Release Region

This sequence will try to find and highlight the image in the upper-left region of the screen. Then it releases the region so next searchs will be done on the whole screen.

## Window focus

The Focus class gives you a tool to select specific windows and do action on it. Once the window has been set in focus, it is possible to put it foreground, minimize, maximize and restore it. Example:

ImageRobot.Focus Window Containing Firefox ImageRobot.Restore Window ImageRobot.Maximize Window

This sequence will check if a window containing “Firefox” in the name is found. If so it will create a focus on it Then we restore the window. It means that if the window has been reduced in the desk bar, it will show it up again. Finaly the Robot maximize the window making it full screen as if you clicked the maximize button.

## Mouse control

The Mouse class gives you some functions dedicated to mouse control. You can find the classics “Click Position” - to click at specific coordinates -, “Click Image” - to click on an image if the image has been found -, “Move Cursor To Position” - to move the cursor at specific coordinates - and so on.

If you use the click image without giving a timestamp, you will not see the cursor move before the click.

Even if the “Set Region” function has been used, the mouse will not use it. So it is preferable to use a sequence of actions like the example above:

ImageRobot.Set Region 0 0 960 1080 ${pos}= ImageRobot.Search Image ${img} center=True BuiltIn.Run Keyword If ${pos}[0] != -1 ImageRobot.Click Position ${pos}[0] ${pos}[1] ImageRobot.Release Region

With the “Set Region” we cut the left half part of a screen width 1920 * 1080. We search in this cut part. If the value returned is different than “-1”, it means the image has been found so we can click at the position returned. Finally we release the region set.

## Keyboard input

The Keyboard class gives you some functions dedicated to keyboard control. The classic functions are available like the “Input Text” function. It does not need any locator to be used. There is also a function named “Execute Hotkey” which gives the user a tool to use hotkeys. Example :

ImageRobot.Execute Hotkey ctrl+shift+escape

This line will open the task manager.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ImageRobot-1.3.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ImageRobot-1.3.2-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file ImageRobot-1.3.2.tar.gz.

File metadata

  • Download URL: ImageRobot-1.3.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.0

File hashes

Hashes for ImageRobot-1.3.2.tar.gz
Algorithm Hash digest
SHA256 cf6461cb7c5a0f34cba85aa30c89a31de8b302b4212e287f994d5e92aa0f003a
MD5 876a6c3758d7feef598128bd0106fc44
BLAKE2b-256 d785dbb4fc8b7b4fb142b9035b7dd4f0a92c7861eddb2609669b369db6ffc59c

See more details on using hashes here.

File details

Details for the file ImageRobot-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: ImageRobot-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.0

File hashes

Hashes for ImageRobot-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e146cac6c887661bf90bcc2d7309f74ad6c9e209922a5828ec6c135c788aba74
MD5 d861d3be2bfecb7f3de3bafb5c5e89b3
BLAKE2b-256 e537fc95994d6f5d9ac10eccae74f83c071d37fdd476ae44f381988a21c4d65e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page