Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. image_test = params.small_images[0]
  2. mask = np.zeros(image_test.shape, dtype=np.uint8)
  3. roi_corners = np.array([[0, 14], [13.33, 28], [26.66, 28], [39, 14], [26.66, 0], [13.33, 0]], dtype=np.int32)
  4. # fill the ROI so it doesn't get wiped out when the mask is applied
  5. channel_count = image_test.shape[2]  # i.e. 3 or 4 depending on your image
  6. ignore_mask_color = (255,)*channel_count
  7. cv.fillConvexPoly(mask, roi_corners, ignore_mask_color)
  8. # apply the mask
  9. masked_image = cv.bitwise_and(image_test, mask)
  10. # save the result
  11. cv.imwrite('image_masked.png', masked_image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement