XuanChenStar/wgc_python
Tentang
ð äžäžº Python èªåšåæé ç髿§èœæªåŸåº | 180+ FPS | æ¯æåå°/鮿¡ | 坿å é¶åèåŸ æº;ð High-performance capture library for Python automation | 180+ FPS | Background/Occluded Support | Pausable (Pause/Resume) Zero-Power Standby
Produktivitas dan otomatisasiPertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- 0
- dalam 15 hari
- 0
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
Asliwgc_python
English | ç®äœäžæ
ð 䞺 Python èªåšåèçççªå£æè·åº
é«åž§çæè· · é¶èµæºåŸ æº Â· æ è§é®æ¡ · API æç®
䞺ä»ä¹éæ© wgc_pythonïŒ
ð¯ äžäžºèªåšååºæ¯è®Ÿè®¡
äœ æ¯åŠåšäžºä»¥äžé®é¢å°æ°ïŒ
- mss/BitBltïŒæ æ³æè·è¢«é®æ¡æåå°çªå£
- PrintWindowïŒæ§èœç¶é¢ïŒåºå® 26ms+ å»¶è¿
- å ¶ä» WGC å°è£ ïŒæç»è¿è¡å çšèµæºïŒé¢ç¹å¯ååŒé巚倧ïŒ50ms+ïŒ
wgc_python éè¿ Pause/Resume æºå¶è§£å³äºè¿äžªççŸïŒ
# äŒ ç»æ¹åŒïŒèŠä¹æç»ç©ºèœ¬æµªèŽ¹èµæºïŒèŠä¹é¢ç¹å¯åæ¿åå»¶è¿
start_capture() # 50ms åŒé
get_frame() # è·åæªåŸ
stop_capture() # 鿝äŒè¯ïŒ50msïŒ
# äžæ¬¡æªåŸåèŠéæ°åŒå§...
# wgc_python æ¹åŒïŒäžæ¬¡å¯åšïŒæéæªåŸïŒé¶åŒéåŸ
æº
with WindowCapture("çªå£", "ç±»å") as cap:
while running:
frame = cap.capture_one() # auto Resume â çåŸ
åž§ â æ·èŽ â Pause
# å€çåŸå...
ð æ§èœå¯¹æ¯
| æ¹æ¡ | FPS | åå°æè· | CPU å çš | é¢ç¹åæ¢åŒé | æåå GPU å çš |
|---|---|---|---|---|---|
| python-mss / BitBlt | ~60 | â | é« | äœ | N/A (æ æåæŠå¿µ) |
| PrintWindow | ~38 | â | äž | äœ | N/A (æ¯æ¬¡è°çšå³æè·) |
| å ¶ä» WGC å°è£ | é« | â | é«ïŒæç»ç©ºèœ¬ïŒ | é« (å¯åäŒè¯åŒé倧) | é« (æ æ³çæ£æå) |
| wgc_python | é« | â | æäœïŒPauseæ¶åœé¶ïŒ | æäœïŒååæ å¿äœïŒ | åœé¶ïŒæ D3D æäœïŒ |
衚äžäžºå®æ§å¯¹æ¯ïŒå ·äœæ°åŒå 硬件ãçªå£å 容äžåºæ¯èåŒïŒå»ºè®®ä»¥èªå·±ç宿µäžºåã
âš æ žå¿äŒå¿
1. é«åž§ç
- WGC çŽæ¥æè· GPU åæèŸåºïŒäžéåž§æªå±ïŒåž§çäžéè¿é«äº PrintWindow ç GDI æ¹æ¡
- åçŒå² Staging 纹çïŒGPU åŒæ¥æ·èŽïŒè¯»åäºäžé»å¡
- é¶æ·èŽå奜ïŒ
np.ndarray(strides=...)çŽæ¥ä» GPU æ å°å åæé è§åŸ
2. æºèœèµæºç®¡ç
- Pause/Resume 蜯æåïŒäžéæ¯äžé建 WGC sessionïŒä» ååæ å¿äœè·³è¿åž§å€ç
- capture_one() èªåšç®¡çïŒResume â çåŸ åž§ â æ·èŽ â PauseïŒéŽé GPU 驱åšé¶åŒé
- äŒè¯å€çšïŒé¿å é¢ç¹å建/鿝 D3D 讟å€çåŒé
3. æç® API
- capture_one()ïŒäžè¡ä»£ç 宿æéæè·ïŒè¿å numpy æ°ç»
- get_frame()ïŒé¶æ·èŽè£žæéè·¯åŸïŒé«çº§äœ¿çšïŒ
- 线çšå®å šïŒC++ å±å€çææå€çº¿çšå€ææ§
4. å€åŒå¹¶å
- åäžè¿çšå å¯åæ¶å建å€äžªæè·äŒè¯ïŒäºäžå¹²æ°
- æ¯äžªäŒè¯ç¬ç« D3D11 è®Ÿå€ + ç¬ç«çº¹ç + ç¬ç« WinRT sessionïŒå®å šé犻
- æ¯æåçªå£å€è·¯å¹¶åæè·
5. 客æ·åºç²Ÿåè£åªïŒé»è®€äžæªåæ 颿 /蟹æ¡ïŒ
- é»è®€
client_area_only=TrueïŒåªæè·çªå£å®¢æ·åºå 容ïŒèªåšè£åªæ 颿 å蟹æ¡ïŒçŽæ¥èŸåºææåçŽ - 讟眮
client_area_only=FalseïŒæè·æŽäžªçªå£ïŒå«æ 颿 å蟹æ¡ïŒïŒæ»¡è¶³ UI è®°åœåºæ¯ - DPI æç¥ïŒèªåšä¿®æ£é« DPI 猩æŸåç§»ïŒè£åªç²ŸåºŠåçŽ çº§
- GPU 级è£åªïŒ
CopySubresourceRegionåš GPU äžå®æè£åªïŒäžæµªèŽ¹åžŠå®œå CPU
6. å æ æè·åŒå ³
- é»è®€
capture_cursor=TrueïŒç»é¢å å«éŒ æ å æ ïŒäžåžžè§åœå±è¡äžºäžèŽ - 讟眮
capture_cursor=FalseïŒç»é¢äžå«éŒ æ æéïŒéåèªåšå / æ°æ®ééåºæ¯ïŒä¹å¯çšset_cursor_capture_enabled()è¿è¡æ¶åæ¢ïŒ - é Windows 10 2004 (19041) å以äžç³»ç»ïŒæ§ç³»ç»èªåšå¿œç¥è¯¥é项
7. æ è§é®æ¡
- æ¯ææè·è¢«é®æ¡ãæå°åãåå°çªå£
- å®çŸéé æžžæãæ¡é¢åºçšçåç§åºæ¯
å¿«éåŒå§
å®è£
å·²ååžè³ PyPIïŒçŽæ¥ pip å®è£ å³å¯ïŒ
pip install wgc_python
åºç¡çšæ³
from wgc_python import WindowCapture, enumerate_windows
# æäžŸææçªå£
for title, class_name in enumerate_windows():
print(f"{title} ({class_name})")
# æéæè·ïŒæšè ââ é¶åŒéåŸ
æºïŒ
with WindowCapture("çªå£æ é¢", "çªå£ç±»å") as cap:
frame = cap.capture_one() # BGRA numpy æ°ç»ïŒshape (h, w, 4)
if frame is not None:
print(f"æè·æå: {frame.shape}")
# 客æ·åºè£åªæŒç€º
# é»è®€ client_area_only=TrueïŒåªæªå客æ·åºïŒäžå«æ 颿 /蟹æ¡
cap_client = WindowCapture("è®°äºæ¬", "Notepad") # åªæªå
容
cap_full = WindowCapture("è®°äºæ¬", "Notepad", client_area_only=False) # 嫿 颿
frame_client = cap_client.capture_one() # åªæçŒèŸåº
frame_full = cap_full.capture_one() # 嫿 颿 + èå + çŒèŸåº
cap_client.close()
cap_full.close()
# äžæè·éŒ æ å
æ ïŒé»è®€ capture_cursor=TrueïŒä¿ææ§çè¡äžºïŒ
cap = WindowCapture("è®°äºæ¬", "Notepad", capture_cursor=False)
frame = cap.capture_one() # ç»é¢äžå«éŒ æ æé
cap.set_cursor_capture_enabled(True) # 乿¯æè¿è¡æ¶åæ¢
cap.close()
èªåšåæäœ³å®è·µ
from wgc_python import WindowCapture
cap = WindowCapture("æžžæçªå£", "UnityWndClass")
while True:
frame = cap.capture_one(timeout=1.0)
if frame is not None:
# frame æ¯ BGRA numpy æ°ç»ïŒçŽæ¥çšäº OpenCV/æš¡æ¿å¹é
pass
time.sleep(1)
cap.close()
æŸç€ºåšæè·ïŒæšèå šå±æžžæåºæ¯äœ¿çšïŒ
æè·ç®æ çªå£æåšçæŸç€ºåšèéçªå£æ¬èº«ïŒæè·äŒè¯ç»å®æŸç€ºåšïŒç®æ çªå£åšå šå±/çªå£ä¹éŽåæ¢äžäŒäœ¿æè·äŒè¯å€±æïŒçªå£æè·æš¡åŒäžæ€åºæ¯äŒå»ç»äºæåäžåž§ïŒã
from wgc_python import WindowCaptureMonitor
# å®äœç®æ çªå£æåšçæŸç€ºåšå¹¶æè·å
¶å
šéšå
å®¹ïŒæ 客æ·åºè£åªïŒ
cap = WindowCaptureMonitor("æžžæçªå£", "UnityWndClass")
frame = cap.capture_one() # æŽå± BGRA åž§
cap.close()
éçšåºæ¯ïŒå
šå±æžžæçé¿æèªåšåééãç®æ çªå£æŸç€ºæš¡åŒé¢ç¹ååçåºæ¯ãéèŠè£åªå®¢æ·åºææé€å
¶ä»çªå£å
容æ¶ïŒä»è¯·äœ¿çš WindowCaptureã
é¶æ·èŽé«çº§çšæ³
from wgc_python import WindowCapture
import numpy as np
import ctypes
with WindowCapture("çªå£", "ç±»å") as cap:
cap.resume()
r = cap.get_frame() # (ptr, w, h, row_pitch) â GPU æ å°è£žæé
if r:
ptr, w, h, rp = r
arr = np.ndarray((h, w, 4), dtype=np.uint8,
buffer=(ctypes.c_ubyte * (h * rp)).from_address(ptr),
strides=(rp, 4, 1))
# arr æ¯ GPU å
åçé¶æ·èŽè§åŸ
cap.release_frame()
cap.pause()
宿¶æŸç€º
from wgc_python import WindowCapture
import cv2
with WindowCapture("çªå£æ é¢", "çªå£ç±»å") as cap:
while True:
frame = cap.capture_one()
if frame is not None:
cv2.imshow("Capture", cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
API åè
from wgc_python import (
WindowCapture, # çªå£æè·ç±»ïŒäžäžæç®¡çåšæ¯æïŒ
enumerate_windows, # æäžŸææå¯è§çªå£
get_last_error, # è·åæåé误信æ¯ïŒçº¿çšå®å
šïŒ
get_active_capture_count, # è·åæŽ»è·æè·æ°
)
# WindowCapture ç±»æ¹æ³:
# cap = WindowCapture(title, class_name, client_area_only=True, capture_cursor=True)
#
# cap.capture_one(timeout=0.5) -> np.ndarray | None â
æšè
# èªåš Resume â çåŸ
åž§ â æ·èŽäžº numpy â Pause
# æè·éŽé WGC å®å
šäŒç ïŒGPU 驱åšé¶åŒé
#
# cap.get_frame() -> (ptr, w, h, row_pitch) | None
# cap.release_frame() # éæŸ GPU æ å°
# cap.pause() # æåæè·ïŒé¶èµæºåŸ
æºïŒ
# cap.resume() # æ¢å€æè·
# cap.set_cursor_capture_enabled(enabled) # è¿è¡æ¶åæ¢å
æ æè·
# cap.stop() # åæ¢åž§å°èŸŸ
# cap.close() # 鿝äŒè¯
# cap.is_capturing() -> bool
# cap.is_paused() -> bool
# cap.get_frame_count() -> int
# cap.handle -> int (DLL handle)
ææ¯æ¶æ
WGCæè· â GPU Surface纹ç
â
ââââââââââŒâââââââââ
â FrameArrived â
â if pausing â â â â Pauseæ¶çŽæ¥è¿åïŒé¶ D3D æäœ
ââââââââââ¬ââââââââââ
â
CopyResource (GPUåŒæ¥å€å¶)
â
âââââââââââââââââââââââââââ
â åçŒå²Staging纹ç â
â [0] åå
¥ ââ [1] 读å â
â m_textureInUse é²å²æ â
âââââââââââââââââââââââââââ
â
Map (æ°žä¹
æ å° GPU å
å)
â
âââââââ é¶æ·èŽèŸåº ââââââââ
â get_frame() â
â è¿å裞æé â numpyé¶æ·èŽ â
â éæåš release_frame() â
ââââââââââââââââââââââââââââ
âââââââ äžé®æè· âââââââââââ
â capture_one() â
â auto Pause/Resume â
â è¿å numpy æ°ç» â
â éŽé GPU 驱åšé¶åŒé â
ââââââââââââââââââââââââââââ
Pause/Resume å·¥äœåç
çšæ·è°çš cap.pause()
â
m_isPaused = true âââââ ååæ å¿äœïŒåŸ®ç§çº§
m_readableStagingIndex = -1
â
ââââââŒâââââââââââââââââââââââââââââââââââââââââââââ
â FrameArrived åè°ïŒWGC ä»äŒè§ŠåïŒ â
â â
â lock(mutex); â
â if (m_isPaused) return; // â 纯CPU倿ïŒè·³è¿â
â // â 以äžåªåš resume åæ§è¡ â â
â CopyResource(staging, frame); â
â m_readableStagingIndex = idx; â
â unlock(mutex); â
ââââââ²âââââââââââââââââ¬ââââââââââââââââââââââââââââ
â â
çšæ·è°çš cap.resume() MapFrame æ£æ¥ readableStagingIndex
m_isPaused = false <0 â æè¿åž§å°æªå°±ç»ªïŒè¿å false
äžéæ¯ WGC session / äžé建 D3D è®Ÿå€ / äžéæ°æ³šååè°
â æ¢å€é¶å»¶è¿ïŒæ çªåº
æä»¶ç»æ
wgc_python/
âââ wgc_python/ # Python å
â âââ __init__.py # Python APIïŒctypes FFIïŒ
â âââ wgc_python.dll # çŒè¯åç DLL
âââ wgc_python_dll/ # C++ DLL 项ç®
â âââ WGCWindowCapture.h/cpp # WGC æè·æ žå¿ïŒåçŒå² + é¶æ·èŽïŒ
â âââ WGCExport.h/cpp # DLL 富åºïŒå«çº¿çšå®å
šé误å€çïŒ
â âââ D3DInterop.cpp # D3D11 讟å€äºæäœ
â âââ WindowEnumerator.h/cpp # çªå£æäžŸ
â âââ pch.h # é¢çŒè¯å€Ž
â âââ packages/ # NuGet å
âââ test.py # åèœæµè¯
âââ demon.py # å€çº¿çšå®æ¶æŸç€ºç€ºäŸ
âââ pyproject.toml # pip æå»ºé
眮
âââ BUILD.md / BUILD_EN.md # æå»ºè¯ŽæïŒäž/è±ïŒ
âââ README.md / README_EN.md # äœ¿çšææ¡£ïŒäž/è±ïŒ
âââ CONTRIBUTING.md # èŽ¡ç®æå
âââ CODE_OF_CONDUCT.md # è¡äžºåå
âââ LICENSE # MIT 讞å¯è¯
âââ requirements.txt # Python äŸèµ
ç³»ç»èŠæ±
- Windows 10 1903+ (Build 18362)ïŒå æ æè·åŒå ³é 2004+ (Build 19041)
- Python 3.8+
æå»º DLL
è¯Šè§ BUILD.md
æ éæé€
| é®é¢ | è§£å³æ¹æ¡ |
|---|---|
| DLL æªæŸå° | ç¡®ä¿ wgc_python.dll åšæ£ç¡®äœçœ® |
| æè·å€±èŽ¥ | æ£æ¥çªå£æ¯åŠå¯è§ïŒWindows çæ¬ >= 1903 |
| äžæè·¯åŸä¿å倱莥 | äœ¿çš cv2.imencode + open().write() ä»£æ¿ cv2.imwrite |
| äŸèµçŒºå€± | pip install numpy opencv-python |
éçšåºæ¯
- â æžžæ AI / èªåšåèæ¬
- â RPA æµçšèªåšå
- â å±å¹åœå¶ / çŽæ
- â UI èªåšåæµè¯
- â è®¡ç®æºè§è§åºçš
鞣谢
æ¬é¡¹ç®åºäº robmikh/Win32CaptureSample åŒåã
License
MIT License
English
ð¯ Designed for Automation Scenarios
Are you struggling with these problems?
- mss/BitBlt: Cannot capture occluded or background windows
- PrintWindow: Performance bottleneck, fixed 26ms+ latency
- Other WGC wrappers: Continuous resource consumption, huge overhead for frequent start/stop (50ms+)
wgc_python solves this dilemma with its Pause/Resume mechanism:
# Traditional approach: Either waste resources or suffer latency
start_capture() # 50ms overhead
get_frame() # Get screenshot
stop_capture() # Destroy session (50ms)
# wgc_python approach: One-time init, on-demand capture, zero-overhead standby
with WindowCapture("Window", "Class") as cap:
while running:
frame = cap.capture_one() # auto Resume â wait â copy â Pause
# Process image...
ð Performance Comparison
| Solution | FPS | Background Capture | CPU Usage | Toggle Overhead | GPU When Paused |
|---|---|---|---|---|---|
| python-mss / BitBlt | ~60 | â | High | Low | N/A (no pause) |
| PrintWindow | ~38 | â | Medium | Low | N/A (per-call) |
| Other WGC wrappers | High | â | High (continuous) | High (session start/stop) | High (can't truly pause) |
| wgc_python | High | â | Near Zero (when paused) | Very Low (atomic flag) | Zero (no D3D ops) |
Qualitative comparison only; actual numbers vary by hardware, window content, and workload â benchmark on your own setup.
âš Core Advantages
1. High Frame Rate
- WGC captures GPU composition output directly instead of per-frame GDI screenshots â frame rate ceiling far above PrintWindow-style approaches
- Double-buffered Staging Texture: GPU async copy, read/write non-blocking
- Zero-copy path:
np.ndarray(strides=...)directly from GPU-mapped memory
2. Smart Resource Management
- Pause/Resume soft-pause: Atomic flag only, no WGC session teardown
- capture_one() auto management: Resume â wait â copy â Pause, zero GPU driver overhead between captures
- Session Reuse: No frequent D3D device creation/destruction
3. Minimalist API
- capture_one(): One-line on-demand capture, returns numpy array
- get_frame(): Zero-copy raw pointer path (advanced)
- Thread safe: C++ handles all multi-threading complexity
4. Multi-Instance Capture
- Create multiple capture sessions simultaneously within one process
- Each session has its own D3D11 device, staging textures, and WinRT session â fully isolated
- Supports concurrent capture of the same window
5. Client Area Precision (No Title Bar by Default)
- Default
client_area_only=True: captures only window client area, automatically crops title bar and borders - Set
client_area_only=False: captures entire window including title bar and borders, for UI recording - DPI-aware: automatic high-DPI scaling correction for pixel-perfect cropping
- GPU-level cropping via
CopySubresourceRegion, no wasted bandwidth or CPU
6. Cursor Capture Toggle
- Default
capture_cursor=True: frame includes the mouse cursor, same as typical screen recording - Set
capture_cursor=False: frame excludes the mouse pointer, ideal for automation / data collection (also toggleable at runtime viaset_cursor_capture_enabled()) - Requires Windows 10 2004 (19041) or later; silently ignored on older systems
7. Capture Behind Windows
- Supports capturing occluded, minimized, and background windows
- Perfect for games, desktop apps, and various scenarios
Quick Start
Installation
Published on PyPI â install directly with pip:
pip install wgc_python
Basic Usage
from wgc_python import WindowCapture, enumerate_windows
# Enumerate all windows
for title, class_name in enumerate_windows():
print(f"{title} ({class_name})")
# On-demand capture (recommended â zero-resource standby)
with WindowCapture("Window Title", "WindowClass") as cap:
frame = cap.capture_one() # BGRA numpy array, shape (h, w, 4)
if frame is not None:
print(f"Captured: {frame.shape}")
# Client area demo
# Default client_area_only=True: content only, no title bar/borders
cap_client = WindowCapture("Notepad", "Notepad") # content only
cap_full = WindowCapture("Notepad", "Notepad", client_area_only=False) # with title bar
frame_client = cap_client.capture_one() # edit area only
frame_full = cap_full.capture_one() # title bar + menu + edit area
cap_client.close()
cap_full.close()
# Disable mouse cursor capture (default capture_cursor=True, same as previous versions)
cap = WindowCapture("Notepad", "Notepad", capture_cursor=False)
frame = cap.capture_one() # frame does not contain the mouse pointer
cap.set_cursor_capture_enabled(True) # runtime toggle is also supported
cap.close()
Best Practice for Automation
from wgc_python import WindowCapture
cap = WindowCapture("Game Window", "UnityWndClass")
while True:
frame = cap.capture_one(timeout=1.0)
if frame is not None:
# frame is BGRA numpy array, ready for OpenCV/template matching
pass
time.sleep(1)
cap.close()
Zero-Copy Advanced Usage
from wgc_python import WindowCapture
import numpy as np
import ctypes
with WindowCapture("Window", "Class") as cap:
cap.resume()
r = cap.get_frame() # (ptr, w, h, row_pitch) â GPU mapped pointer
if r:
ptr, w, h, rp = r
arr = np.ndarray((h, w, 4), dtype=np.uint8,
buffer=(ctypes.c_ubyte * (h * rp)).from_address(ptr),
strides=(rp, 4, 1))
# arr is a zero-copy view into GPU-mapped memory
cap.release_frame()
cap.pause()
Real-time Display
from wgc_python import WindowCapture
import cv2
with WindowCapture("Window Title", "WindowClass") as cap:
while True:
frame = cap.capture_one()
if frame is not None:
cv2.imshow("Capture", cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
API Reference
from wgc_python import (
WindowCapture, # Window capture class (context manager support)
enumerate_windows, # Enumerate all visible windows
get_last_error, # Get last error message (thread-safe)
get_active_capture_count, # Get active capture count
)
# WindowCapture methods:
# cap = WindowCapture(title, class_name, client_area_only=True, capture_cursor=True)
#
# cap.capture_one(timeout=0.5) -> np.ndarray | None â
recommended
# Auto Resume â wait for frame â copy to numpy â Pause
# WGC fully dormant between captures, zero GPU driver overhead
#
# cap.get_frame() -> (ptr, w, h, row_pitch) | None
# cap.release_frame() # Release GPU mapping
# cap.pause() # Pause capture (zero-resource standby)
# cap.resume() # Resume capture
# cap.set_cursor_capture_enabled(enabled) # Toggle cursor capture at runtime
# cap.stop() # Stop frame arrival
# cap.close() # Destroy session
# cap.is_capturing() -> bool
# cap.is_paused() -> bool
# cap.get_frame_count() -> int
# cap.handle -> int (DLL handle)
Technical Architecture
WGC Capture â GPU Surface Texture
â
âââââââââââŒâââââââââââ
â FrameArrived â
â if pausing â â â â Paused: return directly, zero D3D ops
âââââââââââ¬âââââââââââ
â
CopyResource (GPU async copy)
â
âââââââââââââââââââââââââââââââ
â Double-buffered Staging â
â [0] Write ââ [1] Read â
â m_textureInUse anti-collide â
âââââââââââââââââââââââââââââââ
â
Map (permanently mapped GPU memory)
â
âââââââ Zero-Copy Output âââââ
â get_frame() â
â raw ptr â numpy zero-copy â
â requires release_frame() â
âââââââââââââââââââââââââââââââ
âââââââ One-Click Capture ââââ
â capture_one() â
â auto Pause/Resume â
â returns numpy array â
â zero GPU overhead when idle â
âââââââââââââââââââââââââââââââ
How Pause/Resume Works
User calls cap.pause()
â
m_isPaused = true âââââ atomic flag, microsecond-level
m_readableStagingIndex = -1
â
ââââââŒâââââââââââââââââââââââââââââââââââââââââââââ
â FrameArrived Callback (WGC still fires)â
â â
â lock(mutex); â
â if (m_isPaused) return; // â pure CPU, skipâ
â // â below runs only after resume â â
â CopyResource(staging, frame); â
â m_readableStagingIndex = idx; â
â unlock(mutex); â
ââââââ²âââââââââââââââââ¬ââââââââââââââââââââââââââââ
â â
User calls cap.resume() MapFrame checks readableStagingIndex
m_isPaused = false <0 â no frame ready â returns false
No WGC session destroy / no D3D device recreate / no callback re-register
â zero-latency resume, no spikes
File Structure
wgc_python/
âââ wgc_python/ # Python package
â âââ __init__.py # Python API (ctypes FFI)
â âââ wgc_python.dll # Compiled DLL
âââ wgc_python_dll/ # C++ DLL Project
â âââ WGCWindowCapture.h/cpp # Capture core (double-buffered + zero-copy)
â âââ WGCExport.h/cpp # DLL exports (thread-safe error handling)
â âââ D3DInterop.cpp # D3D11 device interop
â âââ WindowEnumerator.h/cpp # Window enumeration
â âââ pch.h # Precompiled header
â âââ packages/ # NuGet packages
âââ test.py # Functional tests
âââ demon.py # Threaded realtime display example
âââ pyproject.toml # pip build config
âââ BUILD.md / BUILD_EN.md # Build instructions (CN/EN)
âââ README.md / README_EN.md # Usage docs (CN/EN)
âââ CONTRIBUTING.md # Contributing guide
âââ CODE_OF_CONDUCT.md # Code of conduct
âââ LICENSE # MIT License
âââ requirements.txt # Python dependencies
Build DLL
See BUILD.md
Requirements
- Windows 10 1903+ (Build 18362); cursor capture toggle requires 2004+ (Build 19041)
- Python 3.8+
Troubleshooting
| Issue | Solution |
|---|---|
| DLL not found | Ensure wgc_python.dll is in the correct location |
| Capture failed | Check if window is visible, Windows version >= 1903 |
| Non-ASCII path save failed | Use cv2.imencode + open().write() instead of cv2.imwrite |
| Missing dependencies | pip install numpy opencv-python |
Use Cases
- â Game AI / Automation Scripts
- â RPA Process Automation
- â Screen Recording / Streaming
- â UI Automation Testing
- â Computer Vision Applications
Acknowledgments
This project is based on robmikh/Win32CaptureSample.
License
MIT License
Jelajahi proyek terkait
MemuatâŠ