How to take screenshots using python?
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
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).
- Numpy: To install Numpy type the below command in the terminal.
pip install numpy
- pyautogui: To install pyautogui type the below command in the terminal.
pip install pyautogui
- OpenCV: To install OpenCV type the below command in the terminal.
pip install opencv-python
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course