![]() ![]() ![]() Let’s now load this image from disk and perform masking: # load the original input image and display it to our screen ![]() We go ahead and default the -image argument to the adrian.png file in our project directory. We only need a single switch here, -image, which is the path to the image we want to mask. We then parse our command line arguments on Lines 7-10. Lines 2-4 import our required Python packages. # construct the argument parser and parse the argumentsĪp.add_argument("-i", "-image", type=str, default="adrian.png", Open the opencv_masking.py file in your project directory structure, and let’s get to work: # import the necessary packages Let’s learn how to apply image masking using OpenCV! We’ll then use masking to extract both the body and face from the image using rectangular and circular masks, respectively. Our opencv_masking.py script will load the input adrian.png image from disk. Your project folder should look like the following: $ tree. Start by using the “Downloads” section of this guide to access the source code and example image. But before we write any code, let’s first review our project directory structure. Performing image masking with OpenCV is easier than you think. Gain access to Jupyter Notebooks for this tutorial and other PyImageSearch guides that are pre-configured to run on Google Colab’s ecosystem right in your web browser! No installation required.Īnd best of all, these Jupyter Notebooks will run on Windows, macOS, and Linux! Project structure Then join PyImageSearch University today! Ready to run the code right now on your Windows, macOS, or Linux systems?.Wanting to skip the hassle of fighting with the command line, package managers, and virtual environments?.Learning on your employer’s administratively locked system?.To learn how to perform image masking with OpenCV, just keep reading.įigure 1: Having trouble configuring your development environment? Want access to pre-configured Jupyter Notebooks running on Google Colab? Be sure to join PyImageSearch Plus - you will be up and running with this tutorial in a matter of minutes. When applying transparency to images with OpenCV, we need to tell OpenCV what parts of the image transparency should be applied to versus not - masks allow us to make that distinction. Provided that we could find the faces in the image, we may construct a mask to show only the faces in the image.Īnother image masking application you’ll encounter is alpha blending and transparency (e.g., in this guide on Creating GIFs with OpenCV). The only part of the image we are interested in finding and describing is the parts of the image that contain faces - we simply don’t care about the rest of the image’s content. Put simply a mask allows us to focus only on the portions of the image that interests us.įor example, let’s say that we were building a computer vision system to recognize faces. This allows us to extract regions from images that are of completely arbitrary shape. My previous guide discussed bitwise operations, a very common set of techniques used heavily in image processing.Īnd as I hinted previously, we can use both bitwise operations and masks to construct ROIs that are non-rectangular. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |