메랜 매크로 기술: 자동 채녈 변경

홈페이지 »

메뉴 인식

미니맵으로 타유저 인식후 자동 채녈 변경처리. 이미지 인식으로 메뉴 인식후 클릭

메뉴사진

                import pyautogui
                from window_mouse_hander import  click_window_center
                import time
                from PIL import ImageGrab
                import win32gui
                from minimap_detector import GameWindowLocator
                import win32gui
                import win32con
                import  time
                import  random
                import win32api
                import os
                import cv2
                
                main_img = "./BB/main.jpg"
                
                class Menu:
                    def __init__(self):
                        self.channel_running = True
                        self.quit_state = True
                
                
                    def capture_window(self,hwnd):
                        """
                        화면 캡쳐
                        """
                        rect = win32gui.GetWindowRect(hwnd)
                
                        image = ImageGrab.grab(rect)
                        return image
                
                
                    #메뉴 찾기
                    def match_template(self,img_path,template_path,val=0.3):
                        best_match = {
                            'value': 0,
                            'position': None,
                            'template_name': None
                        }
                        frame = cv2.imread(img_path)
                        template = cv2.imread(template_path)
                
                
                        result = cv2.matchTemplate(frame, template, cv2.TM_CCOEFF_NORMED)
                        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
                        print("max_val",max_val)
                
                        if max_val >= val :
                            h, w = template.shape[:2]
                            x = max_loc[0] + w // 2
                            y = max_loc[1] + h // 2
                
                            best_match['value'] = max_val
                            best_match['position'] = (max_loc[0], max_loc[1], w, h, max_val)
                            print(best_match['position'])
                            best_match['template_name'] = ""
                
                            if best_match['position']:
                                x, y, w, h, similarity = best_match['position']
                                color = (0, 255, 0)  
                
                
                            return best_match
                        return best_match
                
                
                
                    #채녈 변경
                    def change_channel(self,window_locator):
                
                
                        if not window_locator:
                            window_locator = GameWindowLocator()
                        while not window_locator.get_window_rect():
                            time.sleep(0.5)
                
                
                
                        x, y, w, h = window_locator.get_window_rect()
                        self.move_window_to_top_left(window_locator.hwnd)
                        time.sleep(0.2)
                        click_window_center(w - 1000, h - 200)
                        time.sleep(0.2)
                        click_window_center(901, 580)
                        time.sleep(0.2)
                
                        screen_shot = self.capture_window(window_locator.hwnd)
                
                        #메뉴 찾기
                        screen_shot.save(main_img)
                        template_path = os.path.join('BB', 'menu', 'menu.png')
                        menu_match = self.match_template(main_img, template_path)
                        x, y, w, h, confidence = menu_match['position']
                        click_window_center(x + w // 2, y + h // 2)
                        time.sleep(1.5)
                
                        # 채널 메뉴 찾기
                        screen_shot = self.capture_window(window_locator.hwnd)
                        screen_shot.save(main_img)
                        template_path = os.path.join('BB', 'channel', 'channel_menu.png')
                        menu_match = self.match_template(main_img, template_path)
                        print("channel_menu", menu_match)
                        if not menu_match['position']:
                            return
                        x, y, w, h, confidence = menu_match['position']
                        click_window_center(x + w // 2, y + h // 2)
                        time.sleep(1)
                
                        # 노란색 채널 찾기
                        screen_shot = self.capture_window(window_locator.hwnd)
                        screen_shot.save(main_img)
                        template_path = os.path.join('BB', 'channel', 'channel_lsit.png')
                        menu_match = self.match_best_template(main_img,template_path )
                        x, y, w, h, confidence = menu_match['position']
                        click_window_center(x + w // 2, y + h // 2)
                        time.sleep(1)
                
                        # 확인 버튼 찾기
                        screen_shot = self.capture_window(window_locator.hwnd)
                        screen_shot.save(main_img)
                        template_path = os.path.join('BB', 'channel', 'confirm.png')
                        menu_match = self.match_template(main_img, template_path)
                        x, y, w, h, confidence = menu_match['position']
                        click_window_center(x + w // 2, y + h // 2)
                        time.sleep(0.3)
                        click_window_center(x + w // 2, y + h // 2)
                        time.sleep(1)
                
                
                
                if __name__ == '__main__':
                    menu = Menu()
                    menu.change_channel(None)