scripts/detection_util.py
def region_of_interest(img, vertices):
  """
  Applies an image mask.

  Only keeps the region of the image defined by the polygon
  formed from `vertices`. The rest of the image is set to black.
  """
  # defining a blank mask to start with
  mask = np.zeros_like(img)

  # defining a 3 channel or 1 channel color to fill the mask with depending on the input image
  if len(img.shape) > 2:
    channel_count = img.shape[2]  # i.e. 3 or 4 depending on your image
    ignore_mask_color = (255,) * channel_count
  else:
    ignore_mask_color = 255

  # filling pixels inside the polygon defined by "vertices" with the fill color
  cv2.fillPoly(mask, vertices, ignore_mask_color)
  # plt.imshow(mask)
  # plt.show()

  # returning the image only where mask pixels are nonzero
  masked_image = cv2.bitwise_and(img, mask)
  return masked_image

  Applies an image mask.

  Only keeps the region of the image defined by the polygon
  formed from `vertices`. The rest of the image is set to black.
  
Applies an image mask.
Only keeps the region of the image defined by the polygon
formed from `vertices`. The rest of the image is set to black.
Applies an image mask . Only keeps the region of the image defined by the polygon formed from ` vertices ` . The rest of the image is set to black .
def region_of_interest(img, vertices):
  mask = np.zeros_like(img)
  if len(img.shape) > 2:
    channel_count = img.shape[2]  
    ignore_mask_color = (255,) * channel_count
  else:
    ignore_mask_color = 255
  cv2.fillPoly(mask, vertices, ignore_mask_color)
  masked_image = cv2.bitwise_and(img, mask)
  return masked_image
def region_of_interest ( img , vertices ) : mask = np . zeros_like ( img ) if len ( img . shape ) > 2 : channel_count = img . shape [ 2 ] ignore_mask_color = ( 255 , ) * channel_count else : ignore_mask_color = 255 cv2 . fillPoly ( mask , vertices , ignore_mask_color ) masked_image = cv2 . bitwise_and ( img , mask ) return masked_image
Applies an image mask.
Applies an image mask .
"""
  Applies an image mask.

  Only keeps the region of the image defined by the polygon
  formed from `vertices`. The rest of the image is set to black.
  """ # defining a blank mask to start with # defining a 3 channel or 1 channel color to fill the mask with depending on the input image # i.e. 3 or 4 depending on your image # filling pixels inside the polygon defined by "vertices" with the fill color # plt.imshow(mask) # plt.show() # returning the image only where mask pixels are nonzero
img
vertices