Hier ist mein aktuell In Bezug auf die Screenshoting des Bildschirms basierend auf einem Toggle -Switch habe ich ihn nur zum Laufen gebracht, wenn die Skript -Screenshots bereits. < /p>
Code: Select all
import os
import numpy as np
import cv2
from mss import mss
from datetime import datetime
import time
def main():
capturing = False
# Create output directory
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
capture_number = 0
# Initialize screen capture
with mss() as sct:
monitor = sct.monitors[1] # Adjust the monitor index as needed
interval = 0.1 # Capture interval (10 times per second)
try:
print("Press 's' to start/stop capturing screenshots...")
while True:
start_time = time.time()
frame = np.array(sct.grab(monitor))
if capturing:
name = os.path.join(output_dir, f"capture{capture_number}.png")
cv2.imwrite(name, frame)
# Check for key press to toggle capturing
if cv2.waitKey(1) & 0xFF == ord('s'):
capturing = not capturing
# Sleep to maintain capture rate
sleep_time = interval - (time.time() - start_time)
if sleep_time > 0:
time.sleep(sleep_time)
capture_number +=1
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()