The main goal of masking regions of interest is to color filter an image to perform different operations. For instance, when an autonomous car is driving on the road, the region of interest for the car is the lane lines because it must be driven on the road. In the following steps, we will see an example of how to determine a region of interest when applied to the lane lines on a road:
- Firstly, import the matplotlib (mpimg and pyplot), numpy, and openCV libraries:
In[1]: import cv2
In[2]: import numpy as np
In[3]: import matplotlib.image as mpimg
In[4]: from matplotlib import pyplot as plt
In[5]: %matplotlib inline
- Next, we will read the input image:
In[6]: image_color = cv2.imread('lanes.jpg')
In[7]: cv2.imshow('Original Image', image_color)
In[8]: cv2.waitKey()
In[9]: cv2.destroyAllWindows()
The input image looks like this:
Fig 4.71: Input image
The height and width of the image are as follows:
In[10]: height...