Compare commits
34 Commits
c9081bd371
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eed550797 | |||
| cc9789c65c | |||
| d64b704274 | |||
| ed23f196a6 | |||
| b8abdb690b | |||
| 8d2aad34b2 | |||
| e70c7d2be9 | |||
| 5005670bd3 | |||
| b1fc655c0b | |||
| 9cc4018747 | |||
| 849aaf8e27 | |||
| 804f178fbf | |||
| c1eecfd567 | |||
| 99a2976b61 | |||
| cadcfe8103 | |||
| ab0def9115 | |||
| b24a835f18 | |||
| 0a15b57fe5 | |||
| a7d2a73b00 | |||
|
|
3d209ca811 | ||
|
|
01768dc115 | ||
| f32cbb8f2d | |||
| 7a539e301b | |||
| 00461177de | |||
| 7c6af4411b | |||
| c3e677ca0a | |||
| 332190394d | |||
| d3ace50341 | |||
| 8918683e5a | |||
| b08356b036 | |||
| ffca884a25 | |||
| d3d2e1e65e | |||
| 6ec1b71d28 | |||
| 07d00404d8 |
@@ -10,7 +10,7 @@ from config_file import UserConfigs
|
||||
# load the original input image and display it to our screen
|
||||
|
||||
#filename = "equip/chests/chest_23_32"
|
||||
path = "equip/wands/"
|
||||
path = "flappy/"
|
||||
os.chdir(path)
|
||||
|
||||
for entry in os.listdir():
|
||||
|
||||
@@ -112,6 +112,9 @@ class Equipment(GameBase):
|
||||
|
||||
spawn_1 = self.find_emitter(emitter, screenshot, 1)
|
||||
if len(spawn_1) == 1:
|
||||
#output_by_area = self.vision_stun.draw_rectangles(screenshot, spawn_1)
|
||||
#cv.imshow("spawn_1", output_by_area)
|
||||
#cv.waitKey(150)
|
||||
points = self.vision_stun.get_click_points(spawn_1)
|
||||
for i in range(0, self.SPAWN_COUNT, 1):
|
||||
self.click_point(points[0][0], points[0][1])
|
||||
@@ -316,7 +319,7 @@ class Equipment(GameBase):
|
||||
else:
|
||||
needle = cv.imread("equip/emitters/ring_e2_32.jpg", cv.IMREAD_UNCHANGED)
|
||||
mask = cv.imread("equip/emitters/ring_e2_32-mask.png", cv.IMREAD_COLOR)
|
||||
return self.vision_stun.find(screen, needle, 0.95, 1, True, mask)
|
||||
return self.vision_stun.find(screen, needle, 0.95, 1, False, mask)
|
||||
elif emitter_to_use == EMITTER_WAND:
|
||||
if layer == 0:
|
||||
needle = cv.imread("equip/emitters/wand_e1_32.jpg", cv.IMREAD_UNCHANGED)
|
||||
|
||||
24
field.py
@@ -14,7 +14,6 @@ class Field():
|
||||
else:
|
||||
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||
for rows in range(Field.HEIGHT)]
|
||||
#self.rotate_90_degree_clckwise(self.state)
|
||||
self.cleared_rows = 1
|
||||
|
||||
def __str__(self):
|
||||
@@ -24,7 +23,8 @@ class Field():
|
||||
'{:2d} |'.format(i) + ' '.join(row) + '|'
|
||||
for i, row in enumerate(self.state)]) + '\n' + BAR
|
||||
|
||||
def matrixflip(self, m, d):
|
||||
@staticmethod
|
||||
def matrixflip(m, d):
|
||||
tempm = m.copy()
|
||||
if d == 'h':
|
||||
for i in range(0, len(tempm), 1):
|
||||
@@ -33,14 +33,16 @@ class Field():
|
||||
tempm.reverse()
|
||||
return (tempm)
|
||||
|
||||
def rotate_90_degree_anticlckwise(self, matrix):
|
||||
@staticmethod
|
||||
def rotate_90_degree_anticlckwise(matrix):
|
||||
new_matrix = []
|
||||
for i in range(len(matrix[0]), 0, -1):
|
||||
new_matrix.append(list(map(lambda x: x[i - 1], matrix)))
|
||||
|
||||
return new_matrix
|
||||
|
||||
def rotate_90_degree_clckwise(self, matrix):
|
||||
@staticmethod
|
||||
def rotate_90_degree_clckwise(matrix):
|
||||
new_matrix = []
|
||||
for i in range(len(matrix[0])):
|
||||
li = list(map(lambda x: x[i], matrix))
|
||||
@@ -58,9 +60,8 @@ class Field():
|
||||
self.state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||
|
||||
def rotate_state(self):
|
||||
self.state = self.rotate_90_degree_anticlckwise(self.state)
|
||||
#self.state = self.matrixflip(self.state, 'v')
|
||||
#print(self.state)
|
||||
self.state = Field.rotate_90_degree_anticlckwise(self.state)
|
||||
|
||||
|
||||
def get_line_count(self):
|
||||
return self.cleared_rows
|
||||
@@ -151,11 +152,14 @@ class Field():
|
||||
|
||||
|
||||
|
||||
def check_crucial_pos_to_be_free(self):
|
||||
if self.state[19][9] == ' ' and self.state[19][10] == ' ' and self.state[18][9] == ' ' and self.state[18][10] == ' ':
|
||||
return True
|
||||
return False
|
||||
|
||||
def predict_gaps_in_next_rotation(self):
|
||||
tmp_state = copy(self.state)
|
||||
tmp_state = self.rotate_90_degree_anticlckwise(tmp_state)
|
||||
if tmp_state[10][0] is not ' ' and tmp_state[10][1] is not ' ':
|
||||
return 10
|
||||
tmp_state = Field.rotate_90_degree_anticlckwise(tmp_state)
|
||||
for row in range(int(self.HEIGHT/2)):
|
||||
tmp_state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||
return sum(
|
||||
|
||||
25
flappy.py
@@ -2,6 +2,7 @@ import cv2 as cv
|
||||
import pydirectinput
|
||||
from game_base_class import GameBase
|
||||
from flappy_pos_discovery_thread import FlappyPosDiscovery
|
||||
from keyboard_thread import KeyboardEvent
|
||||
|
||||
class Flappy(GameBase):
|
||||
|
||||
@@ -11,18 +12,25 @@ class Flappy(GameBase):
|
||||
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
|
||||
|
||||
self.flappy_pos_disc = FlappyPosDiscovery()
|
||||
self.keyboard_listener = KeyboardEvent()
|
||||
|
||||
def assess_playfield_and_make_move(self):
|
||||
#last_letter_received = time()
|
||||
wait_timer = 380
|
||||
|
||||
while True:
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
return
|
||||
wait_timer = 380 + self.keyboard_listener.offset_value
|
||||
self.click()
|
||||
cv.waitKey(wait_timer)
|
||||
'''
|
||||
if self.flappy_pos_disc.next_gate_height[0] is not 0:
|
||||
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.get_actual_pet_height()
|
||||
if offset > 50:
|
||||
self.click()
|
||||
cv.waitKey(int(wait_timer -100))
|
||||
print("pet_pos: ", self.flappy_pos_disc.get_actual_pet_height())
|
||||
|
||||
pydirectinput.mouseDown()
|
||||
cv.waitKey(50)
|
||||
pydirectinput.mouseUp()
|
||||
cv.waitKey(int(wait_timer))
|
||||
if self.flappy_pos_disc.next_gate_height[0] is not 0:
|
||||
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.current_pet_height
|
||||
if offset > 50:
|
||||
@@ -33,4 +41,9 @@ class Flappy(GameBase):
|
||||
wait_timer = 380 + offset
|
||||
print(wait_timer)
|
||||
print("pet_pos: ", self.flappy_pos_disc.current_pet_height)
|
||||
print("next gate: ", self.flappy_pos_disc.next_gate_height[0] + 120)
|
||||
print("next gate: ", self.flappy_pos_disc.next_gate_height[0] + 120) '''
|
||||
|
||||
def click(self):
|
||||
pydirectinput.mouseDown()
|
||||
cv.waitKey(50)
|
||||
pydirectinput.mouseUp()
|
||||
@@ -20,7 +20,7 @@ class FlappyPosDiscovery(threading.Thread):
|
||||
self.mask_g = self.scale_picture(cv.imread("flappy/gate-mask.png"), 50)
|
||||
|
||||
self.run_mode = 'run'
|
||||
self.current_pet_height = 0
|
||||
self.current_pet_height = []
|
||||
self.next_gate_height = [0,0,0]
|
||||
|
||||
self.offset_down = 90
|
||||
@@ -51,7 +51,9 @@ class FlappyPosDiscovery(threading.Thread):
|
||||
pass
|
||||
|
||||
if len(rectangles_f) is not 0:
|
||||
self.current_pet_height = rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down
|
||||
self.current_pet_height.append(rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down)
|
||||
if len(self.current_pet_height) > 5:
|
||||
self.current_pet_height.pop(0)
|
||||
|
||||
#print("pet_pos: ", self.current_pet_height)
|
||||
#print("next gate: ", self.next_gate_height)
|
||||
@@ -68,7 +70,8 @@ class FlappyPosDiscovery(threading.Thread):
|
||||
return thresh
|
||||
|
||||
def get_actual_pet_height(self):
|
||||
return self.current_pet_height
|
||||
return sum(self.current_pet_height) / len(self.current_pet_height)
|
||||
|
||||
|
||||
def get_next_gate_height(self):
|
||||
return self.next_gate_height
|
||||
|
||||
32
keyboard_thread.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import threading
|
||||
import cv2 as cv
|
||||
import keyboard
|
||||
|
||||
|
||||
class KeyboardEvent(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
self.run_mode = 'run'
|
||||
self.offset_value = 0
|
||||
self.start()
|
||||
def run(self):
|
||||
while self.run_mode == 'run':
|
||||
if keyboard.is_pressed('up'): # if key 'q' is pressed
|
||||
self.offset_value = -75
|
||||
elif keyboard.is_pressed('down'):
|
||||
self.offset_value = 75
|
||||
elif keyboard.is_pressed('left') or keyboard.is_pressed('right'):
|
||||
self.offset_value = 0
|
||||
cv.waitKey(10)
|
||||
|
||||
def callback(self):
|
||||
pass
|
||||
|
||||
def destroy(self):
|
||||
self.destroy()
|
||||
|
||||
def get_run_mode(self):
|
||||
return self.run_mode
|
||||
|
||||
71
litris.py
@@ -1,3 +1,5 @@
|
||||
from copy import copy
|
||||
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
from time import time
|
||||
@@ -25,14 +27,27 @@ class Litris(GameBase):
|
||||
self.stone_id_thread = NewStoneID()
|
||||
|
||||
self.move_mode = 1
|
||||
self.moved_around_full = False
|
||||
|
||||
self.field_state_storage = {
|
||||
1: self.field,
|
||||
2: self.field,
|
||||
3: self.field,
|
||||
4: self.field
|
||||
}
|
||||
|
||||
def reset(self):
|
||||
self.field.reset_field()
|
||||
self.field.cleared_rows = 1
|
||||
self.move_mode = 1
|
||||
self.moved_around_full = False
|
||||
|
||||
def assess_playfield_and_make_move(self):
|
||||
last_letter_received = time()
|
||||
while True:
|
||||
if self.stone_id_thread.get_pick_up_status() == False:
|
||||
if (time() - last_letter_received) >= 5:
|
||||
self.field.reset_field()
|
||||
self.field.cleared_rows = 1
|
||||
self.reset()
|
||||
last_letter_received = time()
|
||||
self.dig_point(1500, 980, 100)
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
@@ -40,7 +55,7 @@ class Litris(GameBase):
|
||||
continue
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
return
|
||||
cv.waitKey(50)
|
||||
cv.waitKey(25)
|
||||
continue
|
||||
|
||||
|
||||
@@ -70,24 +85,46 @@ class Litris(GameBase):
|
||||
self.move_stone(column - offset_col, rotation)
|
||||
self.drop_down()
|
||||
print(self.field)
|
||||
if self.field.get_line_count() >= 6 and self.field.height() <= 2:
|
||||
if self.field.predict_gaps_in_next_rotation() <= 5:
|
||||
if self.field.get_line_count() >= 6 and self.field.height() <= 2 and self.field.check_crucial_pos_to_be_free():
|
||||
if self.field.predict_gaps_in_next_rotation() <= 3:
|
||||
self.field_state_storage[self.move_mode] = copy(self.field)
|
||||
self.update_move_mode()
|
||||
self.field = self.stone_id_thread.get_current_board_state()
|
||||
#self.field.state = self.stone_id_thread.get_current_board_state()
|
||||
self.field.rotate_state()
|
||||
#self.update_move_mode()
|
||||
self.field.reset_half_field()
|
||||
self.update_field_with_stored_edges()
|
||||
#field_mem = copy(self.field)
|
||||
#self.field = copy(self.field_mem)
|
||||
#self.field_mem = copy(field_mem)
|
||||
|
||||
self.field.cleared_rows = 1
|
||||
|
||||
cv.waitKey(200)
|
||||
cv.waitKey(100)
|
||||
self.stone_id_thread.set_pick_up_status(False)
|
||||
|
||||
|
||||
|
||||
def update_field_with_stored_edges(self):
|
||||
if self.move_mode == 1 and self.moved_around_full:
|
||||
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[2].state))
|
||||
for i in range(11,20,1):
|
||||
for e in range(0,2,1):
|
||||
self.field.state[i][e] = state_copy[i][e]
|
||||
elif self.move_mode == 2 and self.moved_around_full:
|
||||
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[3].state))
|
||||
for i in range(11,20,1):
|
||||
for e in range(0,2,1):
|
||||
self.field.state[i][e] = state_copy[i][e]
|
||||
elif self.move_mode == 3 and self.moved_around_full:
|
||||
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[4].state))
|
||||
for i in range(11, 20, 1):
|
||||
for e in range(0, 2, 1):
|
||||
self.field.state[i][e] = state_copy[i][e]
|
||||
elif self.move_mode == 4:
|
||||
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[1].state))
|
||||
for i in range(11,20,1):
|
||||
for e in range(0,2,1):
|
||||
self.field.state[i][e] = state_copy[i][e]
|
||||
self.moved_around_full = True
|
||||
|
||||
def drop_down(self):
|
||||
if self.move_mode == 1:
|
||||
@@ -110,7 +147,7 @@ class Litris(GameBase):
|
||||
self.keyboard.press(down)
|
||||
self.keyboard.release(down)
|
||||
print("drop down pressed:", down)
|
||||
cv.waitKey(50)
|
||||
cv.waitKey(40)
|
||||
|
||||
def update_move_mode(self):
|
||||
if self.move_mode <=3:
|
||||
@@ -143,13 +180,13 @@ class Litris(GameBase):
|
||||
self.keyboard.press(down)
|
||||
self.keyboard.release(down)
|
||||
print("direction pressed: ", down)
|
||||
cv.waitKey(120)
|
||||
cv.waitKey(60)
|
||||
|
||||
if rotation == 3:
|
||||
self.keyboard.press('e')
|
||||
self.keyboard.release('e')
|
||||
print("rotation 1 pressed: e")
|
||||
cv.waitKey(40)
|
||||
cv.waitKey(30)
|
||||
elif rotation == 2:
|
||||
self.keyboard.press('e')
|
||||
self.keyboard.release('e')
|
||||
@@ -163,28 +200,28 @@ class Litris(GameBase):
|
||||
self.keyboard.press('e')
|
||||
self.keyboard.release('e')
|
||||
print("rotation 3 pressed: e 1")
|
||||
cv.waitKey(20)
|
||||
cv.waitKey(30)
|
||||
self.keyboard.press('e')
|
||||
self.keyboard.release('e')
|
||||
print("rotation 3 pressed: e 2")
|
||||
cv.waitKey(20)
|
||||
cv.waitKey(30)
|
||||
self.keyboard.press('e')
|
||||
self.keyboard.release('e')
|
||||
print("rotation 3 pressed: e 3")
|
||||
cv.waitKey(20)
|
||||
cv.waitKey(30)
|
||||
|
||||
if col_movement < 0:
|
||||
for i in range(0, col_movement, - 1):
|
||||
self.keyboard.press(left)
|
||||
self.keyboard.release(left)
|
||||
print("move left 3 pressed:", left)
|
||||
cv.waitKey(40)
|
||||
cv.waitKey(30)
|
||||
else:
|
||||
for i in range(0, col_movement, 1):
|
||||
self.keyboard.press(right)
|
||||
self.keyboard.release(right)
|
||||
print("move right 3 pressed:", right)
|
||||
cv.waitKey(40)
|
||||
cv.waitKey(30)
|
||||
|
||||
def point_in_rect(self, point):
|
||||
for e in range(0, 20, 1):
|
||||
|
||||
@@ -29,7 +29,7 @@ class NewStoneID(threading.Thread):
|
||||
self.data_coordinates = np.zeros((20, 20), dtype=object)
|
||||
self.fill_data_coordinates()
|
||||
|
||||
self.needles = {1: cv.imread("litris/blue_needle.jpg", cv.IMREAD_UNCHANGED)}
|
||||
self.needles = {'Q': cv.imread("litris/blue_needle.jpg", cv.IMREAD_UNCHANGED)}
|
||||
|
||||
self.run_mode = 'run'
|
||||
self.actual_letter = ""
|
||||
@@ -76,7 +76,7 @@ class NewStoneID(threading.Thread):
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
screenshot = screenshot[580:845, 1148:1412]
|
||||
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16)
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles['Q'], 0.85, 16)
|
||||
if len(rectangles) == 0:
|
||||
return None
|
||||
|
||||
@@ -144,12 +144,13 @@ class NewStoneID(threading.Thread):
|
||||
# cv.imshow("screenshot", screenshot)
|
||||
# cv.waitKey(150)
|
||||
# continue
|
||||
data_coords = np.zeros((20, 20), dtype=object)
|
||||
#data_coords = np.zeros((20, 20), dtype=object)
|
||||
data_coords = np.full((20, 20), ' ', dtype=object)
|
||||
#field = Pickaxe_Field()
|
||||
for needle_key in self.needles.keys():
|
||||
#gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
|
||||
#thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.8, 100)
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.8, 200)
|
||||
if len(rectangles) == 0:
|
||||
continue
|
||||
points = self.vision_stun.get_click_points(rectangles)
|
||||
@@ -157,7 +158,7 @@ class NewStoneID(threading.Thread):
|
||||
for point in points:
|
||||
x, y = self.point_in_rect(point)
|
||||
if x is not None and y is not None:
|
||||
data_coords[x][y] = int(needle_key)
|
||||
data_coords[x][y] = needle_key
|
||||
#self.change_value(x, y, int(needle_key))
|
||||
# print(field.data_value_grid)
|
||||
# cv.circle(screenshot, points[0], 7, (0, 255, 0), -1)
|
||||
|
||||
@@ -4,6 +4,7 @@ import pydirectinput
|
||||
from nltk.corpus import words
|
||||
from pytesseract import pytesseract
|
||||
|
||||
import utils
|
||||
from utils import mse
|
||||
from game_base_class import GameBase
|
||||
import random
|
||||
@@ -87,7 +88,7 @@ class MentiWords(GameBase):
|
||||
|
||||
with open("menti_dic") as file:
|
||||
self.word_list = [line.rstrip() for line in file]
|
||||
self.word_list2 = words.words()
|
||||
#self.word_list2 = words.words()
|
||||
|
||||
def reset_lists(self):
|
||||
self.current_letters = []
|
||||
@@ -126,7 +127,7 @@ class MentiWords(GameBase):
|
||||
|
||||
#screenshot = cv.imread("menti_words/screenshot.jpg")
|
||||
screenshot = self.capture_window.get_screenshot()
|
||||
screenshot = screenshot[870:1270, 1080:1480]
|
||||
screenshot = utils.scale_screenshot(screenshot[870:1270, 1080:1480], 200, False)
|
||||
|
||||
#cv.imshow("screenshot", screenshot)
|
||||
#cv.waitKey(150)
|
||||
@@ -134,26 +135,35 @@ class MentiWords(GameBase):
|
||||
for needle_key in self.needles.keys():
|
||||
# gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
|
||||
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||
rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.85, 1)
|
||||
|
||||
thresh_needle = utils.scale_screenshot(self.needles[needle_key], 200, False)
|
||||
rectangles = self.vision_stun.find(screenshot, thresh_needle , 0.85, 2)
|
||||
#rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.95, 1 ,True, self.masks[needle_key])
|
||||
if len(rectangles) == 0:
|
||||
continue
|
||||
points = self.vision_stun.get_click_points(rectangles)
|
||||
for point in points:
|
||||
self.current_letters.append(needle_key)
|
||||
self.letter_coords[needle_key] = (int(point[0]/2), int(point[1]/2))
|
||||
'''
|
||||
cropped1 = self.vision_stun.draw_display_picture(screenshot, rectangles, 10)
|
||||
|
||||
#cropped1 = utils.scale_screenshot(cropped1)
|
||||
cv.imshow("cropped1", cropped1)
|
||||
cv.waitKey(150)
|
||||
text_1 = pytesseract.image_to_string(cropped1, lang='eng', config='--psm 6').strip()
|
||||
if str.isalpha(text_1):
|
||||
#cv.imshow("cropped1", cropped1)
|
||||
#cv.waitKey(150)
|
||||
points = self.vision_stun.get_click_points(rectangles)
|
||||
self.current_letters.append(text_1)
|
||||
self.letter_coords[text_1] = points[0]
|
||||
self.letter_coords[text_1] = points[0]'''
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
return
|
||||
|
||||
def possible_words(self, lwords, charSet):
|
||||
lst = []
|
||||
for word in lwords:
|
||||
if len(word) <= 2:
|
||||
if len(word) <= 1:
|
||||
continue
|
||||
flag = 1
|
||||
chars = self.charCount(word)
|
||||
|
||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
12
utils.py
@@ -61,18 +61,20 @@ def check_for_bl_line(line_item, black_list):
|
||||
return False
|
||||
|
||||
|
||||
def scale_screenshot(screenshot):
|
||||
scale_percent = 200 # percent of original size
|
||||
def scale_screenshot(screenshot, percent = 200, thresh_mode = True):
|
||||
scale_percent = percent # percent of original size
|
||||
width = int(screenshot.shape[1] * scale_percent / 100)
|
||||
height = int(screenshot.shape[0] * scale_percent / 100)
|
||||
dim = (width, height)
|
||||
resized_img = cv.resize(screenshot, dim, interpolation=4)
|
||||
|
||||
gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY)
|
||||
thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||
if thresh_mode:
|
||||
gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY)
|
||||
thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||
return thresh
|
||||
# cv.imshow("Tresh", thresh)
|
||||
# cv.waitKey(1000)
|
||||
return thresh
|
||||
return resized_img
|
||||
|
||||
|
||||
def save_line_item_npy_jpg(short_pic_list):
|
||||
|
||||