本文整理匯總了Python中cv2.Subdiv2D方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.Subdiv2D方法的具體用法?Python cv2.Subdiv2D怎麽用?Python cv2.Subdiv2D使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.Subdiv2D方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: measure_triangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import Subdiv2D [as 別名]
def measure_triangle(image, points):
rect = (0, 0, image.shape[1], image.shape[0])
sub_div = cv2.Subdiv2D(rect)
for p in points:
sub_div.insert(p)
triangle_list = sub_div.getTriangleList()
triangle = []
pt = []
for t in triangle_list:
pt.append((t[0], t[1]))
pt.append((t[2], t[3]))
pt.append((t[4], t[5]))
pt1 = (t[0], t[1])
pt2 = (t[2], t[3])
pt3 = (t[4], t[5])
if rect_contains(rect, pt1) and rect_contains(rect, pt2) and rect_contains(rect, pt3):
ind = []
for j in range(0, 3):
for k in range(0, len(points)):
if abs(pt[j][0] - points[k][0]) < 1.0 and abs(pt[j][1] - points[k][1]) < 1.0:
ind.append(k)
if len(ind) == 3:
triangle.append((ind[0], ind[1], ind[2]))
pt = []
return triangle
示例2: calculateDelaunayTriangles
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import Subdiv2D [as 別名]
def calculateDelaunayTriangles(rect, points):
def rectContains(point, rect):
if point[0] < rect[0] or point[0] > rect[2]:
return False
elif point[1] < rect[1] or point[1] > rect[3]:
return False
return True
subDiv = cv2.Subdiv2D(rect)
for point in points:
subDiv.insert((point[0], point[1]))
triangleList = subDiv.getTriangleList()
return_mat = []
for triangle in triangleList:
pt = []
pt.append((triangle[0], triangle[1]))
pt.append((triangle[2], triangle[3]))
pt.append((triangle[4], triangle[5]))
if rectContains(pt[0], rect) and rectContains(pt[1], rect) and rectContains(pt[2], rect):
ind = []
for i in range(3):
for j in range(len(points)):
if np.abs(pt[i][0] - points[j][0]) < 1.0 and np.abs(pt[i][1] - points[j][1]) < 1.0:
ind.append(j)
if len(ind) == 3:
return_mat.append(ind)
return return_mat
示例3: calculateDelaunayTriangles
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import Subdiv2D [as 別名]
def calculateDelaunayTriangles(rect, points):
subdiv = cv2.Subdiv2D(rect);
for p in points:
subdiv.insert((p[0], p[1]));
triangleList = subdiv.getTriangleList();
delaunayTri = []
for t in triangleList:
pt = []
pt.append((t[0], t[1]))
pt.append((t[2], t[3]))
pt.append((t[4], t[5]))
pt1 = (t[0], t[1])
pt2 = (t[2], t[3])
pt3 = (t[4], t[5])
if rectContains(rect, pt1) and rectContains(rect, pt2) and rectContains(rect, pt3):
ind = []
for j in range(0, 3):
for k in range(0, len(points)):
if (abs(pt[j][0] - points[k][0]) < 1.0 and abs(pt[j][1] - points[k][1]) < 1.0):
ind.append(k)
if len(ind) == 3:
delaunayTri.append((ind[0], ind[1], ind[2]))
return delaunayTri
示例4: calculateDelaunayTriangles
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import Subdiv2D [as 別名]
def calculateDelaunayTriangles(rect, points):
# create subdiv
subdiv = cv2.Subdiv2D(rect);
# Insert points into subdiv
for p in points:
subdiv.insert(p)
triangleList = subdiv.getTriangleList();
delaunayTri = []
pt = []
for t in triangleList:
pt.append((t[0], t[1]))
pt.append((t[2], t[3]))
pt.append((t[4], t[5]))
pt1 = (t[0], t[1])
pt2 = (t[2], t[3])
pt3 = (t[4], t[5])
if rectContains(rect, pt1) and rectContains(rect, pt2) and rectContains(rect, pt3):
ind = []
# Get face-points (from 68 face detector) by coordinates
for j in range(0, 3):
for k in range(0, len(points)):
if (abs(pt[j][0] - points[k][0]) < 1.0 and abs(pt[j][1] - points[k][1]) < 1.0):
ind.append(k)
# Three points form a triangle. Triangle array corresponds to the file tri.txt in FaceMorph
if len(ind) == 3:
delaunayTri.append((ind[0], ind[1], ind[2]))
pt = []
return delaunayTri
示例5: makeDelaunay
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import Subdiv2D [as 別名]
def makeDelaunay(theSize1,theSize0,theList):
# Check if a point is inside a rectangle
def rect_contains(rect, point) :
if point[0] < rect[0] :
return False
elif point[1] < rect[1] :
return False
elif point[0] > rect[2] :
return False
elif point[1] > rect[3] :
return False
return True
# Write the delaunay triangles into a file
def draw_delaunay(subdiv,dictionary1) :
list4=[]
triangleList = subdiv.getTriangleList();
r = (0, 0, theSize1,theSize0)
for t in triangleList :
pt1 = (int(t[0]), int(t[1]))
pt2 = (int(t[2]), int(t[3]))
pt3 = (int(t[4]), int(t[5]))
if rect_contains(r, pt1) and rect_contains(r, pt2) and rect_contains(r, pt3) :
list4.append((dictionary1[pt1],dictionary1[pt2],dictionary1[pt3]))
dictionary1={}
return list4
# Make a rectangle.
rect = (0, 0, theSize1,theSize0)
# Create an instance of Subdiv2D.
subdiv = cv2.Subdiv2D(rect);
# Make a points list and a searchable dictionary.
theList=theList.tolist()
points=[(int(x[0]),int(x[1])) for x in theList]
dictionary={x[0]:x[1] for x in list(zip(points,range(76)))}
# Insert points into subdiv
for p in points :
subdiv.insert(p)
# Make a delaunay triangulation list.
list4=draw_delaunay(subdiv,dictionary);
# Return the list.
return list4
# makeDelaunay(1080,1440)