Python is a widely used general-purpose language. It allows performing a variety of tasks. One of them can be taking a screenshot. It provides a module named
pyautogui which can be used to take the screenshot. This module along with
NumPy and
OpenCV provides the way to manipulate and save the images (screenshot in this case)
pyautogui takes pictures as a PIL(python image library) which supports opening, manipulating, and saving many different image file formats. Then we need to convert the image to NumPy array, so that it can be converted from RGB to BGR because when the image file is read with the OpenCV using
imread(), the order of colors should be BGR (blue, green, red).
Modules needed
Below is the implementation.
import numpy as np
import cv2
import pyautogui
image = pyautogui.screenshot()
image = cv2.cvtColor(np.array(image),
cv2.COLOR_RGB2BGR)
cv2.imwrite("image1.png", image)
|
Output:
Last Updated :
03 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...