当前位置: 首页>>代码示例>>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;未经允许,请勿转载。