-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (106 loc) · 4.57 KB
/
Copy pathmain.py
File metadata and controls
121 lines (106 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import pyautogui
import cv2
import random
import numpy as np
import math
from bresenham import bresenham
import os
def find_controls(template, source_image):
source_image = cv2.imread(source_image, 0) # Reads image in color
template = cv2.imread(template, 0)
w, h = template.shape[::-1]
# apply template matching
res = cv2.matchTemplate(source_image, template, cv2.TM_SQDIFF)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = min_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
# Calculate the center:
center = (int((top_left[0] + bottom_right[0]) / 2), int((top_left[1] + bottom_right[1]) / 2))
return center
def get_RGB_from_Image(point,img):
x = point[0]
y = point[1]
# pixel_b, pixel_g, pixel_r = image[row][column]
RGB_from_image = {'red': img.item(y,x,2), 'green':img.item(y,x,1),'blue':img.item(y,x,0)}
return RGB_from_image, x, y
def edit_RGB_values (edit_colors,RGB_locations,okLocation,RGB):
# print(RGB_locations[key]) #<--- this points to the insert locations
pyautogui.moveTo(edit_colors)
pyautogui.click()
for eachColor in RGB_locations:
pyautogui.moveTo(RGB_locations[eachColor])
pyautogui.click(clicks=2)
pyautogui.press('backspace')
pyautogui.typewrite(str(RGB[eachColor]))
pyautogui.moveTo(okLocation)
pyautogui.click()
def drawlines(x1, y1):
pixelsDrawn = []
r = 10
x1 = int(start_point[0] + x1)
y1 = int(start_point[1] + y1)
# Use parametric equations
t_degree = random.randint(0,360)
t_radians = math.radians(t_degree)
x2 = x1 + int(r*(math.cos(t_radians)))
y2 = y1 + int(r*(math.sin(t_radians)))
pyautogui.moveTo(x1, y1)
pyautogui.dragTo(x2, y2, button='left')
pixelsDrawn = pixelsDrawn + (list(bresenham(x1, y1, x2, y2)))
stepsize = 2 # moves over 2 pixels
miniRsum = 0
while(miniRsum < r):
x1 = x1 + int(stepsize*(math.cos(t_radians+(math.pi/2))))
y1 = y1 + int(stepsize*(math.sin(t_radians+(math.pi/2))))
x2 = x1 + int(r * (math.cos(t_radians)))
y2 = y1 + int(r * (math.sin(t_radians)))
miniRsum = miniRsum + stepsize
pyautogui.moveTo(x1, y1)
pyautogui.dragTo(x2, y2, button='left')
pixelsDrawn = pixelsDrawn + (list(bresenham(x1, y1, x2, y2)))
no_duplicate_list = []
#Removes all duplicates in the list.
for x in pixelsDrawn:
if x not in no_duplicate_list:
no_duplicate_list.append(x)
#[no_duplicate_list.append(x) for x in pixelsDrawn if x not in no_duplicate_list]
return no_duplicate_list
if __name__== "__main__":
# Calibrate #Height = img.shape[0] , Width = img.shape[1]
mainImg = cv2.imread('landscape.jpg', cv2.IMREAD_COLOR)
maxWidth = 800
maxHeight = 600
scaling_factors = np.arange(1, 0, -0.001).tolist()
for i in scaling_factors:
if mainImg.shape[1] > maxWidth or mainImg.shape[0] > maxHeight:
mainImg = cv2.resize(mainImg, (0, 0), fx=i, fy=i)
else:
break;
imageWidth = mainImg.shape[1]
imageHeight = mainImg.shape[0]
start_point = (54, 261)
os.system("Start /max mspaint")
edit_colors = find_controls('edit_color.png', 'homescreen.png') # 64x126 | 1920x1080
RGB_locations = {'red':find_controls('red.PNG', 'edit_colors_window.png'),
'green':find_controls('green.PNG', 'edit_colors_window.png'),
'blue':find_controls('blue.PNG', 'edit_colors_window.png')}
ok_button = find_controls('ok.png', 'edit_colors_window.png')
chooselist = [] #Creates a list of pixels from the image dimensions
for i in range(0,imageWidth):
for j in range(0,imageHeight):
chooselist.append((i,j))
#print("Array created: \n", chooselist)
while(len(chooselist) > 0):
randomPoint = random.choice(chooselist)
RGBFromImage, randomX, randomY = get_RGB_from_Image(randomPoint,mainImg)
edit_RGB_values(edit_colors, RGB_locations, ok_button, RGBFromImage)
pixelsToDelete = drawlines(randomX, randomY)
#Normalizes points back to image pixels.
for i in range(len(pixelsToDelete)):
#Performs tuple list substraction.
pixelsToDelete[i] = tuple(np.subtract((pixelsToDelete[i][0],pixelsToDelete[i][1]),(54,261)))
#This removes drawn pixels from the origial list.
for pixel in pixelsToDelete:
if(pixel in chooselist):
chooselist.remove(pixel)