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