Last active
May 25, 2022 03:15
-
-
Save wonsolution/eb86b29b05d84af0cb4078b400f6648b to your computer and use it in GitHub Desktop.
Python openCV macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui | |
import cv2 | |
import numpy as np | |
pyautogui.screenshot('seat.png', region=(90,220,530,400)) | |
#pyautogui.screenshot('full.png') #풀스크린샷 | |
#pyautogui.screenshot('저장위치 및 파일 명', region=(캡쳐시작x좌표,캡쳐시작y좌표,캡쳐끝x,캡쳐끝y)) | |
img_seat = cv2.imread('seat.png') | |
seat_r = cv2.imread('VIP_R.png') | |
w, h = template.shape[:-1] | |
res = cv2.matchTemplate(img_seat, seat_r, cv2.TM_CCOEFF_NORMED) | |
threshold = 0.7 | |
loc = np.where(res >= threshold) | |
seat_rPt = (0,0) | |
for pt in zip(*loc[::-1]): # Switch collumns and rows | |
print (pt) | |
seat_rPt = pt | |
cv2.rectangle(img_seat, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) | |
break | |
cv2.imwrite('result.png', img_seat) | |
x = seat_rPt[0] + 93 | |
y = seat_rPt[1] + 223 | |
seat_rPt1 = (x,y) | |
print(seat_rPt1) | |
pyautogui.click(seat_rPt1) | |
print('좌석 선택') | |
#좌석 선택 확인하기 | |
pyautogui.screenshot('seatC.png', region=(90,220,530,400)) | |
img_seat = cv2.imread('seatC.png') | |
seat_r = cv2.imread('R_check.png') | |
w, h = template.shape[:-1] | |
res = cv2.matchTemplate(img_seat, seat_r, cv2.TM_CCOEFF_NORMED) | |
threshold = 0.8 | |
loc = np.where(res >= threshold) | |
seat_rPt = (0,0) | |
for pt in zip(*loc[::-1]): # Switch collumns and rows | |
print (pt) | |
seat_rPt = pt | |
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) | |
break | |
cv2.imwrite('result.png', img_seat) | |
x = seat_rPt[0] + 93 | |
y = seat_rPt[1] + 223 | |
seat_rPt1 = (x,y) | |
print(seat_rPt1) | |
print('선택확인') | |
pyautogui.moveTo(750,630,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip 버전확인 | |
>>>pip --version | |
pip업그레이드(upgrade) -ver.window | |
>>> python -m pip install --upgrade pip | |
python Opencv install | |
>>>python -m pip install opencv-python | |
python opencv설치확인 | |
import cv2 | |
numpy install | |
>>>pip install numpy | |
numpy upgrade | |
>>>pip install numpy --upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui, sys | |
from time import sleep | |
import pyperclip | |
import cv2 | |
import numpy as np | |
pyautogui.click(808,1420) | |
sleep(1) | |
print('창 열기') | |
# 드래그를 해야될 경우 | |
# pyautogui.dragTo(1834, 80, button='left') #드래그 시작 할 위치 | |
# pyautogui.dragTo(1081, 76, 1, button='left') #드래그 이동 할 위치 | |
# print('좌표 0,0으로 이동') | |
pyautogui.click(1154,488) | |
print('검색창 클릭') | |
pyautogui.typewrite('http://ticket.interpark.com/') | |
pyautogui.press('enter') | |
sleep(3) | |
print('인터파크 티켓 이동') | |
pyautogui.click(1239,264) | |
sleep(2) | |
print('로그인 클릭') | |
pyautogui.click(1032,706) | |
sleep(2.2) | |
print('카카오톡 로그인 클릭-자동로그인으로 아이디, 비번 입력 안해도 됨.') | |
pyautogui.click(1078,335) | |
sleep(0.5) | |
print('인터파크 티켓 검색 클릭') | |
pyperclip.copy("마리퀴리") | |
pyautogui.hotkey("ctrl","v") | |
pyautogui.press('enter') | |
print('마리퀴리 검색') | |
sleep(2) | |
pyautogui.click(1589,652) | |
sleep(2.5) | |
print('예매하기 클릭') | |
pyautogui.click(1493,615) | |
sleep(1) | |
print('공연일자 클릭') | |
pyautogui.click(1551,665) | |
sleep(1) | |
pyautogui.click(1551,725) | |
sleep(1) | |
print('회차 선택') | |
pyautogui.click(1608,799) | |
print('예매하기 클릭') | |
sleep(3) | |
pyautogui.click(673,289) | |
print('닫기 클릭') | |
sleep(1) | |
pyautogui.screenshot('seat.png', region=(90,220,530,400)) | |
img_rgb = cv2.imread('seat.png') | |
template = cv2.imread('VIP_R.png') | |
w, h = template.shape[:-1] | |
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED) | |
threshold = 0.7 | |
loc = np.where(res >= threshold) | |
temppt = (0,0) | |
for pt in zip(*loc[::-1]): # Switch collumns and rows | |
print (pt) | |
temppt = pt | |
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) | |
break | |
cv2.imwrite('result.png', img_rgb) | |
a = temppt[0] + 93 | |
b = temppt[1] + 222 | |
temppt1 = (a,b) | |
print(temppt1) | |
pyautogui.click(temppt1) | |
print('좌석 선택') | |
#좌석 선택 확인하기 | |
pyautogui.screenshot('seatC.png', region=(90,220,530,400)) | |
img_seat = cv2.imread('seatC.png') | |
seat_r = cv2.imread('R_check.png') | |
w, h = template.shape[:-1] | |
res = cv2.matchTemplate(img_seat, seat_r, cv2.TM_CCOEFF_NORMED) | |
threshold = 0.8 | |
loc = np.where(res >= threshold) | |
seat_rPt = (0,0) | |
for pt in zip(*loc[::-1]): # Switch collumns and rows | |
print (pt) | |
seat_rPt = pt | |
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) | |
break | |
cv2.imwrite('result.png', img_seat) | |
x = seat_rPt[0] + 91 | |
y = seat_rPt[1] + 220 | |
seat_rPt1 = (x,y) | |
print(seat_rPt1) | |
print('선택확인') | |
pyautogui.click(750,630) | |
print('예매하기 클릭') | |
pyautogui.moveTo(597,225,1) | |
pyautogui.click() | |
pyautogui.moveTo(597,258,1) | |
pyautogui.click() | |
print('일반 1매 선택') | |
pyautogui.click(819,627) | |
print('다음 단계') | |
sleep(1) | |
pyautogui.click(422,220) | |
pyperclip.copy(" ") # <-빈칸에 본인의 생년월일(yymmdd)을 입력해주세요 | |
pyautogui.hotkey("ctrl","v") | |
print('생년월일 입력') | |
pyautogui.click(819,627) | |
print('다음 단계') | |
pyautogui.moveTo(61,270,1) | |
pyautogui.click() | |
print('무통장입금 선택') | |
pyautogui.moveTo(486,260) | |
pyautogui.click() | |
pyautogui.moveTo(486,375,1) | |
pyautogui.click() | |
print('우체국 선택') | |
pyautogui.click(819,627) | |
print('다음 단계') | |
pyautogui.moveTo(57,476,1) | |
pyautogui.click() | |
pyautogui.click(364,476) | |
print('동의 유무') | |
pyautogui.click(819,627) | |
print('결제하기') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment