Exemple #1
0
def capture():
    for i, window in enumerate(current_windows()):
        name = win_name(window)
        if name == 'League of Legends (TM) Client' or 'League of Legends' in name:
            window = legWindow(window)

            with mss.mss() as sct:
                k = 69

                ptime = time.perf_counter()
                while True:
                    img = np.array(sct.grab(window.geometry))
                    roi = img[window.hper(.5):window.hper(2.5),
                              window.wper(96.7):window.wper(99)]
                    cv2.imwrite(
                        str(HERE.joinpath('traindata', 'clock', f'{k}.png')),
                        roi)

                    # mss.tools.to_png(img.rgb, img.size, output=HERE.joinpath('traindata', 'clock', f'{k}.png'))
                    while ptime + 1 >= time.perf_counter():
                        time.sleep(.001)
                    ptime = time.perf_counter()
                    k = k + 1
                    print(f'{k}: {time.perf_counter()}')

        elif i == len(current_windows()):
            print('league client not found, exiting')
Exemple #2
0
def main():
    for i, window in enumerate(current_windows()):
        name = win_name(window)
        if name == 'League of Legends (TM) Client' or 'League of Legends' in name:
            window = legWindow(window)

            with mss.mss() as sct:
                while True:
                    start = time.perf_counter()

                    # Grab the screen
                    img = np.array(sct.grab(window.geometry))
                    imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                    # this is good for object detection
                    imgCanny = cv2.Canny(img, 100, 150)

                    # this is good for text
                    thresh = cv2.adaptiveThreshold(imgGray, 255, 1, 1, 11, 2)
                    roi = thresh[window.hper(.5):window.hper(2.5),
                                 window.wper(96.7):window.wper(99)]
                    # roi = img[mon["top"]:50, mon["left"]+550:mon["left"]+620]
                    # clock = pytesseract.image_to_string(Image.fromarray(roi)).replace('\n', '').strip()
                    # print(clock)

                    cv2.imshow('the name? rango 2',
                               resizeWithAspectRatio(roi, width=900))
                    if cv2.waitKey(10) & 0xFF == ord('q'):
                        cv2.destroyAllWindows()
                        break

                    end = time.perf_counter()
                    print(f'frame took {round(end-start, 3)} seconds')

        elif i == len(current_windows()):
            print('league client not found, exiting')
Exemple #3
0
    def on_button_hijack_click(self):
        cur_windows = winlaunch.current_windows()
        for wid in cur_windows:
            if winlaunch.win_name(wid) == "IBOS Comm":
                self.ibos_wid = wid
                break

        self.firefox_wid, firefox_pid = winlaunch.launch("firefox")

        self.hijack = True
Exemple #4
0
    def fetch_state(self):
        self.connection.sendall(("FETCH-STATE#").encode())
        # TODO: add # delimiter at end of msg
        state = self.connection.recv(1000).decode().split("|")

        cur_windows = winlaunch.current_windows()
        for wid in cur_windows:
            if winlaunch.win_name(wid) == "IBOS Comm":
                self.ibos_wid = wid
                break

        netapps = {}
        for l in state[3].split("\n"):
            netapps[l.split(", ")[2]] = int(l.split(" ")[1][:-1])

        for l in state[2].split("\n"):
            id = int(l.split(" ")[1][:-1])
            if id == 0:
                continue
            url = l.split(", ")[1]
            ip = l.split(", ")[2]
            if id > self.last_webapp:
                self.last_webapp = id
                self.tabs[id - 1] = BrowserContainer(id - 1, url,
                                                     8081 + netapps[ip] - 1)
                self.hijack = True

        self.builder.get_object("app_combobox").config(
            values=[x.split(" ")[1][:-1] for x in state[2].split("\n")])
        self.builder.get_object("app_combobox").bind(
            '<<ComboboxSelected>>', self.on_app_combobox_select)
        self.builder.get_variable("app_combobox_text").set(state[1])

        if int(state[1]) - 1 != self.cur_tab and int(state[1]) != 0:
            self.set_url_text(state[0].split(", ")[0])
            self.cur_tab = int(state[1]) - 1

            for tid in self.tabs:
                self.tabs[tid].hide()

            if self.cur_tab != -1:
                self.tabs[self.cur_tab].show()
Exemple #5
0
    def __init__(self, wid):
        # simple geometry
        self.wid = wid
        self.name = win_name(wid)
        self.width, self.height = tuple(win_size(wid))
        self.x, self.y = tuple(win_pos(wid))

        # determine if on left or right monitor. this is a bad method, only works iwth my two monitor setup
        if self.x >= 1920:  # right monitor
            monitor = 1
        else:  # left monitor
            monitor = 2

        # window dimensions into mss format
        self.geometry = {
            "top": self.y,
            "left": self.x,
            "width": self.width,
            "height": self.height,
            "mon": monitor
        }
        # to get window position relative to a monitor we have to account for monitor position
        self.x += -1920
Exemple #6
0
#             break

with mss.mss() as sct:
    # Get information of monitor 2
    monitor_number = 1
    mon = sct.monitors[monitor_number]

    # The screen part to capture
    monitor = {
        "top": mon["top"] + 100,  # 100px from the top
        "left": mon["left"] + 100,  # 100px from the left
        "width": 160,
        "height": 135,
        "mon": monitor_number,
    }
    output = "sct-mon{mon}_{top}x{left}_{width}x{height}.png".format(**monitor)

    # Grab the data
    img = sct.grab(monitor)

    # Save to the picture file
    # mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
    # print(output)
    cv2.imshow('test', np.array(img))
    if cv2.waitKey(0) & 0xFF == ord('q'):
        cv2.destroyAllWindows()

for window in current_windows():
    name = win_name(window)
    size = list(win_size(window))
    print(f'{name}: {size}')