mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-09 12:37:12 +00:00
feat: use mss instead of imagegrab
This commit is contained in:
parent
c24d9cc2e9
commit
30f9a45d8a
@ -42,6 +42,7 @@ dependencies = [
|
|||||||
"timm",
|
"timm",
|
||||||
"einops",
|
"einops",
|
||||||
"modelscope",
|
"modelscope",
|
||||||
|
"mss",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
@ -4,11 +4,11 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
from PIL import Image, ImageGrab
|
from PIL import Image
|
||||||
import imagehash
|
import imagehash
|
||||||
from memos.utils import write_image_metadata
|
from memos.utils import write_image_metadata
|
||||||
from screeninfo import get_monitors
|
|
||||||
import ctypes
|
import ctypes
|
||||||
|
from mss import mss
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
import win32gui
|
import win32gui
|
||||||
@ -173,25 +173,17 @@ def take_screenshot_windows(
|
|||||||
app_name,
|
app_name,
|
||||||
window_title,
|
window_title,
|
||||||
):
|
):
|
||||||
for monitor in get_monitors():
|
with mss() as sct:
|
||||||
safe_monitor_name = "".join(
|
for i, monitor in enumerate(sct.monitors[1:], 1): # Skip the first monitor (entire screen)
|
||||||
c for c in monitor.name if c.isalnum() or c in ("_", "-")
|
safe_monitor_name = f"monitor_{i}"
|
||||||
)
|
|
||||||
logging.info(f"Processing monitor: {safe_monitor_name}")
|
logging.info(f"Processing monitor: {safe_monitor_name}")
|
||||||
|
|
||||||
webp_filename = os.path.join(
|
webp_filename = os.path.join(
|
||||||
base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.webp"
|
base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.webp"
|
||||||
)
|
)
|
||||||
|
|
||||||
img = ImageGrab.grab(
|
img = sct.grab(monitor)
|
||||||
bbox=(
|
img = Image.frombytes("RGB", img.size, img.bgra, "raw", "BGRX")
|
||||||
monitor.x,
|
|
||||||
monitor.y,
|
|
||||||
monitor.x + monitor.width,
|
|
||||||
monitor.y + monitor.height,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
img = img.convert("RGB")
|
|
||||||
current_hash = str(imagehash.phash(img))
|
current_hash = str(imagehash.phash(img))
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user