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


Python cv2.boxPoints方法代码示例

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


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

示例1: mask2poly_single

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def mask2poly_single(binary_mask):
    """

    :param binary_mask:
    :return:
    """
    try:
        contours, hierarchy = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
        # contour_lens = np.array(list(map(len, contours)))
        # max_id = contour_lens.argmax()
        # max_contour = contours[max_id]
        max_contour = max(contours, key=len)
        rect = cv2.minAreaRect(max_contour)
        poly = cv2.boxPoints(rect)
        # poly = TuplePoly2Poly(poly)
    except:
        import pdb
        pdb.set_trace()
    return poly 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:21,代码来源:transforms_rbbox.py

示例2: getEllipseRotation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def getEllipseRotation(image, cnt):
    try:
        # Gets rotated bounding ellipse of contour
        ellipse = cv2.fitEllipse(cnt)
        centerE = ellipse[0]
        # Gets rotation of ellipse; same as rotation of contour
        rotation = ellipse[2]
        # Gets width and height of rotated ellipse
        widthE = ellipse[1][0]
        heightE = ellipse[1][1]
        # Maps rotation to (-90 to 90). Makes it easier to tell direction of slant
        rotation = translateRotation(rotation, widthE, heightE)

        cv2.ellipse(image, ellipse, (23, 184, 80), 3)
        return rotation
    except:
        # Gets rotated bounding rectangle of contour
        rect = cv2.minAreaRect(cnt)
        # Creates box around that rectangle
        box = cv2.boxPoints(rect)
        # Not exactly sure
        box = np.int0(box)
        # Gets center of rotated rectangle
        center = rect[0]
        # Gets rotation of rectangle; same as rotation of contour
        rotation = rect[2]
        # Gets width and height of rotated rectangle
        width = rect[1][0]
        height = rect[1][1]
        # Maps rotation to (-90 to 90). Makes it easier to tell direction of slant
        rotation = translateRotation(rotation, width, height)
        return rotation

#################### FRC VISION PI Image Specific ############# 
开发者ID:team3997,项目名称:ChickenVision,代码行数:36,代码来源:ChickenVision.py

示例3: forward_convert

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def forward_convert(coordinate, with_label=True):
    """
    :param coordinate: format [x_c, y_c, w, h, theta]
    :return: format [x1, y1, x2, y2, x3, y3, x4, y4]
    """

    boxes = []
    if with_label:
        for rect in coordinate:
            box = cv2.boxPoints(((rect[0], rect[1]), (rect[2], rect[3]), rect[4]))
            box = np.reshape(box, [-1, ])
            boxes.append([box[0], box[1], box[2], box[3], box[4], box[5], box[6], box[7], rect[5]])
    else:
        for rect in coordinate:
            box = cv2.boxPoints(((rect[0], rect[1]), (rect[2], rect[3]), rect[4]))
            box = np.reshape(box, [-1, ])
            boxes.append([box[0], box[1], box[2], box[3], box[4], box[5], box[6], box[7]])

    return np.array(boxes, dtype=np.float32) 
开发者ID:Thinklab-SJTU,项目名称:R3Det_Tensorflow,代码行数:21,代码来源:coordinate_convert.py

示例4: forward_convert

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def forward_convert(coordinate, with_label=True):
    """
    :param coordinate: format [x_c, y_c, w, h, theta]
    :return: format [x1, y1, x2, y2, x3, y3, x4, y4]
    """
    boxes = []
    if with_label:
        for rect in coordinate:
            box = cv2.boxPoints(((rect[0], rect[1]), (rect[2], rect[3]), rect[4]))
            box = np.reshape(box, [-1, ])
            boxes.append([box[0], box[1], box[2], box[3], box[4], box[5], box[6], box[7], rect[5]])
    else:
        for rect in coordinate:
            box = cv2.boxPoints(((rect[0], rect[1]), (rect[2], rect[3]), rect[4]))
            box = np.reshape(box, [-1, ])
            boxes.append([box[0], box[1], box[2], box[3], box[4], box[5], box[6], box[7]])

    return np.array(boxes, dtype=np.float32) 
开发者ID:DetectionTeamUCAS,项目名称:R2CNN-Plus-Plus_Tensorflow,代码行数:20,代码来源:coordinate_convert.py

示例5: calcSafeRect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def calcSafeRect(self, roi, src):
        '''
            return [x, y, w, h]
        '''
        box = cv2.boxPoints(roi)
        x, y, w, h = cv2.boundingRect(box)

        src_h, src_w, _ = src.shape

        tl_x = x if x > 0 else 0
        tl_y = y if y > 0 else 0
        br_x = x + w - 1 if x + w - 1 < src_w else src_w - 1
        br_y = y + h - 1 if y + h - 1 < src_h else src_h - 1

        roi_w = br_x - tl_x
        roi_h = br_y - tl_y
        if roi_w <= 0 or roi_h <= 0:
            return [tl_x, tl_y, roi_w, roi_h], False

        return [tl_x, tl_y, roi_w, roi_h], True 
开发者ID:SunskyF,项目名称:EasyPR-python,代码行数:22,代码来源:plate_locate.py

