56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
import threading
|
|
import cv2 as cv
|
|
from window_capture import WindowCapture
|
|
from vision import Vision
|
|
from config_file import UserConfigs
|
|
|
|
class FlappyPosDiscovery(threading.Thread):
|
|
|
|
def __init__(self):
|
|
threading.Thread.__init__(self)
|
|
|
|
self.config = UserConfigs()
|
|
self.capture_window = WindowCapture(None, None, self.config)
|
|
self.vision_stun = Vision()
|
|
|
|
self.needle_f = cv.imread("flappy/flappy.jpg")
|
|
self.mask_f = cv.imread("flappy/flappy-mask.png")
|
|
|
|
self.needle_g = cv.imread("flappy/gate.png")
|
|
self.mask_g = cv.imread("flappy/gate-mask.png")
|
|
|
|
self.run_mode = 'run'
|
|
self.current_pet_height = 0
|
|
self.next_gate_height = 0
|
|
|
|
self.offset_down = 90
|
|
|
|
self.start()
|
|
|
|
def run(self):
|
|
while self.run_mode == 'run':
|
|
screenshot_g = self.capture_window.get_screenshot_by_area([1600, 1200, 800, 90])
|
|
screenshot_f = self.capture_window.get_screenshot_by_area([200, 1250, 610, 90])
|
|
rectangles_g = self.vision_stun.find(screenshot_g, self.needle_g, 0.97, 5, True, self.mask_g)
|
|
rectangles_f = self.vision_stun.find(screenshot_f, self.needle_f, 0.97, 1, True, self.mask_f)
|
|
|
|
if len(rectangles_g) is not 0:
|
|
self.next_gate_height = rectangles_g[0][1] + rectangles_g[0][3] + self.offset_down
|
|
|
|
if len(rectangles_f) is not 0:
|
|
self.current_pet_height = rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down
|
|
|
|
#print("pet_pos: ", self.current_pet_height)
|
|
#print("next gate: ", self.next_gate_height)
|
|
def get_actual_pet_height(self):
|
|
return self.current_pet_height
|
|
|
|
def get_next_gate_height(self):
|
|
return self.next_gate_height
|
|
|
|
|
|
|
|
|
|
|
|
|