레이블이 imagesearch인 게시물을 표시합니다. 모든 게시물 표시
레이블이 imagesearch인 게시물을 표시합니다. 모든 게시물 표시

2019년 12월 17일 화요일

How to implement Autohotkey's imeagesearch function in Python

Hello everyone. For Work automation, Python!
So today we will learn how to implement Autohotkey's imeagesearch functionality in Python.

First, download imagesearch.py from drov0's Github. And put imeagesearch.py in py file's path to be created.
(https://github.com/drov0/python-imagesearch)

Click the [Clone or download] button, You will get imagesearch.py

Second, install following libraries. Run Python in the location of requirements.txt in the downloaded folder and proceed with pip3 install -r requirements.txt. The best thing to do is to install it through Anaconda and proceed with the installation of additional libraries.

Required libraries
- opencv-python
- numpy
- python3_xlib
- pyautogui

If do perfectly, preparation is completed!

Now put the image file you want to find in the path. Let's design a program that clicks on the Google logo.

Google logo


As shown below, capture only a part of Google logo and put in path as google.png file.

Capture the red box and make it a png file


Then write python file like below.

from imagesearch import *

img = './google_logo.png'
pos = imagesearch(img)
if pos[0] != -1:
    click_image(img, pos, 'left', 0.1)

Explanation

line 1 from imagesearch import *: imports imagesearch.py
line 3 img = './google_logo.png': Put the path of the image file you want to find in the variable img.
line 4 pos = imagesearch (img): Find the image file and insert the mouse coordinates in the variable pos.
line 5 if pos [0]! = -1: : If pos value is normal, excute.
line 6 click_image (img, pos, 'left', 0.1): Randomly clicks pos position within img size, having a 0.1 second mouse movement time.

Through your browser, open the Google logo window that looks like the image we have, and run that py file. If you recognize the image and click on the Google logo, it's a success!

Thank you.

Korean Language Version link is
(https://pyinweb.blogspot.com/2019/04/imagesearch.html)

2019년 4월 5일 금요일

파이썬으로 오토핫키의 imagesearch를 구현해보자!

안녕하세요? 업무 자동화 하면 바로 파이썬입니다!
그래서 오늘은 오토핫키의 imagesearch 기능을 파이썬에서 구현하는 방법을 알아볼까 합니다. 기대되시나요? 그러면 글을 차근차근히 읽어주시면 됩니다!


우선 drov0님의 Github에서 imagesearch.py를 받아줍니다. imagesearch.py는 만들 py파일 경로에 넣어주세요.
(https://github.com/drov0/python-imagesearch)

[Clone or download] 버튼을 클릭하면 imagesearch.py를 받을 수 있습니다.


그리고 아래의 라이브러리들을 설치해줍니다. 다운 받은 폴더의 requirements.txt가 있는 자리에서 파이썬을 실행시키신 후, pip3 install -r requirements.txt 명령어를 진행해주시면 됩니다. 가장 좋은 것은 Anaconda를 통해 설치하고, 추가적으로 필요한 라이브러리들을 설치하는 방법으로 진행해주실 것을 권합니다.

필요한 라이브러리
opencv-python
numpy
python3_xlib
pyautogui

그렇다면 준비는 모두 완료되었습니다.


이제 찾고싶은 이미지 파일을 경로에 넣어줍니다. 우선 구글 로고를 클릭하는 프로그램을 만들어봅시다.

구글 로고
아래 그림처럼 구글 로고의 일부부분만 캡처해서 google.png파일로 해당 경로에 넣어줍니다.
빨간색 박스 부분을 캡처해 png파일로 만든다.



그리고 python 파일을 아래와 같이 작성해봅니다.

from imagesearch import * 

img = './google_logo.png'
pos = imagesearch(img)
if pos[0] != -1:
    click_image(img, pos, 'left', 0.1)



설명

line 1 from imagesearch import * : imagesearch.py를 import해줍니다.
line 3 img = './google_logo.png' : 찾고 싶은 이미지 파일의 경로를 변수 img에 넣어줍니다.
line 4 pos = imagesearch(img) : 변수 pos에 이미지 파일을 찾은 후 마우스 좌표를 넣어줍니다.
line 5 if pos[0] != -1: : pos 값이 정상일 경우 실행합니다.
line 6 click_image(img, pos, 'left', 0.1) : pos위치를 img 크기 내에서 랜덤으로 클릭해줍니다. 0.1초의 마우스 이동시간을 갖습니다.

브라우저를 통해, 우리가 갖고 있는 이미지와 같은 구글 로고 창을 띄운 뒤, 해당 py파일을 실행해봅시다. 이미지를 인식해서 구글 로고를 클릭했다면, 성공입니다!

감사합니다.