Skip to content

Instantly share code, notes, and snippets.

@sechiro
Created September 11, 2021 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sechiro/fe66a4e379ffc4160fbfbd593d81c92a to your computer and use it in GitHub Desktop.
Save sechiro/fe66a4e379ffc4160fbfbd593d81c92a to your computer and use it in GitHub Desktop.
Cookie ClickerでFortuneクッキー取得後の幸運のニュースを自動でクリックするスクリプト
import cv2
import numpy as np
import pyautogui
import time
def main():
s_filename = 'tabloid.png'
# Env: Raspberry OS chromium browser full screen mode on 1024px x 600px (7inch) display
# Trim tabloid area (include menu button)
s = pyautogui.screenshot(region=(324, 166, 368, 100))
s.save(s_filename)
# HSV range for fortune dark green text
# OpenCV uses H: 0-179, S: 0-255, V: 0-255
HSV_MIN = np.array([35, 200, 200])
HSV_MAX = np.array([50, 255, 255])
# read screen shot
img = cv2.imread(f'./{s_filename}')
# convert to hsv
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# create bin image devided by text color
bin_image = cv2.inRange(img_hsv, HSV_MIN, HSV_MAX)
# get dark green text positions
num_labels, label_image, stats, center = cv2.connectedComponentsWithStats(bin_image)
# first point is the background, second point is a dark green text region
if( len(stats) > 1 ):
x = stats[1][0]
y = stats[1][1]
print(x, y)
# move mouse pointer to text
pyautogui.moveTo(324 + x + 10, 166 + y + 10)
pyautogui.click()
# save bin image for testing
cv2.imwrite("bin_image.jpg", bin_image)
if __name__ == "__main__":
while(True):
main()
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment