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


Python cv2.LINE_8属性代码示例

本文整理汇总了Python中cv2.LINE_8属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.LINE_8属性的具体用法?Python cv2.LINE_8怎么用?Python cv2.LINE_8使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.LINE_8属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cv2_draw_3d_bbox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def cv2_draw_3d_bbox(img, bboxes, colors, thickness=1, line_type=cv2.LINE_8):
    # assume bboxes has right format(N, 8, 2).
    bboxes = bboxes.astype(np.int32)
    for box, color in zip(bboxes, colors):
        color = tuple(int(c) for c in color)
        box_a, box_b = box[:4], box[4:]
        for pa, pb in zip(box_a, box_a[[1, 2, 3, 0]]):
            cv2.line(img, (int(pa[0]), int(pa[1])), (int(pb[0]), int(pb[1])),
                     color, thickness, line_type)
        for pa, pb in zip(box_b, box_b[[1, 2, 3, 0]]):
            cv2.line(img, (int(pa[0]), int(pa[1])), (int(pb[0]), int(pb[1])),
                     color, thickness, line_type)
        for pa, pb in zip(box_a, box_b):
            cv2.line(img, (int(pa[0]), int(pa[1])), (int(pb[0]), int(pb[1])),
                     color, thickness, line_type)
    return img 
开发者ID:traveller59,项目名称:second.pytorch,代码行数:18,代码来源:bbox_plot.py

示例2: draw_circle

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def draw_circle(canvas, xy, r=1, stroke=None, fill=None, thickness=1, antialias=False):
    x,y = tuple(map(int, xy))
    line_type = cv2.LINE_AA if antialias else cv2.LINE_8
    if fill is not None:
        cv2.circle(canvas, (x,y), r, fill, -1, line_type)
    if stroke is not None:
        cv2.circle(canvas, (x,y), r, stroke, thickness, line_type)

# @njit
# def draw_circle(canvas, xy, r, fill):
#     x,y = xy
#     r2 = r * r
#     for i in range(canvas.shape[0]):
#         cy = i - y
#         cy2 = cy * cy
#         for j in range(canvas.shape[1]):
#             cx = j - x
#             ls = cx * cx + cy2
#             if ls < r2:
#                 canvas[i,j] = fill 
开发者ID:kylemcdonald,项目名称:python-utils,代码行数:22,代码来源:draw_shapes.py

示例3: draw_boxed_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def draw_boxed_text(img, text, topleft, color):
    """Draw a transluent boxed text in white, overlayed on top of a
    colored patch surrounded by a black border. FONT, TEXT_SCALE,
    TEXT_THICKNESS and ALPHA values are constants (fixed) as defined
    on top.

    # Arguments
      img: the input image as a numpy array.
      text: the text to be drawn.
      topleft: XY coordinate of the topleft corner of the boxed text.
      color: color of the patch, i.e. background of the text.

    # Output
      img: note the original image is modified inplace.
    """
    assert img.dtype == np.uint8
    img_h, img_w, _ = img.shape
    if topleft[0] >= img_w or topleft[1] >= img_h:
        return img
    margin = 3
    size = cv2.getTextSize(text, FONT, TEXT_SCALE, TEXT_THICKNESS)
    w = size[0][0] + margin * 2
    h = size[0][1] + margin * 2
    # the patch is used to draw boxed text
    patch = np.zeros((h, w, 3), dtype=np.uint8)
    patch[...] = color
    cv2.putText(patch, text, (margin+1, h-margin-2), FONT, TEXT_SCALE,
                WHITE, thickness=TEXT_THICKNESS, lineType=cv2.LINE_8)
    cv2.rectangle(patch, (0, 0), (w-1, h-1), BLACK, thickness=1)
    w = min(w, img_w - topleft[0])  # clip overlay at image boundary
    h = min(h, img_h - topleft[1])
    # Overlay the boxed text onto region of interest (roi) in img
    roi = img[topleft[1]:topleft[1]+h, topleft[0]:topleft[0]+w, :]
    cv2.addWeighted(patch[0:h, 0:w, :], ALPHA, roi, 1 - ALPHA, 0, roi)
    return img 
开发者ID:cristianpb,项目名称:object-detection,代码行数:37,代码来源:utils.py

示例4: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def __init__(self, category, colors=[], thickness=3, line_type=cv2.LINE_8, shift=0, font_face=cv2.FONT_HERSHEY_SIMPLEX, font_scale=1):
        self.category = category
        if colors:
            self.colors = [tuple(map(lambda c: c * 255, matplotlib.colors.colorConverter.to_rgb(c)[::-1])) for c in colors]
        else:
            self.colors = [tuple(map(lambda c: c * 255, matplotlib.colors.colorConverter.to_rgb(prop['color'])[::-1])) for prop in plt.rcParams['axes.prop_cycle']]
        self.thickness = thickness
        self.line_type = line_type
        self.shift = shift
        self.font_face = font_face
        self.font_scale = font_scale 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:visualize.py

示例5: cv2_draw_lines

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def cv2_draw_lines(img, lines, colors, thickness, line_type=cv2.LINE_8):
    lines = lines.astype(np.int32)
    for line, color in zip(lines, colors):
        color = list(int(c) for c in color)
        cv2.line(img, (line[0], line[1]), (line[2], line[3]), color, thickness)
    return img 
开发者ID:traveller59,项目名称:second.pytorch,代码行数:8,代码来源:simplevis.py

示例6: cv2_draw_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def cv2_draw_text(img, locs, labels, colors, thickness, line_type=cv2.LINE_8):
    locs = locs.astype(np.int32)
    font_line_type = cv2.LINE_8
    font = cv2.FONT_ITALIC
    font = cv2.FONT_HERSHEY_DUPLEX
    font = cv2.FONT_HERSHEY_PLAIN
    font = cv2.FONT_HERSHEY_SIMPLEX
    for loc, label, color in zip(locs, labels, colors):
        color = list(int(c) for c in color)
        cv2.putText(img, label, tuple(loc), font, 0.7, color, thickness,
                    font_line_type, False)
    return img 
开发者ID:traveller59,项目名称:second.pytorch,代码行数:14,代码来源:simplevis.py

示例7: cv2_draw_bbox_with_label

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def cv2_draw_bbox_with_label(img,
                             bboxes,
                             colors,
                             labels=None,
                             label_colors=None,
                             thickness=1,
                             line_type=cv2.LINE_8,
                             font_line_type=cv2.LINE_8):
    # assume bboxes has right format.
    bboxes = bboxes.astype(np.int32)
    if label_colors is None:
        label_colors = colors
    if labels is None:
        labels = [None] * bboxes.shape[0]

    font = cv2.FONT_ITALIC
    font = cv2.FONT_HERSHEY_DUPLEX
    font = cv2.FONT_HERSHEY_PLAIN
    font = cv2.FONT_HERSHEY_SIMPLEX
    for bbox, color, label, label_color in zip(bboxes, colors, labels,
                                               label_colors):
        color = tuple(int(c) for c in color)
        label_color = tuple(int(c) for c in label_color)
        cv2.rectangle(img, tuple(bbox[:2]), tuple(bbox[2:]), color, thickness,
                      line_type)
        if label is not None:
            cv2.putText(img, label, tuple(bbox[:2]), font, 1, label_color,
                        thickness, font_line_type, False)
    return img 
开发者ID:traveller59,项目名称:second.pytorch,代码行数:31,代码来源:bbox_plot.py

示例8: draw_boxed_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def draw_boxed_text(img, text, topleft, color):
    """Draw a transluent boxed text in white, overlayed on top of a
    colored patch surrounded by a black border. FONT, TEXT_SCALE,
    TEXT_THICKNESS and ALPHA values are constants (fixed) as defined
    on top.

    # Arguments
      img: the input image as a numpy array.
      text: the text to be drawn.
      topleft: XY coordinate of the topleft corner of the boxed text.
      color: color of the patch, i.e. background of the text.

    # Output
      img: note the original image is modified inplace.
    """
    assert img.dtype == np.uint8
    img_h, img_w, _ = img.shape
    if topleft[0] >= img_w or topleft[1] >= img_h:
        return
    margin = 3
    size = cv2.getTextSize(text, FONT, TEXT_SCALE, TEXT_THICKNESS)
    w = size[0][0] + margin * 2
    h = size[0][1] + margin * 2
    # the patch is used to draw boxed text
    patch = np.zeros((h, w, 3), dtype=np.uint8)
    patch[...] = color
    cv2.putText(patch, text, (margin+1, h-margin-2), FONT, TEXT_SCALE,
                WHITE, thickness=TEXT_THICKNESS, lineType=cv2.LINE_8)
    cv2.rectangle(patch, (0, 0), (w-1, h-1), BLACK, thickness=1)
    w = min(w, img_w - topleft[0])  # clip overlay at image boundary
    h = min(h, img_h - topleft[1])
    # Overlay the boxed text onto region of interest (roi) in img
    roi = img[topleft[1]:topleft[1]+h, topleft[0]:topleft[0]+w, :]
    cv2.addWeighted(patch[0:h, 0:w, :], ALPHA, roi, 1 - ALPHA, 0, roi)
    return img 
