0

I want to extract an Ellipse mask from an image in OpenCV Python. cv.ellipse draws the ellipse but I cant extract a mask out of it. Thanks.

Manu Jain
  • 31
  • 1
  • 6
  • 1
    A mask is just a CV_8UC1 matrix, aka uint8 numpy array with some non zero pixels. Just draw the filled ellipse with value 255 on a black matrix – Miki Dec 02 '15 at 01:25
  • The question is not clear enough, Please attach some relevant information like sample input, expected output? – ZdaR Dec 02 '15 at 05:54
  • Try leveraging https://stackoverflow.com/questions/34290781/how-to-mask-circular-area – jtlz2 Nov 02 '18 at 10:48

1 Answers1

1

This is how you would draw a blue circle, on an image, in a desired location

cv2.circle(img,(x,y), 63, (0,0,255), -1)

You will have a line of code similar to this to draw your ellipse on the image.

Draw this ellipse again on a new image:

newImg = np.zeros((height,width,3), np.uint8)
cv2.circle(newImg,(x,y), 63, (0,0,255), -1)

You will see that it is a mask! you can take those values and just keep plotting "Masks" or "Circles" or "Ellipses" (They are all the same thing in this case) to your hearts desire.

GPPK
  • 6,546
  • 4
  • 32
  • 57