當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.CC_STAT_WIDTH屬性代碼示例

本文整理匯總了Python中cv2.CC_STAT_WIDTH屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CC_STAT_WIDTH屬性的具體用法?Python cv2.CC_STAT_WIDTH怎麽用?Python cv2.CC_STAT_WIDTH使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.CC_STAT_WIDTH屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _convert_connection_components

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CC_STAT_WIDTH [as 別名]
def _convert_connection_components(retval, labels, stats, centroids, original_mask):
    assert np.amax(labels) == retval - 1
    connected_components = [None] * retval
    for i in range(retval):
        mask = np.array(labels == i, dtype=np.uint8)
        stat_for_label = stats[i]
        stat_left = stat_for_label[cv2.CC_STAT_LEFT]
        stat_top = stat_for_label[cv2.CC_STAT_TOP]
        stat_width = stat_for_label[cv2.CC_STAT_WIDTH]
        stat_height = stat_for_label[cv2.CC_STAT_HEIGHT]
        rect = Rect(stat_left, stat_top, stat_width, stat_height)
        centr = centroids[i]
        area = _get_area_rect(rect)
        num = int(np.sum(original_mask[mask == 1]))
        if area > labels.shape[0] * labels.shape[1] / 16:
            log.debug("_convert_connection_components: i = {}".format(i))
            log.debug("_convert_connection_components: rect = {}".format(rect))
            log.debug("_convert_connection_components: centr = {}".format(centr))
            log.debug("_convert_connection_components: area = {}".format(area))
            log.debug("_convert_connection_components: num = {}".format(num))

        component = ConnectedComponent(label_id=i, mask=mask, centroid=centr, rect=rect,
                                       area=area, num=num)
        connected_components[i] = component

    return connected_components 
開發者ID:opencv,項目名稱:open_model_zoo,代碼行數:28,代碼來源:detect_by_simple_dense_optical_flow.py

示例2: getDetBoxes_core

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CC_STAT_WIDTH [as 別名]
def getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text):
    # prepare data
    linkmap = linkmap.copy()
    textmap = textmap.copy()
    img_h, img_w = textmap.shape

    """ labeling method """
    ret, text_score = cv2.threshold(textmap, low_text, 1, 0)
    ret, link_score = cv2.threshold(linkmap, link_threshold, 1, 0)

    text_score_comb = np.clip(text_score + link_score, 0, 1)
    nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4)

    det = []
    mapper = []
    for k in range(1,nLabels):
        # size filtering
        size = stats[k, cv2.CC_STAT_AREA]
        if size < 10: continue

        # thresholding
        if np.max(textmap[labels==k]) < text_threshold: continue

        # make segmentation map
        segmap = np.zeros(textmap.shape, dtype=np.uint8)
        segmap[labels==k] = 255
        segmap[np.logical_and(link_score==1, text_score==0)] = 0   # remove link area
        x, y = stats[k, cv2.CC_STAT_LEFT], stats[k, cv2.CC_STAT_TOP]
        w, h = stats[k, cv2.CC_STAT_WIDTH], stats[k, cv2.CC_STAT_HEIGHT]
        niter = int(math.sqrt(size * min(w, h) / (w * h)) * 2)
        sx, ex, sy, ey = x - niter, x + w + niter + 1, y - niter, y + h + niter + 1
        # boundary check
        if sx < 0 : sx = 0
        if sy < 0 : sy = 0
        if ex >= img_w: ex = img_w
        if ey >= img_h: ey = img_h
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(1 + niter, 1 + niter))
        segmap[sy:ey, sx:ex] = cv2.dilate(segmap[sy:ey, sx:ex], kernel)

        # make box
        np_contours = np.roll(np.array(np.where(segmap!=0)),1,axis=0).transpose().reshape(-1,2)
        rectangle = cv2.minAreaRect(np_contours)
        box = cv2.boxPoints(rectangle)

        # align diamond-shape
        w, h = np.linalg.norm(box[0] - box[1]), np.linalg.norm(box[1] - box[2])
        box_ratio = max(w, h) / (min(w, h) + 1e-5)
        if abs(1 - box_ratio) <= 0.1:
            l, r = min(np_contours[:,0]), max(np_contours[:,0])
            t, b = min(np_contours[:,1]), max(np_contours[:,1])
            box = np.array([[l, t], [r, t], [r, b], [l, b]], dtype=np.float32)

        # make clock-wise order
        startidx = box.sum(axis=1).argmin()
        box = np.roll(box, 4-startidx, 0)
        box = np.array(box)

        det.append(box)
        mapper.append(k)

    return det, labels, mapper 
開發者ID:clovaai,項目名稱:CRAFT-pytorch,代碼行數:63,代碼來源:craft_utils.py


注:本文中的cv2.CC_STAT_WIDTH屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。