本文整理匯總了Python中cv2.fillPoly方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.fillPoly方法的具體用法?Python cv2.fillPoly怎麽用?Python cv2.fillPoly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.fillPoly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: drawSplinesOnImage
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def drawSplinesOnImage(splines, color, im, pc, image_scale):
for s in splines:
# Get the shape of this spline and draw it on the image
nds = []
for wp in s["waypoints"]:
nds.append(pc.tgcToCV2(wp["waypoint"]["x"], wp["waypoint"]["y"], image_scale))
# Don't try to draw malformed splines
if len(nds) == 0:
continue
# Uses points and not image pixels, so flip the x and y
nds = np.array(nds)
nds[:,[0, 1]] = nds[:,[1, 0]]
nds = np.int32([nds]) # Bug with fillPoly, needs explict cast to 32bit
thickness = int(s["width"])
if(thickness < image_scale):
thickness = int(image_scale)
if s["isFilled"]:
cv2.fillPoly(im, nds, color, lineType=cv2.LINE_AA)
else:
cv2.polylines(im, nds, s["isClosed"], color, thickness, lineType=cv2.LINE_AA)
示例2: drawWayOnImage
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def drawWayOnImage(way, color, im, pc, image_scale, thickness=-1, x_offset=0.0, y_offset=0.0):
# Get the shape of this way and draw it as a poly
nds = []
for node in way.get_nodes(resolve_missing=True): # Allow automatically resolving missing nodes, but this is VERY slow with the API requests, try to request them above instead
nds.append(pc.latlonToCV2(node.lat, node.lon, image_scale, x_offset, y_offset))
# Uses points and not image pixels, so flip the x and y
nds = np.array(nds)
nds[:,[0, 1]] = nds[:,[1, 0]]
nds = np.int32([nds]) # Bug with fillPoly, needs explict cast to 32bit
cv2.fillPoly(im, nds, color)
# Add option to draw shape again, but with thick line
# Use this to automatically expand some shapes, for example water
# For better masking
if thickness > 0:
# Need to draw again since fillPoly has no line thickness options that I've found
cv2.polylines(im, nds, True, color, thickness, lineType=cv2.LINE_AA)
示例3: draw_lane_fit
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_lane_fit(undist, warped ,Minv, left_fitx, right_fitx, ploty):
# Drawing
# Create an image to draw the lines on
warp_zero = np.zeros_like(warped).astype(np.uint8)
color_warp = np.dstack((warp_zero, warp_zero, warp_zero))
# Recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
pts = np.hstack((pts_left, pts_right))
# Draw the lane onto the warped blank image
cv2.fillPoly(color_warp, np.int_([pts]), (0,255,0))
# Warp the blank back to original image space using inverse perspective matrix(Minv)
newwarp = cv2.warpPerspective(color_warp, Minv, (undist.shape[1], undist.shape[0]))
# Combine the result with the original image
result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0)
return result
示例4: draw_shape
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_shape(self, image, shape, dims, color):
"""Draws a shape from the given specs."""
# Get the center x, y and the size s
x, y, s = dims
if shape == 'square':
image = cv2.rectangle(image, (x - s, y - s),
(x + s, y + s), color, -1)
elif shape == "circle":
image = cv2.circle(image, (x, y), s, color, -1)
elif shape == "triangle":
points = np.array([[(x, y - s),
(x - s / math.sin(math.radians(60)), y + s),
(x + s / math.sin(math.radians(60)), y + s),
]], dtype=np.int32)
image = cv2.fillPoly(image, points, color)
return image
示例5: showMask
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def showMask(img_obj):
img = cv2.imread(img_obj['fpath'])
img_ori = img.copy()
gtmasks = img_obj['gtmasks']
n = len(gtmasks)
print(img.shape)
for i, mobj in enumerate(gtmasks):
if not (type(mobj['mask']) is list):
print("Pass a RLE mask")
continue
else:
pts = np.round(np.asarray(mobj['mask'][0]))
pts = pts.reshape(pts.shape[0] // 2, 2)
pts = np.int32(pts)
color = np.uint8(np.random.rand(3) * 255).tolist()
cv2.fillPoly(img, [pts], color)
cv2.addWeighted(img, 0.5, img_ori, 0.5, 0, img)
cv2.imshow("Mask", img)
cv2.waitKey(0)
示例6: draw_right_arrow
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_right_arrow(img,shift_arrow):
wheel_color = (200,200,200)
shift_from_center = 55
overlay = img.copy()
# (2) draw shapes:
# (3) blend with the original:
opacity = 0.7
cv2.line(overlay,(int((img.shape[1]/2)-shift_from_center+shift_arrow*5),int(img.shape[0]/2)),(int(((img.shape[1]/2))+shift_from_center+shift_arrow*5),int(img.shape[0]/2)),wheel_color , 15)
pts = np.array([[int(((img.shape[1]/2))+shift_from_center+shift_arrow*5)+25,int(img.shape[0]/2)]
,[int(((img.shape[1]/2))+shift_from_center+shift_arrow*5),int(img.shape[0]/2)-25],
[int(((img.shape[1]/2))+shift_from_center+shift_arrow*5),int(img.shape[0]/2)+25]],
np.int32)
pts = pts.reshape((-1,1,2))
# cv2.fillPoly(img,[pts],wheel_color,-1)
cv2.fillPoly(overlay, [pts], wheel_color, 8)
cv2.addWeighted(overlay, opacity, img, 1 - opacity, 0, img)
return img
示例7: draw_left_arrow
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_left_arrow(img,shift_arrow):
wheel_color = (200,200,200)
shift_from_center = 55
overlay = img.copy()
# (2) draw shapes:
# (3) blend with the original:
opacity = 0.7
cv2.line(overlay,(int((img.shape[1]/2)-shift_from_center-shift_arrow*5),int(img.shape[0]/2)),(int(((img.shape[1]/2))+shift_from_center-shift_arrow*5),int(img.shape[0]/2)),wheel_color , 15)
pts = np.array([[int(((img.shape[1]/2))-shift_from_center-shift_arrow*5)-25,int(img.shape[0]/2)]
,[int(((img.shape[1]/2))-shift_from_center-shift_arrow*5),int(img.shape[0]/2)-25],
[int(((img.shape[1]/2))-shift_from_center-shift_arrow*5),int(img.shape[0]/2)+25]],
np.int32)
pts = pts.reshape((-1,1,2))
# cv2.fillPoly(img,[pts],wheel_color,-1)
cv2.fillPoly(overlay, [pts], wheel_color, 8)
cv2.addWeighted(overlay, opacity, img, 1 - opacity, 0, img)
return img
示例8: draw_up_arrow
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_up_arrow(img,shift_arrow):
wheel_color = (200,200,200)
shift_from_center = 55
overlay = img.copy()
# (2) draw shapes:
# (3) blend with the original:
opacity = 0.7
cv2.line(overlay,(int((img.shape[1]/2)),int(img.shape[0]/2)-shift_from_center-shift_arrow*5),(int(((img.shape[1]/2))),int(img.shape[0]/2)+shift_from_center-shift_arrow*5),wheel_color , 15)
pts = np.array([[int((img.shape[1]/2)),int((img.shape[0]/2-shift_from_center-shift_arrow*5))-25]
,[int((img.shape[1]/2))-25,int((img.shape[0]/2)-shift_from_center-shift_arrow*5)],
[int((img.shape[1]/2))+25,int((img.shape[0]/2-shift_from_center-shift_arrow*5))]],
np.int32)
pts = pts.reshape((-1,1,2))
# cv2.fillPoly(img,[pts],wheel_color,-1)
cv2.fillPoly(overlay, [pts], wheel_color, 8)
cv2.addWeighted(overlay, opacity, img, 1 - opacity, 0, img)
return img
示例9: draw_down_arrow
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_down_arrow(img,shift_arrow):
wheel_color = (200,200,200)
shift_from_center = 55
overlay = img.copy()
# (2) draw shapes:
# (3) blend with the original:
opacity = 0.7
cv2.line(overlay,(int((img.shape[1]/2)),int(img.shape[0]/2)-shift_from_center+shift_arrow*5),(int(((img.shape[1]/2))),int(img.shape[0]/2)+shift_from_center+shift_arrow*5),wheel_color , 15)
pts = np.array([[int((img.shape[1]/2)),int((img.shape[0]/2+shift_from_center+shift_arrow*5))+25]
,[int((img.shape[1]/2))-25,int((img.shape[0]/2)+shift_from_center+shift_arrow*5)],
[int((img.shape[1]/2))+25,int((img.shape[0]/2+shift_from_center+shift_arrow*5))]],
np.int32)
pts = pts.reshape((-1,1,2))
# cv2.fillPoly(img,[pts],wheel_color,-1)
cv2.fillPoly(overlay, [pts], wheel_color, 8)
cv2.addWeighted(overlay, opacity, img, 1 - opacity, 0, img)
return img
示例10: fill_convex
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def fill_convex (image):
H, W = image.shape
padded = np.zeros((H+20, W+20), dtype=np.uint8)
padded[10:(10+H),10:(10+W)] = image
contours = measure.find_contours(padded, 0.5)
if len(contours) == 0:
return image
if len(contours) == 1:
contour = contours[0]
else:
contour = np.vstack(contours)
cc = np.zeros_like(contour, dtype=np.int32)
cc[:,0] = contour[:, 1]
cc[:,1] = contour[:, 0]
hull = cv2.convexHull(cc)
contour = hull.reshape((1, -1, 2))
cv2.fillPoly(padded, contour, 1)
return padded[10:(10+H),10:(10+W)]
示例11: compute_car_offcenter
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def compute_car_offcenter(ploty, left_fitx, right_fitx, undist):
# Create an image to draw the lines on
height = undist.shape[0]
width = undist.shape[1]
# Recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
pts = np.hstack((pts_left, pts_right))
bottom_l = left_fitx[height-1]
bottom_r = right_fitx[0]
offcenter = off_center(bottom_l, width/2.0, bottom_r)
return offcenter, pts
示例12: draw
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw(self, mask, color=(255, 0, 0), line_width=50, average=False):
"""
Draw the line on a color mask image.
"""
h, w, c = mask.shape
plot_y = np.linspace(0, h - 1, h)
coeffs = self.average_fit if average else self.last_fit_pixel
line_center = coeffs[0] * plot_y ** 2 + coeffs[1] * plot_y + coeffs[2]
line_left_side = line_center - line_width // 2
line_right_side = line_center + line_width // 2
# Some magic here to recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array(list(zip(line_left_side, plot_y)))
pts_right = np.array(np.flipud(list(zip(line_right_side, plot_y))))
pts = np.vstack([pts_left, pts_right])
# Draw the lane onto the warped blank image
return cv2.fillPoly(mask, [np.int32(pts)], color)
示例13: mask
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def mask(self, width=None, height=None):
"""
Returns or generates :class:`Mask` representation of polygons.
:returns: Mask representation
:rtype: :class:`Mask`
"""
if not self._c_mask:
size = height, width if height and width else self.bbox().max_point
# Generate mask from polygons
mask = np.zeros(size)
mask = cv2.fillPoly(mask, self.points, 1)
self._c_mask = Mask(mask)
self._c_mask._c_polygons = self
return self._c_mask
示例14: draw_poly
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def draw_poly(mask, poly, track_id=-1):
"""
Draw a polygon in the img.
Args:
img: np array of type np.uint8
poly: np array of shape N x 2
"""
if track_id == -1:
color = (255*rand(), 255*rand(), 255*rand())
else:
color_list = ['purple', 'yellow', 'blue', 'green', 'red', 'skyblue', 'navyblue', 'azure', 'slate', 'chocolate', 'olive', 'orange', 'orchid']
color_name = color_list[track_id % 13]
color = find_color_scalar(color_name)
poly = np.array(poly, dtype=np.int32)
cv2.fillPoly(mask, [poly], color=color)
return mask
示例15: __fill_lip_solid
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillPoly [as 別名]
def __fill_lip_solid(self, outer, inner):
""" Fills solid colour inside two outlines. """
inner[0].reverse()
inner[1].reverse()
outer_curve = zip(outer[0], outer[1])
inner_curve = zip(inner[0], inner[1])
points = []
for point in outer_curve:
points.append(np.array(point, dtype=np.int32))
for point in inner_curve:
points.append(np.array(point, dtype=np.int32))
points = np.array(points, dtype=np.int32)
self.red_l = int(self.red_l)
self.green_l = int(self.green_l)
self.blue_l = int(self.blue_l)
cv2.fillPoly(self.image, [points], (self.red_l, self.green_l, self.blue_l))