1- from typing import List , Optional
1+ from typing import List , Optional , Union , Tuple
22
33import numpy as np
44import geojson
@@ -21,23 +21,22 @@ def geometry(self) -> geojson.MultiPolygon:
2121 def raster (self ,
2222 height : Optional [int ] = None ,
2323 width : Optional [int ] = None ,
24- color = (255 , 255 , 255 ),
25- thickness = - 1 ,
26- canvas = None ) -> np .ndarray :
24+ color : Union [ int , Tuple ] = (255 , 255 , 255 ),
25+ thickness : int = - 1 ,
26+ canvas : Optional [ np . ndarray ] = None ) -> np .ndarray :
2727 """
2828 Draw the polygon onto a 3d mask
2929 Args:
3030 height (int): height of the mask
3131 width (int): width of the mask
32- color (int): color for the polygon. Only a single int since this is a grayscale mask.
32+ color (int): color for the polygon.
33+ RGB values by default but if a 2D canvas is provided this can set this to an int.
34+ thickness (int): How thick to make the polygon border. -1 fills in the polygon
35+ canvas (np.ndarray): Canvas to draw the polygon on
3336 Returns:
3437 numpy array representing the mask with the polygon drawn on it.
3538 """
36- if canvas is None :
37- if height is None or width is None :
38- raise ValueError (
39- "Must either provide canvas or height and width" )
40- canvas = np .zeros ((height , width , 3 ), dtype = np .uint8 )
39+ canvas = self .get_or_create_canvas (height , width , canvas )
4140 pts = np .array (self .geometry ['coordinates' ]).astype (np .int32 )
4241 if thickness == - 1 :
4342 return cv2 .fillPoly (canvas , pts , color )
0 commit comments