Exemplo n.º 1
0
def get_bag(bagornot, *args):
    x1, y1 = position() #Get runescapes top-left coords

    x1 += 557    #make The Bag's top-left, and btm-right coords
	#y1=229 default for archlinux
    y1 += 229    #x2,y2 == btm-right coord, width and height
    x2 = x1 + 173
    y2 = y1 + 253#253default for arch
    try: # block to allow this func to also get 'hsv' img objects
        for arg in args:
            if arg == 'hsv':
                rs_bag = Screenshot.shoot(x1,y1,x2,y2,'hsv')
                return rs_bag, x1, y1
            if arg == 'gray':
                rs_bag = Screenshot.shoot(x1,y1,x2,y2)
                return rs_bag, x1, y1
    except:
        pass

    rs_bag = Screenshot.shoot(x1,y1,x2,y2)

    if bagornot == 'only':
        return rs_bag
    else:
        return rs_bag, x1, y1
Exemplo n.º 2
0
    def get_bag(self, return_coords=False, *args):
        #x1, y1 = position() #Get runescapes top-left coords

        # bag postions, x1,y1-x2,y2
        x1 = self.rsx + 565
        y1 = self.rsy + 239
        x2 = self.rsx + 721
        y2 = self.rsy + 485

        try:  # block to allow this func to also get 'hsv' img objects
            for arg in args:
                if arg == 'hsv':
                    rs_bag = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
                    return rs_bag, x1, y1
                if arg == 'gray':
                    rs_bag = Screenshot.shoot(x1, y1, x2, y2)
                    return rs_bag, x1, y1
        except:
            pass

        rs_bag = Screenshot.shoot(x1, y1, x2, y2)

        if return_coords:
            return rs_bag, x1, y1
        else:
            return rs_bag
Exemplo n.º 3
0
    def findCageOption(self):
        """Finds cage option in fishing guild when right clicked on fish bubbles"""
        x1 = 5
        y1 = 25
        x2 = 767
        y2 = 524
        rs_window = Screenshot.shoot(x1,y1,x2,y2)
        #cv2.imshow('img',rs_window)
        #cv2.waitKey(0)
        rsc = rs_window.copy()
        # gets only all the black and white
        ret,thresh1 = cv2.threshold(rsc,0,255,cv2.THRESH_BINARY)
        # inverst to only get black cloros as white
        ret,thresh1 = cv2.threshold(thresh1,0,255,cv2.THRESH_BINARY_INV)

        _, contours,h = cv2.findContours(thresh1,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)
            # draws only if its squared
            if len(approx)==4:
                print("square of {}".format(cv2.contourArea(cnt)))
                #cv2.drawContours(rs_window,[cnt],0,(255,255,255),-1)
                # get geometry of approx
                # add rs coords
                x,y,w,h = cv2.boundingRect(cnt)

                #combines rs_window coords
                x += x1
                y += y1

                # scrshot of option menu on play window
                img = Screenshot.shoot(x,y,x+w,y+h)
                ret,thresh1 = cv2.threshold(img,254,255,cv2.THRESH_BINARY)

                # loads image from db
                img_from_dict = self.idb.pickled_dict['cage']


                #finds a match 
                from modules import Match
                # runs func when match is found returns true to keep looking for template
                if Match.images(thresh1,img_from_dict,x,y, self.doInMatched):
                    # keep looking for other bubbles
                    return 1
                else:
                    # found 'cage'
                    return 0
        # in case the options menu is aginast an edge
        return 1
