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


Python cv2.convexityDefects方法代碼示例

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


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

示例1: FindHullDefects

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def FindHullDefects(self, segment):
        _,contours,hierarchy = cv2.findContours(segment, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

        # find largest area contour
        max_area = -1
        for i in range(len(contours)):
            area = cv2.contourArea(contours[i])
            if area>max_area:
                cnt = contours[i]
                max_area = area

        cnt = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
        hull = cv2.convexHull(cnt, returnPoints=False)
        defects = cv2.convexityDefects(cnt, hull)

        return [cnt,defects] 
開發者ID:PacktPublishing,項目名稱:OpenCV-Computer-Vision-Projects-with-Python,代碼行數:18,代碼來源:chapter2.py

示例2: manage_image_opr

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def manage_image_opr(frame, hand_hist):
    hist_mask_image = hist_masking(frame, hand_hist)

    hist_mask_image = cv2.erode(hist_mask_image, None, iterations=2)
    hist_mask_image = cv2.dilate(hist_mask_image, None, iterations=2)

    contour_list = contours(hist_mask_image)
    max_cont = max(contour_list, key=cv2.contourArea)

    cnt_centroid = centroid(max_cont)
    cv2.circle(frame, cnt_centroid, 5, [255, 0, 255], -1)

    if max_cont is not None:
        hull = cv2.convexHull(max_cont, returnPoints=False)
        defects = cv2.convexityDefects(max_cont, hull)
        far_point = farthest_point(defects, max_cont, cnt_centroid)
        print("Centroid : " + str(cnt_centroid) + ", farthest Point : " + str(far_point))
        cv2.circle(frame, far_point, 5, [0, 0, 255], -1)
        if len(traverse_point) < 20:
            traverse_point.append(far_point)
        else:
            traverse_point.pop(0)
            traverse_point.append(far_point)

        draw_circles(frame, traverse_point) 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:27,代碼來源:FingerDetection.py

示例3: calculateFingers

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def calculateFingers(res,drawing):  # -> finished bool, cnt: finger count
    #  convexity defect
    hull = cv2.convexHull(res, returnPoints=False)
    if len(hull) > 3:
        defects = cv2.convexityDefects(res, hull)
        if type(defects) != type(None):  # avoid crashing.   (BUG not found)

            cnt = 0
            for i in range(defects.shape[0]):  # calculate the angle
                s, e, f, d = defects[i][0]
                start = tuple(res[s][0])
                end = tuple(res[e][0])
                far = tuple(res[f][0])
                a = math.sqrt((end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2)
                b = math.sqrt((far[0] - start[0]) ** 2 + (far[1] - start[1]) ** 2)
                c = math.sqrt((end[0] - far[0]) ** 2 + (end[1] - far[1]) ** 2)
                angle = math.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c))  # cosine theorem
                if angle <= math.pi / 2:  # angle less than 90 degree, treat as fingers
                    cnt += 1
                    cv2.circle(drawing, far, 8, [211, 84, 0], -1)
            return True, cnt
    return False, 0


# Camera 
開發者ID:lzane,項目名稱:Fingers-Detection-using-OpenCV-and-Python,代碼行數:27,代碼來源:new.py

示例4: isArrow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def isArrow(heptagon):
    hull = cv2.convexHull(heptagon, returnPoints = False)

    if len(hull) > 2:
        defects = cv2.convexityDefects(heptagon, hull)
        if defects is None or len(defects) != 2: 
            return False
      
        farpoints = [d[0][2] for d in defects]    
        if not np.abs(farpoints[0] - farpoints[1]) in [3, 4]:
            return False

        for defect in defects:
            s, e, f, d = defect[0]
            #    print defects
            #    s, e, f, d = defect[0]
            ps = heptagon[s, 0]
            pe = heptagon[e, 0]
            pd = heptagon[f, 0]
            if angle(ps, pd, pe) < 120:
                return True    

        return False 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:25,代碼來源:find_arrows.py

示例5: isArrow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def isArrow(heptagon):
    hull = cv2.convexHull(heptagon, returnPoints=False)

    if len(hull) > 2:
        defects = cv2.convexityDefects(heptagon, hull)
        if defects is None or len(defects) != 2:
            return False

        farpoints = [d[0][2] for d in defects]
        if not np.abs(farpoints[0] - farpoints[1]) in [3, 4]:
            return False

        for defect in defects:
            s, e, f, d = defect[0]
            #    print defects
            #    s, e, f, d = defect[0]
            ps = heptagon[s, 0]
            pe = heptagon[e, 0]
            pd = heptagon[f, 0]
            if angle(ps, pd, pe) < 120:
                return True

        return False 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:25,代碼來源:whale176-rectangle.py

示例6: tip

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def tip(arrow):
    hull = cv2.convexHull(arrow, returnPoints = False)
    defects = cv2.convexityDefects(arrow, hull)
    farpoints = [d[0][2] for d in defects]
    if np.abs(farpoints[0] - farpoints[1]) == 4:
        return arrow[sum(farpoints) / 2, 0]
    else:
        return arrow[0, 0] 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:10,代碼來源:find_arrows.py

示例7: tip

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import convexityDefects [as 別名]
def tip(arrow):
    hull = cv2.convexHull(arrow, returnPoints=False)
    defects = cv2.convexityDefects(arrow, hull)
    farpoints = [d[0][2] for d in defects]
    if np.abs(farpoints[0] - farpoints[1]) == 4:
        return arrow[sum(farpoints) / 2, 0]
    else:
        return arrow[0, 0] 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:10,代碼來源:whale176-rectangle.py


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