接著真的要開始寫辨識了,首先來引入之前寫的東西
def keras_init(self):
# Load the model
self.model = load_model('x.h5')
self.data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# 預處理
self.model.predict(self.data)
def fix_range(self):
# 原本是用576*1280去做辨識的,所以要依選取範圍調整大小
size_x = abs(self.range_x1 - self.range_x2)
size_y = abs(self.range_y1 - self.range_y2)
# 尺寸修正
rate_x = size_x / 576
rate_y = size_y / 1280
# 尺寸大約60px
size_list = [
60,
90,
60,
60,
]
left_position_list = [
(60, 60),
(576 - size_list[1], 60),
(576 - size_list[2], 40),
(576 - size_list[3], 80),
]
# 填入辨識範圍清單
self.position_list = []
for left in left_position_list:
right = (left[0]+size_list[0], left[1]+size_list[1])
fix_left = (left[0] * rate_x, left[1] * rate_y)
fix_right = (right[0] * rate_x, right[1] * rate_y)
self.position_list.append([fix_left, fix_right])
keras_init()用來初始化訓練相關的套件,fix_range()則是依據範圍大小來調整辨識位置
也就是說剛運行時要呼叫keras_init(),在調整完角度後就呼叫fix_range()
def handle_cont_msg(self, msg):
global gui, cont
if type(msg) == list:
if msg[0] == 'on_click':
# print(msg)
if msg[1] == 1:
self.range_x1, self.range_y1 = msg[2], msg[3]
elif msg[1] == 2:
self.range_x2, self.range_y2 = msg[2], msg[3]
cont.game_listen_stop()
self.fix_range()
gui.set_range_result(self.range_x1, self.range_y1, self.range_x2, self.range_y2)
還是很懶,明天再來寫辨識的方法...