Exemple #1
0
    def get_slots(self, buysell):
        """ Returns available buy/sell slot location by x, y, w, h """
        # gets trading window pos
        x, y, w, h = self.pos
        # find buy/sell slots
        img = Screenshot.this(x, y, w, h, 'hsv')

        if buysell == 'buy':
            low = [32, 248, 192]
            high = [35, 254, 203]
        elif buysell == 'sell':
            low = [16, 248, 122]
            high = [17, 251, 204]

        available_slots = self.get_hsv_pattern_pos(img, low, high)

        slots = list()
        for cnt in available_slots:
            rect = cv2.boundingRect(cnt)
            #pyautogui.moveTo(x, y)
            slots.append(rect)
        return slots  #positions of buy/sell arrows
Exemple #2
0
    def set_main_wndw(self):
        # gets screen size
        w, h = pyautogui.size()
        # takes screen screenshot. Returns  hsv format image
        scrn_scrnshot = Screenshot.this(0, 0, w, h, 'hsv')

        # find Grand exchange window
        # the  rectangule only the GE can have when GE Trading window active
        lower_hsv = np.array([12, 0, 7])
        upper_hsv = np.array([40, 62, 64])
        # mask of applied values
        mask = cv2.inRange(scrn_scrnshot, lower_hsv, upper_hsv)

        # find contours to get sides of rectangle
        contours, h = cv2.findContours(mask, 1, 2)

        for cnt in contours:
            # looks for biggest square
            # if cv2.contourArea(cnt) <= 1695.0:
            #    continue
            # checks contour sides
            approx = cv2.approxPolyDP(cnt, 0.01 * cv2.arcLength(cnt, True),
                                      True)

            # Squares are found with this code
            # to find the rectangular GE window
            if len(approx) == 4:
                if cv2.contourArea(cnt) == 140123:
                    # position of GE Trading window found
                    x, y, w, h = cv2.boundingRect(cnt)
                    # add to take screenshot of GE trading window
                    w = x + w
                    h = y + h
                    self.pos = (x, y, w, h)
                    print(f"Trading window at:X={self.pos[0]} Y={self.pos[1]}")
                    return