本文整理匯總了Python中cv2.fillConvexPoly方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.fillConvexPoly方法的具體用法?Python cv2.fillConvexPoly怎麽用?Python cv2.fillConvexPoly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.fillConvexPoly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: merge_img
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def merge_img(src_img, dst_img, dst_matrix, dst_points, blur_detail_x=None, blur_detail_y=None, mat_multiple=None):
face_mask = np.zeros(src_img.shape, dtype=src_img.dtype)
for group in core.OVERLAY_POINTS:
cv2.fillConvexPoly(face_mask, cv2.convexHull(dst_matrix[group]), (255, 255, 255))
r = cv2.boundingRect(np.float32([dst_points[:core.FACE_END]]))
center = (r[0] + int(r[2] / 2), r[1] + int(r[3] / 2))
if mat_multiple:
mat = cv2.getRotationMatrix2D(center, 0, mat_multiple)
face_mask = cv2.warpAffine(face_mask, mat, (face_mask.shape[1], face_mask.shape[0]))
if blur_detail_x and blur_detail_y:
face_mask = cv2.blur(face_mask, (blur_detail_x, blur_detail_y), center)
return cv2.seamlessClone(np.uint8(dst_img), src_img, face_mask, center, cv2.NORMAL_CLONE)
示例2: render
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def render(img, obj, projection, model, color=False):
"""
Render a loaded obj model into the current video frame
"""
vertices = obj.vertices
scale_matrix = np.eye(3) * 3
h, w = model.shape
for face in obj.faces:
face_vertices = face[0]
points = np.array([vertices[vertex - 1] for vertex in face_vertices])
points = np.dot(points, scale_matrix)
# render model in the middle of the reference surface. To do so,
# model points must be displaced
points = np.array([[p[0] + w / 2, p[1] + h / 2, p[2]] for p in points])
dst = cv2.perspectiveTransform(points.reshape(-1, 1, 3), projection)
imgpts = np.int32(dst)
if color is False:
cv2.fillConvexPoly(img, imgpts, (137, 27, 211))
else:
color = hex_to_rgb(face[-1])
color = color[::-1] # reverse
cv2.fillConvexPoly(img, imgpts, color)
return img
示例3: add_coco_hp
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def add_coco_hp(image, points, color):
for j in range(17):
cv2.circle(image,
(points[j, 0], points[j, 1]), 2, (int(color[0]), int(color[1]), int(color[2])), -1)
stickwidth = 2
cur_canvas = image.copy()
for j, e in enumerate(_kp_connections):
if points[e].min() > 0:
X = [points[e[0], 1], points[e[1], 1]]
Y = [points[e[0], 0], points[e[1], 0]]
mX = np.mean(X)
mY = np.mean(Y)
length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
polygon = cv2.ellipse2Poly((int(mY),int(mX)), (int(length/2), stickwidth), int(angle), 0, 360, 1)
cv2.fillConvexPoly(cur_canvas, polygon, (int(color[0]), int(color[1]), int(color[2])))
image = cv2.addWeighted(image, 0.5, cur_canvas, 0.5, 0)
return image
示例4: add_coco_hp
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def add_coco_hp(self, points, points_prob, img_id='default'):
points = np.array(points, dtype=np.int32).reshape(self.num_joints, 2)
points_prob = np.array(points_prob, dtype=np.float32).reshape(self.num_joints)
for j in range(self.num_joints):
if points_prob[j]>0.:
cv2.circle(self.imgs[img_id],
(points[j, 0], points[j, 1]), 2, (255,255,255), -1)
stickwidth = 2
cur_canvas = self.imgs[img_id].copy()
for j, e in enumerate(self.edges):
if points_prob[e[0]] > 0. and points_prob[e[1]] > 0.:
X = [points[e[0], 1], points[e[1], 1]]
Y = [points[e[0], 0], points[e[1], 0]]
mX = np.mean(X)
mY = np.mean(Y)
length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
polygon = cv2.ellipse2Poly((int(mY),int(mX)), (int(length/2), stickwidth), int(angle), 0, 360, 1)
cv2.fillConvexPoly(cur_canvas, polygon, (255, 255, 255))
self.imgs[img_id] = cv2.addWeighted(self.imgs[img_id], 0.8, cur_canvas, 0.2, 0)
示例5: cal_iou2d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def cal_iou2d(box1, box2, T_VELO_2_CAM=None, R_RECT_0=None):
# Input:
# box1/2: x, y, w, l, r
# Output :
# iou
buf1 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
buf2 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
tmp = center_to_corner_box2d(np.array([box1, box2]), coordinate='lidar', T_VELO_2_CAM=T_VELO_2_CAM, R_RECT_0=R_RECT_0)
box1_corner = batch_lidar_to_bird_view(tmp[0]).astype(np.int32)
box2_corner = batch_lidar_to_bird_view(tmp[1]).astype(np.int32)
buf1 = cv2.fillConvexPoly(buf1, box1_corner, color=(1,1,1))[..., 0]
buf2 = cv2.fillConvexPoly(buf2, box2_corner, color=(1,1,1))[..., 0]
indiv = np.sum(np.absolute(buf1-buf2))
share = np.sum((buf1 + buf2) == 2)
if indiv == 0:
return 0.0 # when target is out of bound
return share / (indiv + share)
示例6: cal_iou3d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def cal_iou3d(box1, box2, T_VELO_2_CAM=None, R_RECT_0=None):
# Input:
# box1/2: x, y, z, h, w, l, r
# Output:
# iou
buf1 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
buf2 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
tmp = center_to_corner_box2d(np.array([box1[[0,1,4,5,6]], box2[[0,1,4,5,6]]]), coordinate='lidar', T_VELO_2_CAM=T_VELO_2_CAM, R_RECT_0=R_RECT_0)
box1_corner = batch_lidar_to_bird_view(tmp[0]).astype(np.int32)
box2_corner = batch_lidar_to_bird_view(tmp[1]).astype(np.int32)
buf1 = cv2.fillConvexPoly(buf1, box1_corner, color=(1,1,1))[..., 0]
buf2 = cv2.fillConvexPoly(buf2, box2_corner, color=(1,1,1))[..., 0]
share = np.sum((buf1 + buf2) == 2)
area1 = np.sum(buf1)
area2 = np.sum(buf2)
z1, h1, z2, h2 = box1[2], box1[3], box2[2], box2[3]
z_intersect = cal_z_intersect(z1, h1, z2, h2)
return share * z_intersect / (area1 * h1 + area2 * h2 - share * z_intersect)
示例7: draw_limbs_2d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def draw_limbs_2d(img, joints_2d, limb_parents, rect):
# draw skeleton
for limb_num in range(len(limb_parents)):
x1 = joints_2d[limb_num, 0]
y1 = joints_2d[limb_num, 1]
x2 = joints_2d[limb_parents[limb_num], 0]
y2 = joints_2d[limb_parents[limb_num], 1]
length = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
deg = math.degrees(math.atan2(x1 - x2, y1 - y2))
# here round() returns float type, so use int() to convert it to integer type
polygon = cv2.ellipse2Poly((int(round((y1+y2)/2)), int(round((x1+x2)/2))),
(int(length/2), 3),
int(deg),
0, 360, 1)
img = cv2.fillConvexPoly(img, polygon, color=(49, 22, 122))
# draw rectangle
x, y, w, h = rect
pt1 = (x, y)
pt2 = (x + w, y + h)
cv2.rectangle(img, pt1, pt2, (60, 66, 207), 4)
return img
示例8: create_label
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def create_label(shape, joint_list, person_to_joint_assoc):
label = np.zeros(shape, dtype=np.uint8)
cord_list = []
for limb_type in range(17):
for person_joint_info in person_to_joint_assoc:
joint_indices = person_joint_info[joint_to_limb_heatmap_relationship[limb_type]].astype(int)
if -1 in joint_indices:
continue
joint_coords = joint_list[joint_indices, :2]
coords_center = tuple(np.round(np.mean(joint_coords, 0)).astype(int))
cord_list.append(joint_coords[0])
limb_dir = joint_coords[0, :] - joint_coords[1, :]
limb_length = np.linalg.norm(limb_dir)
angle = math.degrees(math.atan2(limb_dir[1], limb_dir[0]))
polygon = cv2.ellipse2Poly(coords_center, (int(limb_length / 2), 4), int(angle), 0, 360, 1)
cv2.fillConvexPoly(label, polygon, limb_type+1)
return label,cord_list
示例9: getKeypoints
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def getKeypoints(probMap, threshold=0.1):
mapSmooth = cv2.GaussianBlur(probMap, (3, 3), 0, 0)
mapMask = np.uint8(mapSmooth>threshold)
keypoints = []
contours = None
try:
#OpenCV4.x
contours, _ = cv2.findContours(mapMask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
except:
#OpenCV3.x
_, contours, _ = cv2.findContours(mapMask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
blobMask = np.zeros(mapMask.shape)
blobMask = cv2.fillConvexPoly(blobMask, cnt, 1)
maskedProbMap = mapSmooth * blobMask
_, maxVal, _, maxLoc = cv2.minMaxLoc(maskedProbMap)
keypoints.append(maxLoc + (probMap[maxLoc[1], maxLoc[0]],))
return keypoints
示例10: shade
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def shade(self, polygons: np.ndarray, image: np.ndarray) -> np.ndarray:
canvas_dimensions = self.get_output_dimensions(image)
scale_factor = max(canvas_dimensions) / max(image.shape)
scaled_polygons = polygons * scale_factor
output_image = np.zeros(canvas_dimensions, dtype=np.uint8)
for polygon, scaled_polygon in zip(polygons, scaled_polygons):
polygon = self.strip_negative_points(polygon)
scaled_polygon = self.strip_negative_points(scaled_polygon)
if len(polygon) < 3:
continue
mask = np.zeros(image.shape[:2], dtype=np.uint8)
cv2.fillConvexPoly(mask, polygon, (255,))
color = self.get_dominant_color(image[mask > 0], 3, 3).tolist()
# color = cv2.mean(image, mask)[:3]
cv2.fillConvexPoly(output_image, scaled_polygon.astype(np.int32), color, lineType=cv2.LINE_AA)
return output_image
示例11: warpTriangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def warpTriangle(img1, img2, t1, t2):
def applyAffineTransform(src, srcTri, dstTri, size) :
warpMat = cv2.getAffineTransform(np.float32(srcTri), np.float32(dstTri))
dst = cv2.warpAffine(src, warpMat, (size[0], size[1]), None,
flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
return dst
r1 = cv2.boundingRect(np.float32([t1]))
r2 = cv2.boundingRect(np.float32([t2]))
t1Rect = []
t2Rect = []
t2RectInt = []
for i in range(0, 3):
t1Rect.append(((t1[i][0] - r1[0]),(t1[i][1] - r1[1])))
t2Rect.append(((t2[i][0] - r2[0]),(t2[i][1] - r2[1])))
t2RectInt.append(((t2[i][0] - r2[0]),(t2[i][1] - r2[1])))
mask = np.zeros((r2[3], r2[2], 3), dtype = np.float32)
cv2.fillConvexPoly(mask, np.int32(t2RectInt), (1, 1, 1));
img1Rect = img1[r1[1]:r1[1] + r1[3], r1[0]:r1[0] + r1[2]]
size = (r2[2], r2[3])
img2Rect = applyAffineTransform(img1Rect, t1Rect, t2Rect, size)
img2Rect = img2Rect * mask
img2[r2[1]: r2[1] + r2[3], r2[0]: r2[0] + r2[2]] = img2[r2[1]: r2[1] + r2[3],
r2[0]: r2[0] + r2[2]] * ((1.0, 1.0, 1.0) - mask)
img2[r2[1]: r2[1] + r2[3], r2[0]: r2[0] + r2[2]] = img2[r2[1]: r2[1] + r2[3],
r2[0]: r2[0] + r2[2]] + img2Rect
示例12: warpTriangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def warpTriangle(img1, img2, t1, t2):
r1 = cv2.boundingRect(np.float32([t1]))
r2 = cv2.boundingRect(np.float32([t2]))
t1Rect = []
t2Rect = []
t2RectInt = []
for i in range(0, 3):
t1Rect.append(((t1[i][0] - r1[0]), (t1[i][1] - r1[1])))
t2Rect.append(((t2[i][0] - r2[0]), (t2[i][1] - r2[1])))
t2RectInt.append(((t2[i][0] - r2[0]), (t2[i][1] - r2[1])))
mask = np.zeros((r2[3], r2[2], 3), dtype=np.float32)
cv2.fillConvexPoly(mask, np.int32(t2RectInt), (1.0, 1.0, 1.0));
img1Rect = img1[r1[1]:r1[1] + r1[3], r1[0]:r1[0] + r1[2]]
size = (r2[2], r2[3])
img2Rect = applyAffineTransform(img1Rect, t1Rect, t2Rect, size)
img2Rect = img2Rect * mask
img2[r2[1]:r2[1] + r2[3], r2[0]:r2[0] + r2[2]] = img2[r2[1]:r2[1] + r2[3], r2[0]:r2[0] + r2[2]] * (
(1.0, 1.0, 1.0) - mask)
img2[r2[1]:r2[1] + r2[3], r2[0]:r2[0] + r2[2]] = img2[r2[1]:r2[1] + r2[3], r2[0]:r2[0] + r2[2]] + img2Rect
示例13: __smoothen_color
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def __smoothen_color(self, outer, inner):
""" Smoothens and blends colour applied between a set of outlines. """
outer_curve = zip(outer[0], outer[1])
inner_curve = zip(inner[0], inner[1])
x_points = []
y_points = []
for point in outer_curve:
x_points.append(point[0])
y_points.append(point[1])
for point in inner_curve:
x_points.append(point[0])
y_points.append(point[1])
img_base = np.zeros((self.height, self.width))
cv2.fillConvexPoly(img_base, np.array(np.c_[x_points, y_points], dtype='int32'), 1)
img_mask = cv2.GaussianBlur(img_base, (81, 81), 0) #51,51
img_blur_3d = np.ndarray([self.height, self.width, 3], dtype='float')
img_blur_3d[:, :, 0] = img_mask
img_blur_3d[:, :, 1] = img_mask
img_blur_3d[:, :, 2] = img_mask
self.im_copy = (img_blur_3d * self.image * 0.7 + (1 - img_blur_3d * 0.7) * self.im_copy).astype('uint8')
示例14: cal_iou2d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def cal_iou2d(box1, box2):
# Input:
# box1/2: x, y, w, l, r
# Output :
# iou
buf1 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
buf2 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
tmp = center_to_corner_box2d(np.array([box1, box2]), coordinate='lidar')
box1_corner = batch_lidar_to_bird_view(tmp[0]).astype(np.int32)
box2_corner = batch_lidar_to_bird_view(tmp[1]).astype(np.int32)
buf1 = cv2.fillConvexPoly(buf1, box1_corner, color=(1,1,1))[..., 0]
buf2 = cv2.fillConvexPoly(buf2, box2_corner, color=(1,1,1))[..., 0]
indiv = np.sum(np.absolute(buf1-buf2))
share = np.sum((buf1 + buf2) == 2)
if indiv == 0:
return 0.0 # when target is out of bound
return share / (indiv + share)
示例15: cal_iou3d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import fillConvexPoly [as 別名]
def cal_iou3d(box1, box2):
# Input:
# box1/2: x, y, z, h, w, l, r
# Output:
# iou
buf1 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
buf2 = np.zeros((cfg.INPUT_HEIGHT, cfg.INPUT_WIDTH, 3))
tmp = center_to_corner_box2d(np.array([box1[[0,1,4,5,6]], box2[[0,1,4,5,6]]]), coordinate='lidar')
box1_corner = batch_lidar_to_bird_view(tmp[0]).astype(np.int32)
box2_corner = batch_lidar_to_bird_view(tmp[1]).astype(np.int32)
buf1 = cv2.fillConvexPoly(buf1, box1_corner, color=(1,1,1))[..., 0]
buf2 = cv2.fillConvexPoly(buf2, box2_corner, color=(1,1,1))[..., 0]
share = np.sum((buf1 + buf2) == 2)
area1 = np.sum(buf1)
area2 = np.sum(buf2)
z1, h1, z2, h2 = box1[2], box1[3], box2[2], box2[3]
z_intersect = cal_z_intersect(z1, h1, z2, h2)
return share * z_intersect / (area1 * h1 + area2 * h2 - share * z_intersect)