A contour is simply a curve joining all continuous points so to create your own contour, you can create a np.array()
with your (x,y)
points in clockwise order
points = np.array([[25,25], [70,10], [150,50], [250,250], [100,350]])
That's it!
There are two methods to draw the contour onto an image depending on what you need:
Contour outline
If you only need the contour outline, use cv2.drawContours()
cv2.drawContours(image,[points],0,(0,0,0),2)
Filled contour
To get a filled contour, you can either use cv2.fillPoly()
or cv2.drawContours()
with thickness=-1
cv2.fillPoly(image, [points], [0,0,0]) # OR
# cv2.drawContours(image,[points],0,(0,0,0),-1)
Full example code for completeness
import cv2
import numpy as np
# Create blank white image
image = np.ones((400,400), dtype=np.uint8) * 255
# List of (x,y) points in clockwise order
points = np.array([[25,25], [70,10], [150,50], [250,250], [100,350]])
# Draw points onto image
cv2.drawContours(image,[points],0,(0,0,0),2)
# Fill points onto image
# cv2.fillPoly(image, [points], [0,0,0])
cv2.imshow('image', image)
cv2.waitKey()