python - How to Mask an image using Numpy/OpenCV? -


I load an image I:

  im = the cv2.imread (file Name)  

I want to put that image in the center of the image. I have created a circle in the area as a mask that I want to keep.

I made a circle with it:

  height, width, depth = im.shape circle = np .zeros ((height, width)) cv2.circle (circle , (Width / 2, height / 2), 280,1, thickness = -1)  

Can I mask out the original image?

  masked_data = im * cycle  

does not work. Of

data p outside the circle of <>

cv2.bitwise_and and mask Chakra passes in the form

  im = cv2.imread (filename) height, width, depth = im.shape circle_img = np.zeros ((height, width), np.uint8) cv2.circle (circle_img (width / 2, height / 2), 280.1, thickness = -1) masked_data = cv2.bitwise_and (IM, IM, mask = circle_img) cv2.imshow ( "masked", masked_data) cv2.waitKey (0)  

Comments