本文目录导读:

Python + PyAutoGUI + Pillow (最通用)
自动截图脚本
import pyautogui
import time
from PIL import Image, ImageDraw, ImageFont
import os
from datetime import datetime
class ScreenshotTool:
def __init__(self, save_dir="screenshots"):
self.save_dir = save_dir
if not os.path.exists(save_dir):
os.makedirs(save_dir)
def capture_full_screen(self):
"""截取全屏"""
screenshot = pyautogui.screenshot()
return screenshot
def capture_region(self, x, y, width, height):
"""截取指定区域"""
screenshot = pyautogui.screenshot(region=(x, y, width, height))
return screenshot
def add_text_annotation(self, image, text, position=(10, 10),
font_size=30, color=(255, 0, 0)):
"""添加文字标注"""
draw = ImageDraw.Draw(image)
try:
font = ImageFont.truetype("arial.ttf", font_size)
except:
font = ImageFont.load_default()
draw.text(position, text, font=font, fill=color)
return image
def add_rectangle_annotation(self, image, bbox, outline_color=(255, 0, 0),
outline_width=3, fill_color=None):
"""添加矩形标注"""
draw = ImageDraw.Draw(image)
draw.rectangle(bbox, outline=outline_color, width=outline_width,
fill=fill_color)
return image
def add_arrow_annotation(self, image, start_pos, end_pos,
color=(255, 0, 0), width=3):
"""添加箭头标注"""
draw = ImageDraw.Draw(image)
draw.line([start_pos, end_pos], fill=color, width=width)
return image
def save_screenshot(self, image, filename=None):
"""保存截图"""
if filename is None:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"screenshot_{timestamp}.png"
filepath = os.path.join(self.save_dir, filename)
image.save(filepath)
print(f"截图保存至: {filepath}")
return filepath
# 使用示例
if __name__ == "__main__":
tool = ScreenshotTool()
# 延迟5秒后截图(方便准备)
print("5秒后开始截图...")
time.sleep(5)
# 全屏截图
screenshot = tool.capture_full_screen()
# 添加标注
screenshot = tool.add_text_annotation(
screenshot,
"示例标注文字",
position=(100, 100),
font_size=40,
color=(0, 255, 0)
)
# 添加矩形标注
screenshot = tool.add_rectangle_annotation(
screenshot,
bbox=[200, 200, 400, 400],
outline_color=(255, 0, 0),
outline_width=5
)
# 保存
tool.save_screenshot(screenshot)
OpenCV + PyAutoGUI (更丰富的标注功能)
import cv2
import numpy as np
import pyautogui
import time
class OpenCvScreenshotTool:
def __init__(self):
pass
def capture_screen(self):
"""截取屏幕"""
screenshot = pyautogui.screenshot()
frame = np.array(screenshot)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
return frame
def add_circle_annotation(self, frame, center, radius, color=(0, 255, 0),
thickness=2):
"""添加圆形标注"""
return cv2.circle(frame, center, radius, color, thickness)
def add_text_annotation(self, frame, text, position, font_scale=1,
color=(0, 0, 255), thickness=2):
"""添加文字标注"""
font = cv2.FONT_HERSHEY_SIMPLEX
return cv2.putText(frame, text, position, font, font_scale,
color, thickness, cv2.LINE_AA)
def add_blur_effect(self, frame, x, y, w, h, kernel_size=(51, 51)):
"""添加模糊效果(用于遮挡敏感信息)"""
roi = frame[y:y+h, x:x+w]
blurred_roi = cv2.GaussianBlur(roi, kernel_size, 0)
frame[y:y+h, x:x+w] = blurred_roi
return frame
def highlight_region(self, frame, x, y, w, h):
"""高亮特定区域"""
overlay = frame.copy()
cv2.rectangle(overlay, (x, y), (x+w, y+h), (255, 255, 0), -1)
frame = cv2.addWeighted(overlay, 0.3, frame, 0.7, 0)
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 255, 0), 2)
return frame
def save_and_show(self, frame, filename="screenshot.png"):
"""保存并显示截图"""
cv2.imwrite(filename, frame)
cv2.imshow("Screenshot", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
# 使用示例
if __name__ == "__main__":
tool = OpenCvScreenshotTool()
print("5秒后开始截图...")
time.sleep(5)
# 截图
frame = tool.capture_screen()
# 添加各种标注
frame = tool.add_circle_annotation(frame, (500, 300), 50, (0, 255, 0), 3)
frame = tool.add_text_annotation(frame, "重要标注", (450, 250), 1.5, (0, 0, 255), 3)
frame = tool.highlight_region(frame, 200, 200, 300, 200)
frame = tool.add_blur_effect(frame, 700, 100, 200, 100)
# 保存
tool.save_and_show(frame)
定时自动截图脚本
import schedule
import time
from datetime import datetime
import pyautogui
import os
class TimedScreenshotTool:
def __init__(self, interval_minutes=30, save_dir="timed_screenshots"):
self.interval = interval_minutes
self.save_dir = save_dir
if not os.path.exists(save_dir):
os.makedirs(save_dir)
def take_screenshot_with_timestamp(self):
"""定时截图并添加时间戳"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
filename = datetime.now().strftime("%Y%m%d_%H%M%S")
screenshot = pyautogui.screenshot()
# 添加时间戳
from PIL import ImageDraw, ImageFont
draw = ImageDraw.Draw(screenshot)
draw.text((10, 10), timestamp, fill=(255, 0, 0))
filepath = os.path.join(self.save_dir, f"{filename}.png")
screenshot.save(filepath)
print(f"[{timestamp}] 截图已保存: {filepath}")
return filepath
def start_timed_capture(self):
"""启动定时截图"""
print(f"开始定时截图,间隔: {self.interval} 分钟")
print("按 Ctrl+C 停止运行")
# 立即执行一次
self.take_screenshot_with_timestamp()
# 设置定时任务
schedule.every(self.interval).minutes.do(self.take_screenshot_with_timestamp)
try:
while True:
schedule.run_pending()
time.sleep(1)
except KeyboardInterrupt:
print("定时截图已停止")
# 使用示例
if __name__ == "__main__":
tool = TimedScreenshotTool(interval_minutes=30) # 每30分钟截图一次
tool.start_timed_capture()
交互式截图标注工具
import cv2
import numpy as np
import pyautogui
class InteractiveScreenshotTool:
def __init__(self):
self.drawing = False
self.start_point = None
self.end_point = None
def mouse_callback(self, event, x, y, flags, param):
"""鼠标回调函数"""
if event == cv2.EVENT_LBUTTONDOWN:
self.drawing = True
self.start_point = (x, y)
self.end_point = (x, y)
elif event == cv2.EVENT_MOUSEMOVE:
if self.drawing:
self.end_point = (x, y)
elif event == cv2.EVENT_LBUTTONUP:
self.drawing = False
self.end_point = (x, y)
def interactive_capture(self):
"""交互式截图标注"""
print("3秒后开始截图...")
time.sleep(3)
# 截图
screenshot = pyautogui.screenshot()
frame = np.array(screenshot)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
# 创建窗口并绑定鼠标事件
window_name = "Interactive Screenshot"
cv2.namedWindow(window_name)
cv2.setMouseCallback(window_name, self.mouse_callback)
while True:
temp_frame = frame.copy()
# 绘制矩形
if self.start_point and self.end_point:
cv2.rectangle(temp_frame, self.start_point, self.end_point,
(0, 255, 0), 2)
cv2.imshow(window_name, temp_frame)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'): # 按q退出
break
elif key == ord('s'): # 按s保存
cv2.imwrite("interactive_screenshot.png", temp_frame)
print("截图已保存")
cv2.destroyAllWindows()
# 使用示例
if __name__ == "__main__":
import time
tool = InteractiveScreenshotTool()
tool.interactive_capture()
安装依赖
# 基础依赖 pip install pyautogui pillow opencv-python numpy # 定时任务依赖 pip install schedule # 可选:windows截图 pip install mss pillow
使用方法
- 基本截图:
python screenshot.py - 定时截图:设置间隔时间(分钟)
- 交互式标注:用鼠标框选区域,添加文字
- 批量处理:对多个截图自动添加水印或标注
这些脚本可以根据你的具体需求进行定制和扩展!
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播