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


Python cv2.matchShapes方法代碼示例

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


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

示例1: findEllipses

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import matchShapes [as 別名]
def findEllipses(edges):
    contours, _ = cv2.findContours(edges.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    ellipseMask = np.zeros(edges.shape, dtype=np.uint8)
    contourMask = np.zeros(edges.shape, dtype=np.uint8)

    pi_4 = np.pi * 4

    for i, contour in enumerate(contours):
        if len(contour) < 5:
            continue

        area = cv2.contourArea(contour)
        if area <= 100:  # skip ellipses smaller then 10x10
            continue

        arclen = cv2.arcLength(contour, True)
        circularity = (pi_4 * area) / (arclen * arclen)
        ellipse = cv2.fitEllipse(contour)
        poly = cv2.ellipse2Poly((int(ellipse[0][0]), int(ellipse[0][1])), (int(ellipse[1][0] / 2), int(ellipse[1][1] / 2)), int(ellipse[2]), 0, 360, 5)

        # if contour is circular enough
        if circularity > 0.6:
            cv2.fillPoly(ellipseMask, [poly], 255)
            continue

        # if contour has enough similarity to an ellipse
        similarity = cv2.matchShapes(poly.reshape((poly.shape[0], 1, poly.shape[1])), contour, cv2.cv.CV_CONTOURS_MATCH_I2, 0)
        if similarity <= 0.2:
            cv2.fillPoly(contourMask, [poly], 255)

    return ellipseMask, contourMask 
開發者ID:AVGInnovationLabs,項目名稱:DoNotSnap,代碼行數:33,代碼來源:RegionOfInterest.py

示例2: matchMaxAreaWithShape

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import matchShapes [as 別名]
def matchMaxAreaWithShape(self, mask, shape):
        """it returns a value which identify the similarity between
            the largest area contour and a shape.
 
        The lower the result, the better match it is. It is calculated 
        based on the hu-moment values. For example if we have three shapes:
        A=star, B=rotated dilatated star, C=square
        Matching Image A with itself = 0.0
        Matching Image A with Image B = 0.001946
        Matching Image A with Image C = 0.326911
        @param mask the binary image to use in the function
        @param shape the contour to compare
        """        
        cnt = self.returnMaxAreaContour(mask)
        return cv2.matchShapes(cnt, shape, 1, 0.0) 
開發者ID:mpatacchiola,項目名稱:deepgaze,代碼行數:17,代碼來源:mask_analysis.py


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