motherloader.py 文件源码

python
阅读 14 收藏 0 点赞 0 评论 0

项目:osrmacro 作者: jjvilm 项目源码 文件源码
def find_motherload_mine():
    """Returns mine's location x, and y coords"""
    play_img,psx,psy = RS.getPlayingScreen()


    mines = {
        0: (np.array([0,0,153]), np.array([8,25,209])),
        1: (np.array([0,0,72]), np.array([2,25,144]))
    }

    for mine_key  in mines.keys():
        #print("Mine: {}".format(mine_key))
        lower = mines[mine_key][0]
        upper = mines[mine_key][1]

        mask = cv2.inRange(play_img, lower, upper)

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

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


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

        _, contours, _ = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        if contours[0].any():
            pass
        else:
            print('didnt find contours')
            break

        for con in contours[::-1]:
            M = cv2.moments(con)
            if cv2.contourArea(con) > 20:
                # Shows the mask

                #centroid from img moments
                cx = int(M['m10']/M['m00'])
                cy = int(M['m01']/M['m00'])

                #combine psx,psy coords with centroid coords from above
                cx += psx
                cy += psy

                #print("Area:",cv2.contourArea(con))
                #print(con[0][0][0],con[0][0][1])
                Mouse.moveClick(cx,cy, 1)
                return cx,cy
            else:
                continue
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号