当前位置: 首页>>代码示例>>Python>>正文


Python cv2.fillPoly方法代码示例

本文整理汇总了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) 
开发者ID:chadrockey,项目名称:TGC-Designer-Tools,代码行数:26,代码来源:tgc_visualizer.py

示例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) 
开发者ID:chadrockey,项目名称:TGC-Designer-Tools,代码行数:19,代码来源:OSMTGC.py

示例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 
开发者ID:ChengZhongShen,项目名称:Advanced_Lane_Lines,代码行数:22,代码来源:image_process.py

示例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 
开发者ID:dmechea,项目名称:PanopticSegmentation,代码行数:18,代码来源:shapes.py

示例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) 
开发者ID:chenyilun95,项目名称:tf-cpn,代码行数:21,代码来源:mask.py

示例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 
开发者ID:SubhiH,项目名称:HandGesturesDroneController,代码行数:21,代码来源:detector_utils.py

示例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 
开发者ID:SubhiH,项目名称:HandGesturesDroneController,代码行数:21,代码来源:detector_utils.py

示例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 
开发者ID:SubhiH,项目名称:HandGesturesDroneController,代码行数:21,代码来源:detector_utils.py

示例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 
开发者ID:SubhiH,项目名称:HandGesturesDroneController,代码行数:21,代码来源:detector_utils.py

示例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)] 
开发者ID:aaalgo,项目名称:plumo,代码行数:21,代码来源:mesh.py

示例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 
开发者ID:JunshengFu,项目名称:vehicle-detection,代码行数:19,代码来源:lane.py

示例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) 
开发者ID:BerkeleyLearnVerify,项目名称:VerifAI,代码行数:22,代码来源:line_utils.py

示例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 
开发者ID:jsbroks,项目名称:imantics,代码行数:21,代码来源:annotation.py

示例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 
开发者ID:Guanghan,项目名称:lighttrack,代码行数:20,代码来源:poly_visualizer.py

示例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)) 
开发者ID:hriddhidey,项目名称:visage,代码行数:18,代码来源:apply_makeup.py


注:本文中的cv2.fillPoly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。