V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
clockzhong
V2EX  ›  Python

如何超清截屏?

  •  
  •   clockzhong · 312 天前 · 1699 次点击
    这是一个创建于 312 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在用 Pyautogui + opencv 做一个自动化脚本,在识别桌面上的图标时总是识别不准。感觉微信和 windows 原生截屏都压缩严重(截屏部分已经很精准了,基本没有冗余空白区域),有没有什么工具或者方法让截屏不被压缩或者有没有比 pyautogui 更好的解决方案? location = pyautogui.locateCenterOnScreen(img, confidence=0.9)

    6 条回复    2023-06-25 10:33:42 +08:00
    qq78660651
        1
    qq78660651  
       312 天前
    网易的 airtest ?
    clockzhong
        2
    clockzhong  
    OP
       312 天前
    @qq78660651 看起来好像不错,去试试先,谢谢
    JimmyB
        3
    JimmyB  
       312 天前
    你是用 mac 吗
    zhengsidao
        4
    zhengsidao  
       312 天前
    Snipaste 这个不管是 win 还是 mac 都非常好用,很清晰
    liantian
        5
    liantian  
       308 天前 via iPad   ❤️ 1
    penll
        6
    penll  
       308 天前
    import mss
    from PIL import Image
    import os

    class CaptureHelper:

    def screenshot(self, screen_idex, target_path = "_temp_capture_target_window.png"):
    with mss.mss() as sct:
    target_monitor = sct.monitors[screen_idex + 1]

    root_path = 'TODO:获取保存路径'
    save_path = os.path.join(root_path, "_temp", target_path)

    img = sct.grab(target_monitor)
    pil_image = Image.frombytes("RGB", img.size, img.bgra, "raw", "BGRX")
    pil_image.save(save_path)# cv2.imwrite(save_path, img) opencv 不支持中文路径

    return save_path



    --------------
    我这边简单写的。支持多显示器。
    注意:opencv 的保持不支持中文路径,所以,用 pillow 的保存
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3136 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:18 · PVG 21:18 · LAX 06:18 · JFK 09:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.