示例6: _mask_post_processing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def _mask_post_processing(mask, center_pos, size, track_mask_threshold):
    target_mask = (mask > track_mask_threshold)
    target_mask = target_mask.astype(np.uint8)
    if cv2.__version__[-5] == '4':
        contours, _ = cv2.findContours(target_mask,
                                       cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_NONE)
    else:
        _, contours, _ = cv2.findContours(
                target_mask,
                cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    cnt_area = [cv2.contourArea(cnt) for cnt in contours]
    if len(contours) != 0 and np.max(cnt_area) > 100:
        contour = contours[np.argmax(cnt_area)] 
        polygon = contour.reshape(-1, 2)
        prbox = cv2.boxPoints(cv2.minAreaRect(polygon))
        rbox_in_img = prbox
    else:  # empty mask
        location = cxy_wh_2_rect(center_pos, size)
        rbox_in_img = np.array([[location[0], location[1]],
                    [location[0] + location[2], location[1]],
                    [location[0] + location[2], location[1] + location[3]],
                    [location[0], location[1] + location[3]]])
    return rbox_in_img 
开发者ID:chainer,项目名称:models,代码行数:26,代码来源:siam_mask_tracker.py

示例7: combine_line

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def combine_line(line):
    """Combine a set of boxes in a line into a single bounding
    box.

    Args:
        line: A list of (box, character) entries

    Returns:
        A (box, text) tuple
    """
    text = ''.join([character if character is not None else '' for _, character in line])
    box = np.concatenate([coords[:2] for coords, _ in line] +
                         [np.array([coords[3], coords[2]])
                          for coords, _ in reversed(line)]).astype('float32')
    first_point = box[0]
    rectangle = cv2.minAreaRect(box)
    box = cv2.boxPoints(rectangle)

    # Put the points in clockwise order
    box = np.array(np.roll(box, -np.linalg.norm(box - first_point, axis=1).argmin(), 0))
    return box, text 
开发者ID:faustomorales,项目名称:keras-ocr,代码行数:23,代码来源:tools.py

示例8: _mask_post_processing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def _mask_post_processing(self, mask):
        target_mask = (mask > cfg.TRACK.MASK_THERSHOLD)
        target_mask = target_mask.astype(np.uint8)
        if cv2.__version__[-5] == '4':
            contours, _ = cv2.findContours(target_mask,
                                           cv2.RETR_EXTERNAL,
                                           cv2.CHAIN_APPROX_NONE)
        else:
            _, contours, _ = cv2.findContours(target_mask,
                                              cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_NONE)
        cnt_area = [cv2.contourArea(cnt) for cnt in contours]
        if len(contours) != 0 and np.max(cnt_area) > 100:
            contour = contours[np.argmax(cnt_area)]
            polygon = contour.reshape(-1, 2)
            prbox = cv2.boxPoints(cv2.minAreaRect(polygon))
            rbox_in_img = prbox
        else:  # empty mask
            location = cxy_wh_2_rect(self.center_pos, self.size)
            rbox_in_img = np.array([[location[0], location[1]],
                                    [location[0] + location[2], location[1]],
                                    [location[0] + location[2], location[1] + location[3]],
                                    [location[0], location[1] + location[3]]])
        return rbox_in_img 
开发者ID:STVIR,项目名称:pysot,代码行数:26,代码来源:siammask_tracker.py

示例9: get_mini_boxes

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def get_mini_boxes(self, contour):
        bounding_box = cv2.minAreaRect(contour)
        points = sorted(list(cv2.boxPoints(bounding_box)), key=lambda x: x[0])

        index_1, index_2, index_3, index_4 = 0, 1, 2, 3
        if points[1][1] > points[0][1]:
            index_1 = 0
            index_4 = 1
        else:
            index_1 = 1
            index_4 = 0
        if points[3][1] > points[2][1]:
            index_2 = 2
            index_3 = 3
        else:
            index_2 = 3
            index_3 = 2

        box = [points[index_1], points[index_2], points[index_3], points[index_4]]
        return box, min(bounding_box[1]) 
开发者ID:WenmuZhou,项目名称:DBNet.pytorch,代码行数:22,代码来源:seg_detector_representer.py

示例10: compute_cell_hulls

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def compute_cell_hulls(self):
        """
        Run find_table_cell_polygons() and compute a rectangle enclosing the cell (for each cell).
        For most (4-point) cells, this is equivalent to the original path, however this removes
        small irregularities and extra points from larger, 5+-point cells (mostly merged cells)
        """
        self.compute_cell_polygons()
        # cv2 convexHull / minAreaRect only work with integer coordinates.
        self.cell_hulls = [
            cv2.boxPoints(cv2.minAreaRect(np.rint(self.cluster_coords[path]).astype(int)))
            for path in self.cell_polygons]
        # Compute centers of cell hulls
        self.cell_centers = np.zeros((len(self.cell_hulls), 2))
        for i in range(len(self.cell_hulls)):
            hull_points = self.cell_hulls[i]
            self.cell_centers[i] = cv_algorithms.meanCenter(hull_points) 
开发者ID:ulikoehler,项目名称:OTR,代码行数:18,代码来源:TableRecognition.py

示例11: masks_to_rects

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def masks_to_rects(masks):
        rects = []
        for mask in masks:
            decoded_mask = mask
            contours = cv2.findContours(decoded_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2]

            areas = []
            boxes = []
            for contour in contours:
                area = cv2.contourArea(contour)
                areas.append(area)

                rect = cv2.minAreaRect(contour)
                box = cv2.boxPoints(rect)
                box = np.int0(box)
                boxes.append(box)

            if areas:
                i = np.argmax(areas)
                rects.append(boxes[i])

        return rects 
开发者ID:opencv,项目名称:open_model_zoo,代码行数:24,代码来源:mask_rcnn_with_text.py

示例12: remove_border

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def remove_border(contour, ary):
    """Remove everything outside a border contour."""
    # Use a rotated rectangle (should be a good approximation of a border).
    # If it's far from a right angle, it's probably two sides of a border and
    # we should use the bounding box instead.
    c_im = np.zeros(ary.shape)
    r = cv2.minAreaRect(contour)
    degs = r[2]
    if angle_from_right(degs) <= 10.0:
        box = cv2.boxPoints(r)
        box = np.int0(box)
        cv2.drawContours(c_im, [box], 0, 255, -1)
        cv2.drawContours(c_im, [box], 0, 0, 4)
    else:
        x1, y1, x2, y2 = cv2.boundingRect(contour)
        cv2.rectangle(c_im, (x1, y1), (x2, y2), 255, -1)
        cv2.rectangle(c_im, (x1, y1), (x2, y2), 0, 4)

    return np.minimum(c_im, ary) 
开发者ID:maddevsio,项目名称:idmatch,代码行数:21,代码来源:crop.py

示例13: drawBrushesOnImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def drawBrushesOnImage(brushes, color, im, pc, image_scale, fill=True):
    for brush in brushes:
        center = pc.tgcToCV2(brush["position"]["x"], brush["position"]["z"], image_scale)
        center = (center[1], center[0]) # In point coordinates, not pixel
        width = brush["scale"]["x"] / image_scale
        height = brush["scale"]["z"] / image_scale
        rotation = - brush["rotation"]["y"] # Inverted degrees, cv2 bounding_box uses degrees

        thickness = 4
        if fill:
            thickness = -1 # Negative thickness is a filled ellipse

        brush_type_name = tgc_definitions.brushes.get(int(brush["type"]), "unknown")

        if 'square' in brush_type_name:
            box_points = cv2.boxPoints((center, (2.0*width, 2.0*height), rotation)) # Squares seem to be larger than circles
            box_points = np.int32([box_points]) # Bug with fillPoly, needs explict cast to 32bit

            if fill:
                cv2.fillPoly(im, box_points, color, lineType=cv2.LINE_AA)
            else:
                cv2.polylines(im, box_points, True, color, thickness, lineType=cv2.LINE_AA)
        else: # Draw as ellipse for now
            '''center – The rectangle mass center.
            size – Width and height of the rectangle.
            angle – The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.'''
            bounding_box =  (center, (1.414*width, 1.414*height), rotation) # Circles seem to scale according to radius
            cv2.ellipse(im, bounding_box, color, thickness=thickness, lineType=cv2.LINE_AA) 
开发者ID:chadrockey,项目名称:TGC-Designer-Tools,代码行数:30,代码来源:tgc_visualizer.py

示例14: mask2poly_single

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def mask2poly_single(binary_mask):
    """

    :param binary_mask:
    :return:
    """
    # try:
    contours, hierarchy = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    max_contour = max(contours, key=len)
    rect = cv2.minAreaRect(max_contour)
    poly = cv2.boxPoints(rect)
    poly = TuplePoly2Poly(poly)

    return poly 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:16,代码来源:rotate_aug.py

示例15: seg2poly_old

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxPoints [as 别名]
def seg2poly_old(rle):
    # TODO: debug for this function
    """
    This function transform a single encoded RLE to a single poly
    :param seg: RlE
    :return: poly
    """
    # try:
    #     binary_mask = mask_utils.decode(rle)
    #     contours, hierarchy = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL)
    #     contour_lens = np.array(list(map(len, contours)))
    #     max_id = contour_lens.argmax()
    #     max_contour = contours[max_id]
    #     rect = cv2.minAreaRect(max_contour)
    #     poly = cv2.boxPoints(rect)
    #     return poly
    # except:
    #     return -1
    try:
        binary_mask = mask_utils.decode(rle)
        contours, hierarchy = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        # len is not appropriate
        # contour_lens = np.array(list(map(len, contours)))
        # max_id = contour_lens.argmax()
        contour_areas = np.array(list(map(cv2.contourArea, contours)))
        max_id = contour_areas.argmax()
        max_contour = contours[max_id]
        rect = cv2.minAreaRect(max_contour)
        poly = cv2.boxPoints(rect)
        poly = TuplePoly2Poly(poly)
        return poly
    except:
        return [] 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:35,代码来源:dota_utils.py


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