开发者ID:dataplayer12,项目名称:homesecurity,代码行数:37,代码来源:visualization.py

示例9: add_text_to_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def add_text_to_image(image,
                      text='',
                      position=None,
                      font=cv2.FONT_HERSHEY_TRIPLEX,
                      font_size=1.0,
                      line_type=cv2.LINE_8,
                      line_width=1,
                      color=(255, 255, 255)):
  """Overlays text on given image.

  NOTE: The input image is assumed to be with `RGB` channel order.

  Args:
    image: The image to overlay text on.
    text: Text content to overlay on the image. (default: '')
    position: Target position (bottom-left corner) to add text. If not set,
      center of the image will be used by default. (default: None)
    font: Font of the text added. (default: cv2.FONT_HERSHEY_TRIPLEX)
    font_size: Font size of the text added. (default: 1.0)
    line_type: Line type used to depict the text. (default: cv2.LINE_8)
    line_width: Line width used to depict the text. (default: 1)
    color: Color of the text added in `RGB` channel order. (default:
      (255, 255, 255))

  Returns:
    An image with target text overlayed on.
  """
  if image is None or not text:
    return image

  cv2.putText(img=image,
              text=text,
              org=position,
              fontFace=font,
              fontScale=font_size,
              color=color,
              thickness=line_width,
              lineType=line_type,
              bottomLeftOrigin=False)

  return image 
开发者ID:genforce,项目名称:higan,代码行数:43,代码来源:visualizer.py

示例10: draw_shape_lines_range

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def draw_shape_lines_range(np_shape, image, range_points, is_closed=False):
    """Draws the shape using lines to connect the different points"""

    np_shape_display = np_shape[range_points]
    points = np.array(np_shape_display, dtype=np.int32)
    cv2.polylines(image, [points], is_closed, (255, 255, 0), thickness=1, lineType=cv2.LINE_8) 
开发者ID:PacktPublishing,项目名称:Mastering-OpenCV-4-with-Python,代码行数:8,代码来源:landmarks_detection_dlib.py

示例11: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def __init__(self, limbs_index, colors=[], radius=5, thickness=2, line_type=cv2.LINE_8, shift=0, font_face=cv2.FONT_HERSHEY_SIMPLEX, font_scale=0.5, z=1):
        self.limbs_index = limbs_index
        self.colors = [tuple(map(lambda c: c * 255, matplotlib.colors.colorConverter.to_rgb(c)[::-1])) for c in colors]
        self._colors = [tuple(map(lambda c: c * 255, matplotlib.colors.colorConverter.to_rgb(prop['color'])[::-1])) for prop in plt.rcParams['axes.prop_cycle']]
        self.radius = radius
        self.thickness = thickness
        self.line_type = line_type
        self.shift = shift
        self.font_face = font_face
        self.font_scale = font_scale
        self.z = z 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:13,代码来源:visualize.py

示例12: cv2_draw_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import LINE_8 [as 别名]
def cv2_draw_text(img, locs, labels, colors, thickness, line_type=cv2.LINE_8):
    locs = locs.astype(np.int32)
    font_line_type = cv2.LINE_8
    font = cv2.FONT_ITALIC
    font = cv2.FONT_HERSHEY_DUPLEX
    font = cv2.FONT_HERSHEY_PLAIN
    font = cv2.FONT_HERSHEY_SIMPLEX
    for loc, label, color in zip(locs, labels, colors):
        color = list(int(c) for c in color)
        cv2.putText(
            img, label, tuple(loc), font, 0.7, color, thickness, font_line_type, False
        )
    return img 
开发者ID:poodarchu,项目名称:Det3D,代码行数:15,代码来源:simplevis.py


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