Exemplo n.º 4
0
    def findFishBubbles(self,click_n,func,*args):
        """Pass a function to do after it finds the fish bubbles"""

        # water bubbles
        #low = np.array([103,81,0])
        #high = np.array([111,255,255])
        play_screen = Screenshot.shoot(6,59,510,355,'hsv')

        low = np.array([220,50,100])
        high = np.array([255,255,255])
        mask = cv2.inRange(play_screen, low, high)

        #cv2.imshow('img', mask)
        #cv2.waitKey(0)

        kernel = np.ones((5,5), np.uint8)
        dilation = cv2.dilate(mask, kernel, iterations = 1)

        #cv2.imshow('dilation', dilation)
        #cv2.waitKey(0)

        _, contours, _ = cv2.findContours(dilation.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        for c in random.choice(contours):
            (x, y, w, h) = cv2.boundingRect(c)
            x += 6 
            y += 59
            x2 = x + w 
            y2 = y + h 
            Mouse.randMove(x,y,x2,y2,click_n)
            # pass args to fucntion doing the actions
            # fucn should return true if needs to continue loking  at other bubbles
            if func():
                continue
            else:
                return
Exemplo n.º 5
0
def check_mine_availability(mine_x, mine_y):
    RandTime.randTime(3, 0, 0, 5, 9, 9)
    cmx, cmy = Mouse.mouse_loc()
    mine_x = cmx - mine_x
    mine_y = cmy - mine_y
    while 1:
        # expands by 4X4 to check color values
        x = mine_x - 2
        y = mine_y - 2
        x2 = mine_x + 2
        y2 = mine_y + 2

        checked_area = Screenshot.shoot(x, y, x2, y2, 'hsv')

        lower_gray = np.array([0, 0, 153])
        upper_gray = np.array([8, 25, 209])

        mask = cv2.inRange(checked_area, lower_gray, upper_gray)
        for colors in mask:
            for value in colors:
                if value == 255:
                    print('mine ACTIVE')
                    RandTime.randTime(5, 0, 0, 5, 9, 9)
                    break
        else:
            print("mine INACTIVE")
            break
Exemplo n.º 6
0
    def find_transportation_arrow(self):
        run = 1
        # moves to north east area of mini map
        Mouse.randMove(680 - 20, 65 - 20, 680 + 20, 65 + 20, 1)
        time.sleep(5)
        while run:
            mini_map = Screenshot.shoot(571, 29, 718, 180, 'hsv')
            low = np.array([10, 101, 147])
            high = np.array([13, 255, 211])

            # applies mask
            mask = cv2.inRange(mini_map, low, high)
            # removes any noise
            kernel = np.ones((5, 5), np.uint8)
            dilation = cv2.dilate(mask, kernel, iterations=1)

            _, contours, _ = cv2.findContours(dilation.copy(),
                                              cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_SIMPLE)
            for c in contours:
                (x, y, w, h) = cv2.boundingRect(c)
                x += 568
                y += 36
                x2 = x + w
                y2 = y + h
                Mouse.randMove(x, y, x2, y2, 1)
                run = 0
            time.sleep(1)
            print('running again')
Exemplo n.º 7
0
    def isBankOpen(self):
        """checks to see if bank is open, returns True, else False"""
        # black X button hsv values
        buttonx_hsv = (np.array([0, 254, 0]), np.array([179, 255, 255]))
        # gets current game's position
        #self.rsx,rsy = self.position()
        #button X on bank window coords
        x1 = self.rsx + 484
        y1 = self.rsy + 44
        x2 = self.rsx + 497
        y2 = self.rsy + 59

        # Screenshot X button
        img = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
        # cv2.imshow('img', img)
        # cv2.waitKey(2000)
        # cv2.destroyAllWindows()
        # Apply hsv ranges
        mask = cv2.inRange(img, buttonx_hsv[0], buttonx_hsv[1])

        # counts white pixels in X
        counter = 0
        for colors in mask:
            for color_value in colors:
                if color_value == 255:
                    counter += 1
        #print(counter)
        #cv2.imshow('img', mask)
        #cv2.waitKey(0)
        # 54 = Bank is open
        if counter == 54:
            return True
        return False
Exemplo n.º 8
0
def isBankOpen():
    """checks to see if bank is open, returns True, else False"""
    # black X button hsv values
    buttonx_hsv = (np.array([0,254,0]),np.array([179,255,255]))
    # gets current game's position
    rsx,rsy = position()
    #button X on bank window coords
    x1 = rsx+480
    y1 = rsy+38
    x2 = rsx+490
    y2 = rsy+49
    # Screenshot X button
    closeButton = Screenshot.shoot(x1,y1,x2,y2,'hsv')
    # Apply hsv ranges
    mask = cv2.inRange(closeButton,buttonx_hsv[0], buttonx_hsv[1])

    # counts white pixels in X
    counter = 0
    for colors in mask:
        for color_value in colors:
            if color_value == 255:
                counter += 1
    #print(counter)
    #cv2.imshow('img', mask)
    #cv2.waitKey(0)
    # 54 = Bank is open
    if counter == 54:
        return True
    return False
Exemplo n.º 9
0
def closeBank():
    cwd = os.getcwd()
    rsx, rsy = position()
    x1 = rsx+449
    y1 = rsy+0
    x2 = rsx+522
    y2 = rsy+59

    closeButton = Screenshot.shoot(x1,y1,x2,y2)
    #SAVE FOR DEBUG
    #cv2.imwrite('debug_closeButton.png',closeButton)
    loc, w, h = Match.this(closeButton, cwd+'/imgs/bankXbutton.png')

    for pt in zip(*loc[::-1]):
        #making pt relative to the RS window
        pt = (pt[0] + x1, pt[1] + y1)
        #make Btm-Right pt
        btx = pt[0] + w
        bty = pt[1] + h
        #gen random coords
        rx = random.randint(pt[0], btx)
        ry = random.randint(pt[1], bty)
        #Move to and Click the X to close bank
        Mouse.moveClick(rx,ry,1)
        break
Exemplo n.º 10
0
    def find_transportation_arrow(self):
        run = 1
        # moves to north east area of mini map
        Mouse.randMove(680-20,65-20,680+20,65+20,1)
        time.sleep(5)
        while run:
            mini_map = Screenshot.shoot(571,29,718,180,'hsv')
            low = np.array([10,101,147])
            high = np.array([13,255,211])

            # applies mask
            mask = cv2.inRange(mini_map, low, high)
            # removes any noise
            kernel = np.ones((5,5), np.uint8)
            dilation = cv2.dilate(mask, kernel, iterations = 1)

            _, contours, _ = cv2.findContours(dilation.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
            for c in contours:
                (x, y, w, h) = cv2.boundingRect(c)
                x += 568
                y += 36
                x2 = x + w
                y2 = y + h 
                Mouse.randMove(x,y,x2,y2,1)
                run = 0
            time.sleep(1)
            print('running again')
Exemplo n.º 11
0
    def getPlayingScreen(self, color):
        """ Returns play screen area as an HSV image,
            and the first point of the image """

        #playScreen = Screenshot.shoot(self.rsx, self.rsy,517,362,color)
        playScreen = Screenshot.shoot(self.rsx, self.rsy, 760, 520, color)

        return playScreen, self.rsx, self.rsy
Exemplo n.º 12
0
 def mini_map_mask(self,low,high, template=None):
     x1 = 571
     y1 = 29
     x2 = 710
     y2 = 180
     mini_map = Screenshot.shoot(x1,y1,x2,y2,'hsv')
     # applies mask
     mask = cv2.inRange(mini_map, low, high)
     return mask, x1, y1
Exemplo n.º 13
0
 def getMinimap(self):
     """ INCOMPLETE Returns minimap area as an HSV image,
         and the first point of the image """
     # bag postions, x1,y1-x2,y2
     x1 = self.rsx + 570
     y1 = self.rsy + 30
     x2 = self.rsx + 720
     y2 = self.rsy + 170
     minimap = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
     return minimap, x1, y1
Exemplo n.º 14
0
 def getBankWindow(self, *args):
     """ window only includes the items in bank, to tabs or buttons"""
     #creates bank window boundaries
     x1 = self.rsx + 70
     y1 = self.rsy + 105
     x2 = self.rsx + 440
     y2 = self.rsy + 319
     # passing 'hsv' to this function returns hsv image
     try:
         if args[0] == 'hsv':
             #gets screenshot object
             bankWindow = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
             ##### DEBUG
             #cv2.imshow('bankwindow', bankWindow)
             #cv2.waitKey(0)
             ####
             return bankWindow, x1, y1
     except:
         #gets screenshot object
         bankWindow = Screenshot.shoot(x1, y1, x2, y2)
         return bankWindow, x1, y1
Exemplo n.º 15
0
def find_template(template_name):  #pass template to function
    global imd
    #checks to see wheater to add cur dir or not
    x1, y1 = RS.position()  #Get runescapes top-left coords

    x1 += 557  #make The Bag's top-left, and btm-right coords
    y1 += 229  #x2,y2 == btm-right coord, width and height
    x2 = x1 + 173
    y2 = y1 + 253

    if not RS.is_button_selected('inventory'):
        #RS.press_button('inventory')
        init_x = random.randint(x1, x2)
        init_y = random.randint(y1, y2)

        Mouse.moveTo(init_x, init_y)
        autopy.key.tap(autopy.key.K_F1)

    # image of bag
    rs_bag = Screenshot.shoot(x1, y1, x2, y2)  #Screenshot taken here,
    # cv2.imshow('bag', rs_bag)
    # cv2.waitKey(0)

    #template
    template = imd.pickled_dict[template_name]
    #imd.showImg('salmon')
    color_mode, w, h = template.shape[::-1]
    # change img to grayscale
    if color_mode == 3:
        template = cv2.cvtColor(template, cv2.COLOR_RGB2GRAY)
    res = cv2.matchTemplate(rs_bag, template, cv2.TM_CCOEFF_NORMED)
    threshold = .8  #default is 8
    loc = np.where(res >= threshold)
    for pt in zip(*loc[::-1]):  #goes through each found image
        btmX = pt[
            0] + w - 5  #pt == top-left coord of template, bottom-right point of of template image
        btmY = pt[1] + h - 5
        #moving the pt coord of the template a bit to the right, so options menu get brought up
        pt = (pt[0] + 5, pt[1] + 2)

        x, y = gen_coords(
            pt, btmX, btmY
        )  #gets random x, y coords relative to RSposition on where to click
        #Mouse.moveClick(x,y, 3)#right clicks on given x,y coords

        # using new method to drop. holding shift
        autopy.key.toggle(autopy.key.K_SHIFT, True)
        Mouse.moveClick(x, y, 1)  #right clicks on given x,y coords
        autopy.key.toggle(autopy.key.K_SHIFT, False)

        #RS.findOptionClick(x,y,'drop')

    RandTime.randTime(2, 0, 0, 2, 9, 9)
Exemplo n.º 16
0
def getBankWindow(*args):
    rsx, rsy = position() #Get runescapes top-left coords
    bankWin
    #creates bank window boundaries
    x1 = rsx + 21
    y1 = rsy + 23
    x2 = rsx + 486
    y2 = rsy + 335
    # passing 'hsv' to this function returns hsv image
    try:
        if args[0] == 'hsv':
            #gets screenshot object
            bankWindow = Screenshot.shoot(x1,y1,x2,y2, 'hsv')
            ##### DEBUG
            #cv2.imshow('bankwindow', bankWindow)
            #cv2.waitKey(0)
            ####
            return bankWindow, x1, y1
    except:
        #gets screenshot object
        bankWindow = Screenshot.shoot(x1,y1,x2,y2)
        return bankWindow, x1, y1
Exemplo n.º 17
0
 def getHealth(self):
     # green color
     health_hsv = [[69, 22, 134], [70, 255, 135]]
     low = np.array(health_hsv[0])
     high = np.array(health_hsv[1])
     health_img = Screenshot.shoot(11, 68, 136, 69, 'hsv')
     self.health_img = health_img
     mask = cv2.inRange(health_img, low, high)
     self.mask = mask
     mask = [1 if x == 255 else x for x in mask[0]]
     #print(mask)
     self.health = int((sum(mask) / 125) * 100)
     #self.health = sum(mask)
     print(f'Enemy HP:{self.health}%')
Exemplo n.º 18
0
def detect_sul():
    # Screenshot rectangle mid-center of the game screen not relevant to the game window
    img = Screenshot.shoot(100, 80, 800, 560, 'hsv')
    # Lower and uppper colors of the sulphur rocks
    low = np.array([0, 35, 51])
    high = np.array([179, 55, 83])

    mask = cv2.inRange(img, low, high)

    # Removes noise
    kernel = np.ones((10, 10), np.uint8)
    # closing is the img w/ no nosie
    closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

    blur = cv2.GaussianBlur(closing, (5, 5), 0)

    contours, _ = cv2.findContours(blur, cv2.RETR_TREE,
                                   cv2.CHAIN_APPROX_SIMPLE)

    cnt = contours[0]

    # Finds min max coords of first contour
    all_xs = []
    all_ys = []
    for a in cnt:
        for b in a:
            all_xs.append(b[0])
            all_ys.append(b[1])
    # getting the rectangle of contour
    x1 = min(all_xs)
    y1 = min(all_ys)

    x2 = max(all_xs)
    y2 = max(all_ys)

    w = x2 - x1
    h = y2 - y1

    x1 += ((w / 2) / 2)
    y1 += ((h / 2) / 2)
    x2 -= ((w / 2) / 2)
    y2 -= ((h / 2) / 2)

    x = random.randint(x1, x2)
    y = random.randint(y1, y2)

    # adding the points of the image back the coords
    x += 100
    y += 80
    click(x, y)
Exemplo n.º 19
0
def detect_sul():
    # Screenshot rectangle mid-center of the game screen not relevant to the game window
    img = Screenshot.shoot(100,80,800,560, 'hsv')
    # Lower and uppper colors of the sulphur rocks
    low = np.array([0,35,51])
    high= np.array([179,55,83])

    mask = cv2.inRange(img, low, high)
    
    # Removes noise
    kernel = np.ones((10,10), np.uint8)
    # closing is the img w/ no nosie
    closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
    
    blur = cv2.GaussianBlur(closing, (5,5),0)

    contours, _ = cv2.findContours(blur, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    cnt = contours[0]
    
    # Finds min max coords of first contour
    all_xs = []
    all_ys = []
    for a in cnt:
        for b in a:
            all_xs.append(b[0])
            all_ys.append(b[1])
    # getting the rectangle of contour
    x1 = min(all_xs)
    y1 = min(all_ys)

    x2 = max(all_xs)
    y2 = max(all_ys)

    w = x2 - x1
    h = y2 - y1

    x1 += ((w/2)/2)
    y1 += ((h/2)/2)
    x2 -= ((w/2)/2)
    y2 -= ((h/2)/2)

    x = random.randint(x1,x2)
    y = random.randint(y1,y2)

    # adding the points of the image back the coords
    x += 100
    y += 80
    click(x,y)
Exemplo n.º 20
0
def is_button_selected(button_name):
    """Returns true if button is selected, else False"""
    x1, y1, x2, y2 = press_button(button_name, 'coords')
    button_img = Screenshot.shoot(x1,y1,x2,y2, 'hsv')
    lower_red = np.array([0,179,0])
    upper_red = np.array([4,193,255])

    mask = cv2.inRange(button_img, lower_red, upper_red)

    for colors in mask:
        for value in colors:
            if value == 255:
                #print('{} is selected'.format(button_name))
                return 1
    #print('{} is NOT selected'.format(button_name))
    return 0
Exemplo n.º 21
0
    def is_button_selected(self, button_name):
        """Returns true if button is selected, else False"""
        x1, y1, x2, y2 = self.press_button(button_name, 'coords')
        button_img = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
        lower_red = np.array([0, 179, 0])
        upper_red = np.array([4, 193, 255])

        mask = cv2.inRange(button_img, lower_red, upper_red)

        for colors in mask:
            for value in colors:
                if value == 255:
                    #print('{} is selected'.format(button_name))
                    return 1
        # print('{} is NOT selected'.format(button_name))
        return 0
Exemplo n.º 22
0
    def isRunActive(self):
        """checks to see if run is active, returns True, else False"""
        # checking color yellow on boot
        run_icon = (np.array([25, 135, 236]), np.array([26, 145, 237]))
        x1 = self.rsx + 564
        y1 = self.rsy + 152
        x2 = self.rsx + 578
        y2 = self.rsy + 160

        img = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
        # Apply hsv ranges
        mask = cv2.inRange(img, run_icon[0], run_icon[1])
        # if true run is off
        if mask.any():
            return True
        else:
            return False
Exemplo n.º 23
0
def check_prayer():
    RSX, RSY = RS.position()
    pc = (545,109,571,135)
    prayer_level = Screenshot.shoot(pc[0],pc[1],pc[2],pc[3], 'hsv')
    
    low = np.array([116,0,0])
    high =np.array([141,255,255])

    mask = cv2.inRange(prayer_level, low, high)
    mask = np.array(mask)
     
    percentage = 0
    
    for color in mask:
        for element in color:
            if element == 255:
                percentage += 1
            else:
                continue
    return percentage/363.0
Exemplo n.º 24
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
Exemplo n.º 25
0
    def find_fairy_ring(self):
        run = 1
        while run:
            play_screen = Screenshot.shoot(6, 59, 510, 355, 'hsv')
            # finding white on fairy ring inner circle
            low = np.array([107, 92, 93])
            high = np.array([113, 255, 129])

            mask = cv2.inRange(play_screen, low, high)

            kernel = np.ones((10, 10), np.uint8)
            dilation = cv2.dilate(mask, kernel, iterations=1)
            #closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

            #_,contours,_ = cv2,findContours(closing.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            _, contours, _ = cv2.findContours(dilation, cv2.RETR_TREE,
                                              cv2.CHAIN_APPROX_SIMPLE)

            for con in contours:
                print("Area: {}".format(cv2.contourArea(con)))
                if cv2.contourArea(con) > 1.0:
                    (x, y, w, h) = cv2.boundingRect(con)
                    x += self.rs_x
                    y += self.rs_y
                    x1 = x
                    y1 = y
                    x2 = x + w
                    y2 = y + h
                    print("x1:{} y1:{} x2:{} y2:{}".format(x1, y1, x2, y2))
                    #print(cv2.contourArea(con))
                    #M = cv2.moments(con)
                    # finds centroid
                    #x,y = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
                    Mouse.randMove(x1, y1, x2, y2, 3)
                    time.sleep(5)
                    if RS.findOptionClick(x1, y1, 'cis'):
                        run = 0
                    time.sleep(2)
                    break
Exemplo n.º 26
0
def findMonk():
    global rsx
    global rsy

    x1 = rsx + 13
    y1 = rsy + 60
    x2 = rsx + 500
    y2 = rsy + 352

    play_window = Screenshot.shoot(x1, y1, x2, y2, 'hsv')
    #finds red shades
    lower_red = np.array([0, 162, 63])
    upper_red = np.array([3, 172, 169])

    #mask = cv2.inRange(play_window, lower_red, upper_red)
    mask2 = cv2.inRange(play_window, lower_red, upper_red)
    #res = cv2.bitwise_and(play_window, play_window, mask=mask)
    #cv2.imshow('res', res)

    _, contours, _ = cv2.findContours(mask2, cv2.RETR_TREE,
                                      cv2.CHAIN_APPROX_SIMPLE)

    cnt = contours[0]

    x, y, w, h = cv2.boundingRect(cnt)
    w = w / 2
    h = h / 2
    x += w / 2
    y += h / 2
    # Draws rectangle around it
    #img = cv2.rectangle(mask, (x,y), (x+w, y+h), (0,0,0), 2)

    #makes x & y relative to RS window
    x += x1
    y += y1

    # returns half a square in the found contour
    return x, y, x + w, y + h
Exemplo n.º 27
0
    def find_fairy_ring(self):
        run = 1
        while run:
            play_screen = Screenshot.shoot(6,59,510,355,'hsv')
            # finding white on fairy ring inner circle
            low = np.array([107,92,93])
            high = np.array([113,255,129])

            mask = cv2.inRange(play_screen, low, high)

            kernel = np.ones((10,10), np.uint8)
            dilation = cv2.dilate(mask, kernel, iterations = 1)
            #closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

            #_,contours,_ = cv2,findContours(closing.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            _,contours,_ = cv2.findContours(dilation, cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

            for con in contours:
                print("Area: {}".format(cv2.contourArea(con)))
                if cv2.contourArea(con) > 1.0:
                    (x, y, w, h) = cv2.boundingRect(con)
                    x += self.rs_x
                    y += self.rs_y
                    x1 = x
                    y1 = y
                    x2 = x + w
                    y2 = y + h
                    print("x1:{} y1:{} x2:{} y2:{}".format(x1,y1,x2,y2))
                    #print(cv2.contourArea(con))
                    #M = cv2.moments(con)
                    # finds centroid
                    #x,y = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
                    Mouse.randMove(x1,y1,x2,y2,3)
                    time.sleep(5)
                    if RS.findOptionClick(x1,y1,'cis'):
                        run = 0
                    time.sleep(2)
                    break
Exemplo n.º 28
0
def findMonk():
    global rsx
    global rsy

    x1 = rsx + 13
    y1 = rsy + 60 
    x2 = rsx + 500
    y2 = rsy + 352

    play_window = Screenshot.shoot(x1,y1,x2,y2, 'hsv')
    #finds red shades
    lower_red = np.array([0,162,63])
    upper_red = np.array([3,172,169])

    #mask = cv2.inRange(play_window, lower_red, upper_red)
    mask2 = cv2.inRange(play_window, lower_red, upper_red)
    #res = cv2.bitwise_and(play_window, play_window, mask=mask)
    #cv2.imshow('res', res)

    _, contours, _ = cv2.findContours(mask2, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    cnt = contours[0]

    x, y, w, h = cv2.boundingRect(cnt)
    w = w/2
    h = h/2
    x += w/2
    y += h/2
    # Draws rectangle around it
    #img = cv2.rectangle(mask, (x,y), (x+w, y+h), (0,0,0), 2)

    #makes x & y relative to RS window
    x += x1
    y += y1

    # returns half a square in the found contour
    return x,y,x+w, y+h
Exemplo n.º 29
0
def getOptionsMenu(x, y):  # X,Y coords of where it right-clicked in bag to bring up the Options Menu
    #"""Returns screenshot as menu, and menu_x, and menu_y which is topleft pt of the menu"""
    # Top-Left coords of where RS window is
    rs_x, rs_y = position()

    # Adding Rs coords to the options menu to get its location relevant to the window
    # 24 here goes up on Y since sometimes screenshot needs to get more of the
    # top Y to find the right option in the options menu.
    menu_x = rs_x + x - 160  #higher number moves screenshot to left
    menu_y = rs_y + y - 40  #moves screenshot up

    menu_x2 = menu_x + 220 #Plus width
    menu_y2 = menu_y + 160 #Plus height

    #takes screenshot here
    menu = Screenshot.shoot(menu_x, menu_y,menu_x2, menu_y2)

    ##$#added for debug purposes####
    #cv2.imshow('img',menu)
    #print(menu_x,menu_y)
    #cv2.waitKey(0)

    #menu is the image, menuy/menux is the top-left coord of the image
    return menu_x, menu_y, menu
Exemplo n.º 30
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
Exemplo n.º 31
0
 def scrnshtIntoDb(self, name, x1, y1, x2, y2):
     img4db = Screenshot.shoot(x1, y1, x2, y2)
     self.pickled_dict[name] = img4db
     print("Screenshot: '{}' added to dict".format(name))
     self.savePickledDict()
Exemplo n.º 32
0
def findOptionClick(x,y,option_name):
    """Option name of in Image database only needs to be passed, x,y are obsoleate"""
    import Imgdb
    # Image DB
    idb = Imgdb.ImgDb()

    template = idb.pickled_dict[option_name]
    # turning template to graysacle
    if len(template.shape) == 3:
        template = cv2.cvtColor(template,cv2.COLOR_RGB2GRAY)

    w, h = template.shape[::-1]#Width, height of template image

    # coords of playing window
    x1 = 0 #5
    y1 = 25
    x2 = 767
    y2 = 524
    rs_window = Screenshot.shoot(x1,y1,x2,y2)

    # Finds all black lines
    ret,thresh1 = cv2.threshold(rs_window,0,255,cv2.THRESH_BINARY)
    # inverst to black to white
    ret,thresh1 = cv2.threshold(thresh1,0,255,cv2.THRESH_BINARY_INV)

    # looks for all squares
    _, contours,h = cv2.findContours(thresh1,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)

        # Square found here vvvv
        if len(approx)==4:
            #print("square of {}".format(cv2.contourArea(cnt)))
            #cv2.drawContours(rs_window,[cnt],0,(255,255,255),-1)

            # get geometry of approx
            # add rs coords
            x,y,w,h = cv2.boundingRect(cnt)

            #combines with playing window
            x += x1
            y += y1

            # scrshot of option menu on play window
            img = Screenshot.shoot(x,y,x+w,y+h)
            ret,pattern = cv2.threshold(img,254,255,cv2.THRESH_BINARY)
            ###  DEBUG LINE
            #cv2.imshow('img',pattern)
            #cv2.waitKey(0)
            #return
            break
    else:
        Mouse.randMove(0,0,500,500,0)
        time.sleep(1)
        print("Else ran")

    res = cv2.matchTemplate(pattern,template,cv2.TM_CCOEFF_NORMED)
    threshold = .9
    loc = np.where( res >= threshold)

    # clicks on option here when found in pattern
    for pt in zip(*loc[::-1]):#goes through each found image
        rsx, rsy = position()
        x += pt[0] + rsx
        y += pt[1] + rsy
        y1 = y
        y2 = y+10
        img = Screenshot.shoot(x,y1,x+w,y2)
        # range of x and y to click on.
        # in the options
        Mouse.randMove(x,y1,x+(w/2),y2, 1)
        # autopy.mouse.click()#taking out since it does not delay the click
        RandTime.randTime(0,0,0,0,0,9)
Exemplo n.º 33
0
def getPlayingScreen():
    """Returns play screen area as an HSV image, and the first point of the image"""
    playScreen = Screenshot.shoot(7,25,520,360,'hsv')
    return playScreen, 7,25
Exemplo n.º 34
0
def main_run():
    # loop while waiting on emey to die
    def wait_loop():
        health_counter = 1
        enemy = Enemy()
        #waits until enemy health is 0
        start_time = time.time()
        while health_counter != 50:
            enemy.getHealth()
            cv2.imshow('health-hsv', enemy.health_img)
            cv2.imshow('mask', enemy.mask)
            cv2.waitKey(1)
            if enemy.health == 0:
                #time.sleep(random())
                print(
                    f'Fight took:{time.time()-start_time:.2f} secs\nHealth Counter={health_counter}'
                )
                health_counter = 1
                return
            health_counter += 1
            #time.sleep(1+random())

    # initialize HumanClicker object
    hc = HumanClicker()

    #dark_wizard = [ [27,70,22], [28,107,64] ]
    #hill giant
    dark_wizard = [[20, 46, 34], [33, 106, 72]]
    green_tile = [[61, 113, 105], [68, 255, 255]]
    # low high hsv values
    player_tile = [[87, 232, 190], [90, 255, 255]]
    #gree_health_bar = [ [54,108,120],[62,255,255]]
    #red_health_bar = [ [0,254,254],[1,255,255] ]
    secs_wait = 1
    while 1:
        playScreen = Screenshot.shoot(0, 0, 520, 360, 'hsv')

        low = np.array(green_tile[0])
        high = np.array(green_tile[1])
        mask = cv2.inRange(playScreen, low, high)

        #kernel = np.ones((3,3), np.uint8)
        #closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

        contours, _ = cv2.findContours(mask, cv2.RETR_TREE,
                                       cv2.CHAIN_APPROX_SIMPLE)

        areas = {}
        # gathers areas with center coords
        for con in (contours):
            area = cv2.contourArea(con)
            if area > 50:
                M = cv2.moments(con)
                #print(area)
                cx = int(M['m10'] / M['m00'])
                cy = int(M['m01'] / M['m00'])
                areas[area] = (cx, cy)
        # restarts loop if no emenies around
        if len(areas.keys()) == 0:
            print(f'No enemy detected...waiting {secs_wait} secs...')
            time.sleep(secs_wait)
            secs_wait += secs_wait * .20
            continue
        # find distance to 260,180 coords.  which is center of playing screen
        distances = {}
        for ele_set in areas.items():
            x = ele_set[1][0]
            y = ele_set[1][1]
            dist = int(sqrt(((260 - x)**2) + ((180 - y)**2)))
            distances[dist] = areas[ele_set[0]]
        # select point with min distance to center of play screen
        min_distance = min([i for i in distances.keys()])
        #print(f'minimum distance:{min_distance}')
        #print(f'coords:{distances[min_distance]}')

        # unpacks coords of tile closest to center of screen
        cx, cy = distances[min_distance]

        # move the mouse to position (100,100) on the screen in approximately 2 seconds
        hc.click(x=cx, y=cy)
        #autopy.mouse.move(cx,cy)
        #Mouse.moveTo(cx,cy)
        # wait after clicking to be able to see health box on top top of playscreen
        # time.sleep(2)
        # wait_loop()
        time.sleep(triangular(14, 29) / 1.5)
        # resets time to wait
        secs_wait = 1
Exemplo n.º 35
0
def detect_fire_altar():
    img = Screenshot.shoot(45,61,455,300, 'hsv')
    # lower and upper reddish colors for fire altar 
    low = np.array([0,74,107])
    high= np.array([13,110,137])

    # Mask
    mask = cv2.inRange(img, low, high)
    #cv2.imshow('mask', mask)

    try:
    ############################################################ Morphological closing
        """Using it to remove noise pixels inside the found object"""
        # kernel is the structuring element which decides the nature of operation
        kernel = np.ones((5,5), np.uint8)
        # closing is the img w/ no noise
        closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
        #cv2.imshow('closing', closing)
    ################################################################ Gaussian blurr
        blur = cv2.GaussianBlur(closing, (5,5),0)
        #cv2.imshow('blur', blur)

    ################################################################# Contours
        # Find Contours
        """findContours fucntion modifies the source image.  so if you want to 
        source image even after finding contours, already store it to some other varialbe"""
        #                               source|cnt retrival mode |contour aprox method
        contours, _ = cv2.findContours(blur, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        #cnt = contours[1]

        #cv2.drawContours(img, contours, -1, (255,255,255), 1)
    ################################################################# Minimum enclosing circle
        #ellipse = cv2.fitEllipse(cnt)
        #cv2.ellipse(img_c, ellipse, (0,255,0),2)
    ################################################################# Rect around all contours

        all_xs = []
        all_ys = []
        # find max min x, y values of all contours
        for con in contours:
            for a in con:
                all_xs.append(a[0][0])
                all_ys.append(a[0][1])
        x1 = min(all_xs)
        y1 = min(all_ys)

        x2 = max(all_xs)
        y2 = max(all_ys)

        # Moving x in by half of half
        x1 += ((x2-x1)/2)/2
        x2 -= ((x2-x1)/2)/2
        # Moving Y in by half of half
        y1 += ((y2-y1)/2)/2
        y2 -= ((y2-y1)/2)/2
        # Adding Screenshot first point coords
        x1 += 45
        x2 += 45
        y1 += 61
        y2 += 61

        print(x1,y1,x2,y2)
        x, y = Mouse.genCoords(x1,y1,x2,y2)
        Mouse.moveClick(x,y,1)

        #print(x1,y1,x2,y2)
        # Drawing rect around the xs ys
        #cv2.rectangle(img, (x1,y1),(x2,y2),(255,255,255),1)

        #cv2.imshow('img', img)
        #cv2.waitKey(0)
        #cv2.destroyAllWindows()
        return True
    except:
        print("Not found!\nTrying Again\n")
        time.sleep(.5)
        return False
Exemplo n.º 36
0
import time
import cv2
import numpy as np


#for _ in xrange(1000):
#    Rs.antiban('magic')
#    time.sleep(1)
#
#dark_wizard = [ [27,70,22], [28,107,64] ]
# hill giant
dark_wizard = [ [20,46,34], [33,106,72]]
#gree_health_bar = [ [54,108,120],[62,255,255]]
#red_health_bar = [ [0,254,254],[1,255,255] ]

playScreen = Screenshot.shoot(7,27,520,360,'hsv')

low = np.array(dark_wizard[0])
high= np.array(dark_wizard[1])

mask = cv2.inRange(playScreen,low,high)

kernel = np.ones((3,3), np.uint8)

closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)

#cv2.imshow('img', closing)
#cv2.waitKey(0)

_, contours, _ = cv2.findContours(closing, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)