為甚麼標題要加個驚嘆號嗎,這樣看起來蠻厲害的
好的最後就是辨識的方法
def cross_detect(self):
# 搜尋所有可能的區域
for p in self.position_list:
# 擷取區域
image = ImageGrab.grab(bbox = (p[0][0], p[0][1], p[1][0], p[1][1]))
# image = self.img.crop((p[0][0], p[0][1], p[1][0], p[1][1]))
# resize to 224, 224
size = (224, 224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# 轉換成np數組
image_array = np.asarray(image)
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
self.data[0] = normalized_image_array
# 進行辨識
prediction = self.model.predict(self.data)
print(prediction)
x, not_x, skip = prediction[0]
if x > 0.8:
print("x!")
elif skip > 0.8:
print("skip!")
else:
print('not x')
並且按下按鈕後觸發該方法
def handle_gui_msg(self, msg):
global gui, cont
if msg == 'set_range':
cont.game_listen()
elif msg == 'cross_detect':
self.cross_detect()
gui.cross_detect_finish()
呼叫gui
self.button_set_range = Button(text="set range", font=("Arial", 14, "bold"), padx=5, pady=5, bg="blue", fg="light green", command=self.set_range)
self.button_set_range.pack()
self.button_cross_detect = Button(text="cross detect", font=("Arial", 14, "bold"), padx=5, pady=5, bg="blue", fg="light green", command=self.cross_detect)
self.button_cross_detect.pack()
def cross_detect(self):
self.q_gui_rsp.put("cross_detect")
self.button_cross_detect['text'] = 'detecting'
self.button_cross_detect['state'] = 'disable'
def cross_detect_finish(self):
self.button_cross_detect['text'] = 'cross_detect'
self.button_cross_detect['state'] = 'normal'
接下來就拿一個廣告測試看看吧這絕對不是業配
辨識的結果如下
emm...竟然有三個位置信心度高於0.8
看起來應該是訓練的樣本數與模型不夠好,明天可能要再調一下模型