farpoint支持python_Python cv2.convexityDefects方法代碼示例

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

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

示例1: FindHullDefects

​點讚 10

# 需要導入模塊: 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,

示例2: calculateFingers

​點讚 7

# 需要導入模塊: 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,

示例3: manage_image_opr

​點讚 7

# 需要導入模塊: 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,

示例4: isArrow

​點讚 6

# 需要導入模塊: 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,

示例5: isArrow

​點讚 6

# 需要導入模塊: 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,

示例6: tip

​點讚 5

# 需要導入模塊: 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,

示例7: tip

​點讚 5

# 需要導入模塊: 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,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值