-
Notifications
You must be signed in to change notification settings - Fork 23
/
Image_Templates.py
72 lines (56 loc) · 3.7 KB
/
Image_Templates.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
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
import sys
from os.path import abspath, getmtime, isfile, join, dirname
import cv2
from EDlogger import logger
"""
File:Image_Templates.py
Description:
Class defines template images that will be used with opencv to match in screen regions
Author: [email protected]
"""
class Image_Templates:
def __init__(self, scaleX, scaleY):
self.template = { 'elw' : {'image': None, 'width': 1, 'height': 1},
'elw_sig' : {'image': None, 'width': 1, 'height': 1},
'navpoint' : {'image': None, 'width': 1, 'height': 1},
'compass' : {'image': None, 'width': 1, 'height': 1},
'target' : {'image': None, 'width': 1, 'height': 1},
'target_occluded' : {'image': None, 'width': 1, 'height': 1},
'disengage' : {'image': None, 'width': 1, 'height': 1},
'missions' : {'image': None, 'width': 1, 'height': 1},
'dest_sirius' : {'image': None, 'width': 1, 'height': 1},
'sirius_atmos' : {'image': None, 'width': 1, 'height': 1}
}
# load the templates and scale them. Default templates assumed 3440x1440 screen resolution
self.reload_templates(scaleX, scaleY)
def load_template(self, file_name, scaleX, scaleY):
""" Load the template image in color. If we need grey scale for matching, we can apply that later as needed.
Resize the image, as the templates are based on 3440x1440 resolution, so scale to current screen resolution
return image and size info. """
template = cv2.imread(self.resource_path(file_name), cv2.IMREAD_GRAYSCALE)
#logger.debug("File:"+self.resource_path(file_name)+" template:"+str(template))
template = cv2.resize(template, (0, 0), fx=scaleX, fy=scaleY)
width, height = template.shape[::-1]
return {'image': template, 'width': width, 'height' : height}
# Load the full set of image templates
def reload_templates(self, scaleX, scaleY):
self.template['elw'] = self.load_template("templates/elw-template.png", scaleX, scaleY)
self.template['elw_sig'] = self.load_template("templates/elw-sig-template.png", scaleX, scaleY)
self.template['navpoint'] = self.load_template("templates/navpoint.png", scaleX, scaleY)
self.template['compass'] = self.load_template("templates/compass.png", scaleX, scaleY)
self.template['target'] = self.load_template("templates/destination.png", scaleX, scaleY)
self.template['target_occluded'] = self.load_template("templates/target_occluded.png", scaleX, scaleY)
self.template['disengage'] = self.load_template("templates/sc-disengage.png", scaleX, scaleY)
self.template['missions'] = self.load_template("templates/completed-missions.png", scaleX, scaleY)
self.template['dest_sirius'] = self.load_template("templates/dest-sirius-atmos-HL.png", scaleX, scaleY)
self.template['robigo_mines'] = self.load_template("templates/robigo-mines-selected.png", scaleX, scaleY)
self.template['sirius_atmos'] = self.load_template("templates/sirius-atmos-selected.png", scaleX, scaleY)
def resource_path(self,relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
#try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
# base_path = sys._MEIPASS
#except Exception:
#base_path = abspath(".")
base_path = abspath(".")
return join(base_path, relative_path)