forked from AdriaGual/marvel-snap-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.py
44 lines (40 loc) · 1.7 KB
/
fields.py
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
from utils import global_utils
import os
import cv2
import config
import random
import logging
# Given a screenshot, returns a list of the detected fields
def get_fields(screenshot, screenshot_dimensions, show_image):
start = global_utils.start_timer()
fields = config.fields
for field in fields.keys():
fields[field]['image'] = screenshot[
fields[field]['x1']:
screenshot_dimensions[0] - fields[field]['x2'],
fields[field]['y1']:
screenshot_dimensions[1]-fields[field]['y2']
]
for available_field in os.listdir(config.fields_folder):
# Searching for a field in the folder.
searched_field = global_utils.search(
config.fields_folder+"\\"+available_field, fields[field]['image'])
if searched_field[0] == 1:
fields[field]['name'] = available_field[:-4]
fields[field]['image'] = global_utils.draw(
fields[field]['image'], searched_field, available_field[:-4], [random.randint(100, 255), random.randint(100, 255), random.randint(100, 255)])
cv2.imwrite(config.project_path+"\\tmp\\" +
available_field[:-4]+".png", fields[field]['image'])
if show_image:
cv2.imshow(fields[field]['name'], fields[field]['image'])
end = global_utils.end_timer()
global_utils.log_time_elapsed(
"get_fields", end-start)
return fields
# Outputs the fields found
def log_fields(fields):
logging.info('* Active fields: ')
available_fields = []
for field in fields.keys():
available_fields.append(field + ": " + fields[field]['name'])
logging.info(available_fields)