forked from GayWindTech/TransAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screenshot.py
33 lines (26 loc) · 966 Bytes
/
Screenshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Union
import pyautogui
import cv2
import numpy as np
global WindowName
WindowName = "Please choose the subtitle area"
def getScreenPos() -> tuple:
PosList = []
img = pyautogui.screenshot() # x,y,w,h
img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
cv2.namedWindow(WindowName, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(WindowName, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow(WindowName, img)
PosList = cv2.selectROI(
windowName=WindowName, img=img, showCrosshair=False, fromCenter=False
)
cv2.destroyAllWindows()
return PosList
def getScreenshot(Pos: Union[list, tuple, set]):
x, y, w, h = Pos
Screenshot = pyautogui.screenshot(region=(x, y, w, h)) # x,y,w,h
Screenshot = cv2.cvtColor(np.asarray(Screenshot), cv2.COLOR_RGB2BGR)
return Screenshot
# cv2.imshow('1',getScreenshot(getScreenPos()))
# cv2.waitKey(0)
# print(OCR(getScreenshot(getScreenPos())))