asweigart/pyscreeze là dự án mã nguồn mở trên GitHub với 221 sao, viết chủ yếu bằng Python. PyScreeze is a simple, cross-platform screenshot module for Python 2 and 3.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
PyScreeze is a simple, cross-platform screenshot module for Python 3.
About
PyScreeze can take screenshots, save them to files, and locates images within the screen. This is useful if you have a small image of, say, a button that needs to be clicked and want to locate it on the screen.
NOTE - PyScreeze depends on Pillow for screenshots, whose older versions have security issues. The only secure versions of Pillow are 8.3.2 and later. However, Pillow 8.3.2 only supports Python as far back as Python 3.6. If you are installing PyScreeze for Python 3.5 or earlier, be aware that there may be security issues with the version of Pillow it uses.
If Pillow is unavailable, there are fallback methods for each OS (screencapture for macOS, gnome-screenshot for Linux, etc.)
Special Notes About Ubuntu
If your Ubuntu system uses the older X11 window system, you must install Xlib by running sudo apt install python3-xlib. This will require the admin password for your computer.
The screenshot() Function
Calling screenshot() will return an Image object (see the Pillow or PIL module documentation for details). Passing a string of a filename will save the screenshot to a file as well as return it as an Image object.
On a 1920 x 1080 screen, the screenshot() function takes roughly 100 milliseconds - it's not fast but it's not slow.
There is also an optional region keyword argument, if you do not want a screenshot of the entire screen. You can pass a four-integer tuple of the left, top, width, and height of the region to capture:
>>> import pyscreeze
>>> im = pyscreeze.screenshot(region=(0,0, 300, 400))
The Locate Functions
You can visually locate something on the screen if you have an image file of it. You can call the locateOnScreen('calc7key.png') function to get the screen coordinates of the 7 button for a calculator app. The return value is a 4-integer tuple: (left, top, width, height). This tuple can be passed to center() to get the X and Y coordinates at the center of this region. If the image can't be found on the screen, locateOnScreen() returns None. (PyAutoGUI is a module that simulates mouse clicks.)
>>> import pyscreeze, pyautogui
>>> button7location = pyscreeze.locateOnScreen('calc7key.png')
>>> button7location
(1416, 562, 50, 41)
>>> button7x, button7y = pyscreeze.center(button7location)
>>> button7x, button7y
(1441, 582)
>>> pyautogui.click(button7x, button7y) # clicks the center of where the 7 button was found
The locateCenterOnScreen() function is probably the one you want to use most often:
On a 1920 x 1080 screen, the locate function calls take about 1 or 2 seconds. This may be too slow for action video games, but works for most purposes and applications.
If speed is important, install the optional opencv library (pip install cv2). The locateAll computation will use it if available, and take less than 1 millisecond to find all matches in a full-screen search. (This does not include the time required to capture a screenshot.)
There are several "locate" functions. They all start looking at the top-left corner of the screen (or image) and look to the left and then down. The arguments can either be a
locateOnScreen(image, grayscale=False) - Returns (left, top, width, height) coordinate of first found instance of the image on the screen. Returns None if not found on the screen.
locateCenterOnScreen(image, grayscale=False) - Returns (x, y) coordinates of the center of the first found instance of the image on the screen. Returns None if not found on the screen.
locateAllOnScreen(image, grayscale=False) - Returns a generator that yields (left, top, width, height) tuples for where the image is found on the screen.
locate(needleImage, haystackImage, grayscale=False) - Returns (left, top, width, height) coordinate of first found instance of needleImage in haystackImage. Returns None if not found on the screen.
locateAll(needleImage, haystackImage, grayscale=False) - Returns a generator that yields (left, top, width, height) tuples for where needleImage is found in haystackImage.
The "locate all" functions can be used in for loops or passed to list():
Optionally, you can pass grayscale=True to the locate functions to give a slight speedup (about 30%-ish). This desaturates the color from the images and screenshots, speeding up the locating but potentially causing false-positive matches.
If you just need to verify that a single pixel matches a given pixel, call the pixelMatchesColor() function, passing it the X coordinate, Y coordinate, and RGB tuple of the color it represents:
asweigart/pyscreeze có 221 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/asweigart/pyscreeze. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
asweigart/pyscreeze có phải mã nguồn mở không?
Có — asweigart/pyscreeze phát hành theo license BSD-3-Clause, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/asweigart/pyscreeze.
asweigart/pyscreeze còn đang phát triển không?
Commit gần nhất trên asweigart/pyscreeze là 2.0 năm trước (theo timestamp GitHub). Repo có 108 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
asweigart/pyscreeze là gì?
asweigart/pyscreeze (asweigart/pyscreeze) là dự án Python trên GitHub. Theo mô tả gốc: PyScreeze is a simple, cross-platform screenshot module for Python 2 and 3.
Đọc thêm về asweigart/pyscreeze ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/asweigart/pyscreeze là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về pyscreeze?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về pyscreeze.