def screenshot(self, amount, i): file = [] with mss.mss() as sct: for _ in range(amount): image = 'run%s.png' % i file = sct.shot(output=image, mon=1) self.image_to_array(file)
def grab_screenshot(queue): # The screen part to capture global isRunning while True: if isRunning: # shot_start = time.perf_counter() print("New shot.") # 720/2 - 150 print(str(top) + ", " + str(left)) monitor = {"top": top, "left": left, "width": 300, "height": 300} #fname = cwd + '\j_' + str(i) + '-' + str(version) + '.png' img = mss.mss().grab(monitor) #https://stackoverflow.com/questions/51488275/cant-record-screen-using-mss-and-cv2 img = np.array(img) # Retrieve as BGRA img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) # Reshape to RGB queue.put(img) # shot_end = time.perf_counter() # print("Shot finished in " + str(shot_end - shot_start) + " sec") # threading.Timer(0.0, run_model, args=(False, queue,)).start() run_model(False, queue) # queue.join() # run_model(img, False) #mss.tools.to_png(img.rgb, img.size, output=fname) return
def capture_images(nImages=150, delay=1 / 15, top=0, left=0, width=1000, height=1000): """ Capture and save screenshots""" try: os.mkdir("capture") except: pass with mss.mss() as sct: monitor = { "top": top, "left": left, "width": int(width), "height": int(height) } #output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor) sct.compression_level = 2 #sct_img = sct.grab(monitor) for n in range(nImages): sct_img = sct.grab(monitor) mss.tools.to_png(sct_img.rgb, sct_img.size, output=f'capture/{n}.png'.format(**monitor)) print(n) time.sleep(delay)
def screenshot(self, amount, i): file = [] with mss.mss() as sct: for _ in range(amount): image = 'run%s.png' % i file = sct.shot(output=image, mon=2) print(file) self.crop_im(image, i)
def takeshot_center(): # The screen part to capture global i cwd = os.getcwd() monitor = {"top": 210, "left": 490, "width": 300, "height": 300} fname = cwd + '\j_' + str(i) + '-' + str(version) + '.png' img = mss.mss().grab(monitor) mss.tools.to_png(img.rgb, img.size, output=fname) i += 1
def start(self): self.isRecording = True self.create_metadata() try: with mss.mss() as sct: while self.isRecording: self.capture_joystick(self.joystick, self.id) self.capture_screen(sct, self.id) self.id = self.id + 1 except Exception as e: raise e
def really_processing(): try: screen_path = os.path.join(self.cur_dir, "__TEMP__.png") screen_path = os.path.abspath(screen_path) img = "" #Делаем скриншот if self.chosen_opt.get() == CHSE_OWN: ch1x = int(self.btn_choose1_X.get()) ch1y = int(self.btn_choose1_Y.get()) ch2x = int(self.btn_choose2_X.get()) ch2y = int(self.btn_choose2_Y.get()) capture_space = { "top": ch1x, "left": ch1y, "width": ch2x - ch1x, "height": ch2y - ch1y } with mss.mss() as print_screen: img = print_screen.grab(capture_space) mss.tools.to_png(img.rgb, img.size, output=screen_path) elif self.chosen_opt.get() == CHSE_FS: with mss.mss() as print_screen: img = print_screen.shot(output=screen_path) #Работа с docx и doc файлами section = self.document.sections[0] section.left_margin = docx.shared.Cm(1) section.right_margin = docx.shared.Cm(1) section.top_margin = docx.shared.Cm(1) section.bottom_margin = docx.shared.Cm(1) self.document.add_picture(screen_path, width=section.page_width - section.left_margin - section.right_margin) self.document.save(file_path) os.remove(screen_path) except Exception as err: err_queue.put((err.__class__, traceback.format_exc())) self.root.event_generate("<<On error>>")
def grab_screenshot(): # The screen part to capture while True: if isRunning: monitor = {"top": top, "left": left, "width": 300, "height": 300} img = mss.mss().grab(monitor) #https://stackoverflow.com/questions/51488275/cant-record-screen-using-mss-and-cv2 img = np.array(img) # Retrieve as BGRA img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) # Reshape to RGB imageScreenshot.img = img return
def takeshot_center(): # The screen part to capture # 720/2 - 150 print(str(top) + ", " + str(left)) monitor = {"top": top, "left": left, "width": 300, "height": 300} #fname = cwd + '\j_' + str(i) + '-' + str(version) + '.png' img = mss.mss().grab(monitor) #https://stackoverflow.com/questions/51488275/cant-record-screen-using-mss-and-cv2 img = np.array(img) # Retrieve as BGRA img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) # Reshape to RGB test(img)
def grab_screen(coordinates): """Grabs a screenshot from the coordinated provided""" with mss.mss() as sct: # print("League window coordinates: ", coordinates) league_img = np.array(sct.grab(coordinates)) return league_img
y0 = pos1[1] width = np.abs(pos2[0] - pos1[0]) height = np.abs(pos1[1] - pos2[1]) for fase in g_i.Phases[:]: g_i.setcurrentphase(fase) time.sleep(2) print(fase.Identification.value) naam = fase.Identification.value with mss.mss() as sct: # The screen part to capture # monitor = {"top": 200, "left": 500, "width": 1300, "height": 650} monitor = { "top": int(y0), "left": int(x0), "width": int(width), "height": int(height) } output = str(naam + ".png".format(**monitor)) # Grab the data sct_img = sct.grab(monitor) # Save to the picture file mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
def screenshot(self, amount, i): file = [] with mss.mss() as sct: for _ in range(amount): file=sct.shot(output ='run%s.png' %i)
def exit_func(event): del event self_import.Windows.unbind('<B1-Motion>') # pylint: disable=E1101 self_import.Windows.unbind( '<ButtonRelease-1>') # pylint: disable=E1101 self_import.Windows.unbind('<F2>') # pylint: disable=E1101 imags, cords = [], [] for x in self.all_cord_mnogo: if x[2] == 0 and x[3] == 0: continue with mss.mss() as sct: cords.append(x[0]) cords.append(x[1]) cords.append(x[2]) cords.append(x[3]) monitor = {"top": x[0], "left": x[1], "width": x[2], "height": x[3]} try: img = resize(array( sct.grab(monitor)), (0, 0), fx=10, fy=10) img = GaussianBlur(img, (11, 11), 0) imags.append(img) except Exception: continue self_import.paint.pack_forget() # self.bat1.pack() self_import.Windows.geometry( '145x32+{}+{}'.format(self.location_window[0], self.location_window[1])) self_import.Windows.update() self_import.Windows.overrideredirect(0) self_import.Windows.update() self_import.START() self_import.lab0['width'] = 25 # self.Windows.bind('F4',skrinshot_bid) i = 0 for y in imags: try: a = pytesseract.image_to_string(y, lang='eng') if a != '': self_import.skrin_shot_batton['text'] = '[+]' self_import.Switches_radio.set('0') if i == 0: self_import.text_box.insert( tkinter.INSERT, '{} '.format(a)) else: self_import.text_box.insert( tkinter.INSERT, '\n\\/-------------{}-------------------\\/\n {} '.format(i+1, a)) i += 1 try: os.remove('Photo\\except_photo{}.png'.format(i)) except FileNotFoundError: pass else: self_import.skrin_shot_batton['text'] = '[-]' imwrite('Photo\\except_photo{}.png'.format(i), y) except pytesseract.pytesseract.TesseractNotFoundError: if 'tesseract-ocr.exe' in os.listdir(os.getcwd()): os.system('tesseract-ocr.exe') return self_import.text_box.delete(1.0, tkinter.END) self_import.text_box.insert( tkinter.INSERT, 'Для работы этой функции необходимо устоновить tesseract по ссылки\nhttps://github.com/UB-Mannheim/tesseract/wiki\nУкажите при устоновки следующий путь\nC:\\Program Files\\Tesseract-OCR') return except pytesseract.pytesseract.TesseractError: self_import.text_box.delete(1.0, tkinter.END) self_import.text_box.insert( tkinter.INSERT, 'Выбраный язык не устоновлен - выберите этот язык при устоновки') return
def skrinshot_s_class(self, self_import, AVTO_S=0): def exit_func(event): del event self_import.Windows.unbind('<B1-Motion>') # pylint: disable=E1101 self_import.Windows.unbind( '<ButtonRelease-1>') # pylint: disable=E1101 self_import.Windows.unbind('<F2>') # pylint: disable=E1101 imags, cords = [], [] for x in self.all_cord_mnogo: if x[2] == 0 and x[3] == 0: continue with mss.mss() as sct: cords.append(x[0]) cords.append(x[1]) cords.append(x[2]) cords.append(x[3]) monitor = {"top": x[0], "left": x[1], "width": x[2], "height": x[3]} try: img = resize(array( sct.grab(monitor)), (0, 0), fx=10, fy=10) img = GaussianBlur(img, (11, 11), 0) imags.append(img) except Exception: continue self_import.paint.pack_forget() # self.bat1.pack() self_import.Windows.geometry( '145x32+{}+{}'.format(self.location_window[0], self.location_window[1])) self_import.Windows.update() self_import.Windows.overrideredirect(0) self_import.Windows.update() self_import.START() self_import.lab0['width'] = 25 # self.Windows.bind('F4',skrinshot_bid) i = 0 for y in imags: try: a = pytesseract.image_to_string(y, lang='eng') if a != '': self_import.skrin_shot_batton['text'] = '[+]' self_import.Switches_radio.set('0') if i == 0: self_import.text_box.insert( tkinter.INSERT, '{} '.format(a)) else: self_import.text_box.insert( tkinter.INSERT, '\n\\/-------------{}-------------------\\/\n {} '.format(i+1, a)) i += 1 try: os.remove('Photo\\except_photo{}.png'.format(i)) except FileNotFoundError: pass else: self_import.skrin_shot_batton['text'] = '[-]' imwrite('Photo\\except_photo{}.png'.format(i), y) except pytesseract.pytesseract.TesseractNotFoundError: if 'tesseract-ocr.exe' in os.listdir(os.getcwd()): os.system('tesseract-ocr.exe') return self_import.text_box.delete(1.0, tkinter.END) self_import.text_box.insert( tkinter.INSERT, 'Для работы этой функции необходимо устоновить tesseract по ссылки\nhttps://github.com/UB-Mannheim/tesseract/wiki\nУкажите при устоновки следующий путь\nC:\\Program Files\\Tesseract-OCR') return except pytesseract.pytesseract.TesseractError: self_import.text_box.delete(1.0, tkinter.END) self_import.text_box.insert( tkinter.INSERT, 'Выбраный язык не устоновлен - выберите этот язык при устоновки') return def one(event): def paint_square(self, event=0): if self.x == 0 and self.y == 0: self.x = event.x self.y = event.y else: self_import.paint.delete('circle') self_import.paint.create_rectangle( event.x, event.y, self.x, self.y, outline='blue', tag='circle') if event.num == 1: ######################################### x0, x_max = self.x, event.x X = x0-x_max if X < 0: X *= -1 else: x0, x_max = x_max, x0 ######################################### y0, y_max = self.y, event.y Y = y0-y_max if Y < 0: Y *= -1 else: y0, y_max = y_max, y0 ######################################### self.x = self.y = 0 if x0 == 0 and y0 == 0: exit_func(self) return rrr = (y0, x0, X, Y, x_max, y_max) self.all_cord_mnogo.append(rrr) self_import.paint.create_rectangle( x_max, y_max, x0, y0, outline='blue', tag=str(x_max)) else: paint_square(self, event) if not ORC_check: self_import.lab0['text'] = ' NO ORC ' return False self_import.STOP() self_import.bat1.pack_forget() self_import.frame1.pack() self_import.lab0.pack() self_import.lab0['width'] = 45 self_import.lab0['text'] = '-------- [F2] --------' self_import.Windows.update() with mss.mss() as sct: monitor = {"top": 0, "left": 0, "width": GetSystemMetrics( 0), "height": GetSystemMetrics(1)} mss.tools.to_png(sct.grab(monitor).rgb, sct.grab( monitor).size, output='Photo\\photo_t.png') self_import.lab0.pack_forget() self_import.frame1.pack_forget() self_import.Windows.overrideredirect(1) global imgas # pylint: disable=E1101 imgas = ImageTk.PhotoImage(Image.open('Photo\\photo_t.png')) self_import.paint.create_image(0, 0, anchor=tkinter.NW, image=imgas) self.location_window = ( self_import.Windows.winfo_x(), self_import.Windows.winfo_y()) self_import.paint.pack() self_import.Windows.geometry( '{}x{}+0+0'.format(self_import.Windows.winfo_screenwidth(), self_import.Windows.winfo_screenheight())) self_import.Windows.update() self.Auto_capture = 0 if AVTO_S == 1: self.Auto_capture = 1 self_import.Windows.bind('<B1-Motion>', one) self_import.Windows.bind('<ButtonRelease-1>', one) self_import.Windows.bind('<F2>', exit_func)
def __init__(self): self.joystick = Joystick() self.id = 0 self.dir = "" self.isRecording = False self.sct = mss.mss()