-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
56 lines (47 loc) · 1.75 KB
/
test.py
File metadata and controls
56 lines (47 loc) · 1.75 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from wgc_python import *
import numpy as np
import cv2
import time
windows = enumerate_windows()
for title, cls in windows[:10]:
print(f"标题: {title}, 类名: {cls}")
if start_capture("记事本", "Notepad"):
print("捕获已启动")
print(f"初始状态 - is_capturing: {is_capturing()}, is_paused: {is_paused()}")
last_time = time.time()
frame_count = 0
paused = False
while True:
if not paused:
result = get_frame()
if result:
data, width, height = result
frame_count += 1
img = np.frombuffer(data, dtype=np.uint8).reshape(height, width, 4)
img_bgr = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
if frame_count % 30 == 0:
fps = 30 / (time.time() - last_time)
cv2.setWindowTitle("Capture", f"FPS: {fps:.1f} (Paused: {paused})")
last_time = time.time()
cv2.imshow("Capture", img_bgr)
else:
# 显示暂停状态
cv2.setWindowTitle("Capture", f"Paused - FPS: 0.0")
time.sleep(0.1) # 减少CPU占用
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
elif key == ord('p'): # 按P键暂停/恢复
paused = not paused
if paused:
pause_capture()
print(f"已暂停 - is_paused: {is_paused()}")
else:
resume_capture()
print(f"已恢复 - is_paused: {is_paused()}")
last_time = time.time()
frame_count = 0
stop_capture()
cv2.destroyAllWindows()
else:
print("捕获启动失败")