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


Python cv2.HuMoments方法代碼示例

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


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

示例1: calculate_contour_features

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import HuMoments [as 別名]
def calculate_contour_features(contour):
    """Calculates interesting properties (features) of a contour.

    We use these features to match shapes (contours). In this script,
    we are interested in finding shapes in our input image that look like
    a corner. We do that by calculating the features for many contours
    in the input image and comparing these to the features of the corner
    contour. By design, we know exactly what the features of the real corner
    contour look like - check out the calculate_corner_features function.

    It is crucial for these features to be invariant both to scale and rotation.
    In other words, we know that a corner is a corner regardless of its size
    or rotation. In the past, this script implemented its own features, but
    OpenCV offers much more robust scale and rotational invariant features
    out of the box - the Hu moments.
    """
    moments = cv2.moments(contour)
    return cv2.HuMoments(moments) 
開發者ID:rbaron,項目名稱:omr,代碼行數:20,代碼來源:omr.py

示例2: HuMoments

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import HuMoments [as 別名]
def HuMoments(m: List[int]) -> List[int]:
    """
    Calculates seven Hu invariants
    """
    # If image is not a single channel image convert it
    if len(m.shape) != 2:
        m = cv2.cvtColor(m, cv2.COLOR_BGR2GRAY)
    m = cv2.moments(m)
    hu_moments = cv2.HuMoments(m).flatten()

    return hu_moments 
開發者ID:intel,項目名稱:dffml,代碼行數:13,代碼來源:operations.py

示例3: get_hu_moments

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import HuMoments [as 別名]
def get_hu_moments(arr):
    arr = invert_binary_image(arr)
    if arr.shape != (32, 32):
        arr.shape = (32, 32)
    m = moments(arr.astype(np.float64), binaryImage=True)
    hu = HuMoments(m)
    return hu.flatten() 
開發者ID:zmr,項目名稱:namsel,代碼行數:9,代碼來源:feature_extraction.py

示例4: fd_hu_moments

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import HuMoments [as 別名]
def fd_hu_moments(image):
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    feature = cv2.HuMoments(cv2.moments(image)).flatten()
    return feature

# feature-descriptor-2: Haralick Texture 
開發者ID:Gogul09,項目名稱:image-classification-python,代碼行數:8,代碼來源:global.py

示例5: _getBlobFeatures

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import HuMoments [as 別名]
def _getBlobFeatures(blob_cnt, blob_mask, roi_image, roi_corner):
    if blob_cnt.size > 0:
        area = float(cv2.contourArea(blob_cnt))
        # find use the best rotated bounding box, the fitEllipse function produces bad results quite often
        # this method is better to obtain an estimate of the worm length than
        # eccentricity
        (CMx, CMy), (L, W), angle = cv2.minAreaRect(blob_cnt)
        #adjust CM from the ROI reference frame to the image reference
        CMx += roi_corner[0]
        CMy += roi_corner[1]

        if L == 0 or W == 0:
            return None #something went wrong abort

        if W > L:
            L, W = W, L  # switch if width is larger than length
        quirkiness = np.sqrt(1 - W**2 / L**2)

        hull = cv2.convexHull(blob_cnt)  # for the solidity
        solidity = area / cv2.contourArea(hull)
        perimeter = float(cv2.arcLength(blob_cnt, True))
        compactness = 4 * np.pi * area / (perimeter**2)

        # calculate the mean intensity of the worm
        intensity_mean, intensity_std = cv2.meanStdDev(roi_image, mask=blob_mask)
        intensity_mean = intensity_mean[0,0]
        intensity_std = intensity_std[0,0]

        # calculate hu moments, they are scale and rotation invariant
        hu_moments = cv2.HuMoments(cv2.moments(blob_cnt))


        # save everything into the the proper output format
        mask_feats = (CMx,
                    CMy,
                    area,
                    perimeter,
                    L,
                    W,
                    quirkiness,
                    compactness,
                    angle,
                    solidity,
                    intensity_mean,
                    intensity_std,
                    *hu_moments.flatten())
    else:
        return tuple([np.nan]*19)

    return mask_feats 
開發者ID:ver228,項目名稱:tierpsy-tracker,代碼行數:52,代碼來源:getBlobsFeats.py


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