Python cv2.ellipse2Poly() Examples
The following are 16
code examples of cv2.ellipse2Poly().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: RegionOfInterest.py From DoNotSnap with GNU General Public License v3.0 | 7 votes |
def findEllipses(edges): contours, _ = cv2.findContours(edges.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) ellipseMask = np.zeros(edges.shape, dtype=np.uint8) contourMask = np.zeros(edges.shape, dtype=np.uint8) pi_4 = np.pi * 4 for i, contour in enumerate(contours): if len(contour) < 5: continue area = cv2.contourArea(contour) if area <= 100: # skip ellipses smaller then 10x10 continue arclen = cv2.arcLength(contour, True) circularity = (pi_4 * area) / (arclen * arclen) ellipse = cv2.fitEllipse(contour) poly = cv2.ellipse2Poly((int(ellipse[0][0]), int(ellipse[0][1])), (int(ellipse[1][0] / 2), int(ellipse[1][1] / 2)), int(ellipse[2]), 0, 360, 5) # if contour is circular enough if circularity > 0.6: cv2.fillPoly(ellipseMask, [poly], 255) continue # if contour has enough similarity to an ellipse similarity = cv2.matchShapes(poly.reshape((poly.shape[0], 1, poly.shape[1])), contour, cv2.cv.CV_CONTOURS_MATCH_I2, 0) if similarity <= 0.2: cv2.fillPoly(contourMask, [poly], 255) return ellipseMask, contourMask
Example #2
Source File: demo_main.py From centerpose with MIT License | 6 votes |
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
Example #3
Source File: debugger.py From centerpose with MIT License | 6 votes |
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)
Example #4
Source File: utils.py From VNect with Apache License 2.0 | 6 votes |
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
Example #5
Source File: openpose_utils.py From EverybodyDanceNow_reproduce_pytorch with MIT License | 6 votes |
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
Example #6
Source File: openpose_utils.py From EverybodyDanceNow-Temporal-FaceGAN with MIT License | 6 votes |
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
Example #7
Source File: visualization.py From 2D-Motion-Retargeting with MIT License | 5 votes |
def pose2im(all_peaks, limbSeq, limb_colors, joint_colors, H, W, _circle=True, _limb=True, imtype=np.uint8): canvas = np.zeros(shape=(H, W, 3)) canvas.fill(255) if _circle: for i in range(len(joint_colors)): cv2.circle(canvas, (int(all_peaks[i][0]), int(all_peaks[i][1])), 2, joint_colors[i], thickness=2) if _limb: stickwidth = 2 for i in range(len(limbSeq)): limb = limbSeq[i] cur_canvas = canvas.copy() point1_index = limb[0] point2_index = limb[1] if len(all_peaks[point1_index]) > 0 and len(all_peaks[point2_index]) > 0: point1 = all_peaks[point1_index][0:2] point2 = all_peaks[point2_index][0:2] X = [point1[1], point2[1]] Y = [point1[0], point2[0]] mX = np.mean(X) mY = np.mean(Y) # cv2.line() 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, limb_colors[i]) canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0) return canvas.astype(imtype)
Example #8
Source File: run_demo_hand_with_tracker.py From convolutional-pose-machines-tensorflow with Apache License 2.0 | 5 votes |
def draw_hand(full_img, joint_coords, is_loss_track): if is_loss_track: joint_coords = FLAGS.default_hand # Plot joints for joint_num in range(FLAGS.num_of_joints): color_code_num = (joint_num // 4) if joint_num in [0, 4, 8, 12, 16]: joint_color = list(map(lambda x: x + 35 * (joint_num % 4), FLAGS.joint_color_code[color_code_num])) cv2.circle(full_img, center=(int(joint_coords[joint_num][1]), int(joint_coords[joint_num][0])), radius=3, color=joint_color, thickness=-1) else: joint_color = list(map(lambda x: x + 35 * (joint_num % 4), FLAGS.joint_color_code[color_code_num])) cv2.circle(full_img, center=(int(joint_coords[joint_num][1]), int(joint_coords[joint_num][0])), radius=3, color=joint_color, thickness=-1) # Plot limbs for limb_num in range(len(FLAGS.limbs)): x1 = int(joint_coords[int(FLAGS.limbs[limb_num][0])][0]) y1 = int(joint_coords[int(FLAGS.limbs[limb_num][0])][1]) x2 = int(joint_coords[int(FLAGS.limbs[limb_num][1])][0]) y2 = int(joint_coords[int(FLAGS.limbs[limb_num][1])][1]) length = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 if length < 150 and length > 5: deg = math.degrees(math.atan2(x1 - x2, y1 - y2)) polygon = cv2.ellipse2Poly((int((y1 + y2) / 2), int((x1 + x2) / 2)), (int(length / 2), 3), int(deg), 0, 360, 1) color_code_num = limb_num // 4 limb_color = list(map(lambda x: x + 35 * (limb_num % 4), FLAGS.joint_color_code[color_code_num])) cv2.fillConvexPoly(full_img, polygon, color=limb_color)
Example #9
Source File: utils.py From convolutional-pose-machines-tensorflow with Apache License 2.0 | 5 votes |
def draw_limbs_2d(img, joints_2d, limb_parents): for limb_num in range(len(limb_parents)-1): 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 # if length < 10000 and length > 5: deg = math.degrees(math.atan2(x1 - x2, y1 - y2)) polygon = cv2.ellipse2Poly((int((y1 + y2) / 2), int((x1 + x2) / 2)), (int(length / 2), 3), int(deg), 0, 360, 1) cv2.fillConvexPoly(img, polygon, color=(0,255,0)) return img
Example #10
Source File: openpose_utils.py From EverybodyDanceNow-Temporal-FaceGAN with MIT License | 5 votes |
def draw(joint_coords, label, thickness = 4): coords_center = tuple(np.round(np.mean(joint_coords, 0)).astype(int)) 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), thickness), int(angle), 0, 360, 1) x = label.copy() cv2.fillConvexPoly(x, polygon, 1) return x
Example #11
Source File: openpose_utils.py From EverybodyDanceNow-Temporal-FaceGAN with MIT License | 5 votes |
def create_face_label(shape , joints): # shape = (shape[0], shape[1], 10) label = np.zeros(shape, dtype=np.uint8) for connection_type in range(len(face)): for connection in face[connection_type]: if min(joints[connection, 2]) < 0.01: continue joint_indices = joints[connection,:2].astype(int) label[:,:,0] = draw(joint_indices[:, :2], label[:,:,0], thickness = 1) # label[:,:,connection_type] = draw(joint_indices[:, :2], label[:,:,connection_type]) # fig = plt.figure(1) # ax = fig.add_subplot(111) # ax.imshow(label[:,:,0]) # plt.show() x = label[:,:, 8].copy() polygon = cv2.ellipse2Poly(tuple(joints[68,:2].astype(int)), (1, 1), 0, 0, 360, 1) #left eye cv2.fillConvexPoly(x, polygon, 1) label[:,:, 8] = x x = label[:,:, 9].copy() polygon = cv2.ellipse2Poly(tuple(joints[69,:2].astype(int)), (1, 1), 0, 0, 360, 1) #right eye cv2.fillConvexPoly(x, polygon, 1) label[:,:, 9] = x return label
Example #12
Source File: utils.py From VNect-tensorflow with Apache License 2.0 | 5 votes |
def draw_limbs_2d(img, joints_2d, limb_parents): for limb_num in range(len(limb_parents)-1): 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 # if length < 10000 and length > 5: deg = math.degrees(math.atan2(x1 - x2, y1 - y2)) polygon = cv2.ellipse2Poly((int((y1 + y2) / 2), int((x1 + x2) / 2)), (int(length / 2), 3), int(deg), 0, 360, 1) cv2.fillConvexPoly(img, polygon, color=(0,255,0)) return img
Example #13
Source File: utils.py From VNect-tensorflow with Apache License 2.0 | 5 votes |
def draw_limbs_2d(img, joints_2d, limb_parents): for limb_num in range(len(limb_parents)-1): 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 # if length < 10000 and length > 5: deg = math.degrees(math.atan2(x1 - x2, y1 - y2)) polygon = cv2.ellipse2Poly((int((y1 + y2) / 2), int((x1 + x2) / 2)), (int(length / 2), 3), int(deg), 0, 360, 1) cv2.fillConvexPoly(img, polygon, color=(0,255,0)) return
Example #14
Source File: util.py From Qualia2.0 with MIT License | 4 votes |
def plot_pose(img_orig, joint_list, person_to_joint_assoc, bool_fast_plot=True, plot_ear_to_shoulder=False): canvas = img_orig.copy() # Make a copy so we don't modify the original image # to_plot is the location of all joints found overlaid on top of the # original image to_plot = canvas.copy() if bool_fast_plot else cv2.addWeighted(img_orig, 0.3, canvas, 0.7, 0) limb_thickness = 4 # Last 2 limbs connect ears with shoulders and this looks very weird. # Disabled by default to be consistent with original rtpose output which_limbs_to_plot = NUM_LIMBS if plot_ear_to_shoulder else NUM_LIMBS - 2 for limb_type in range(which_limbs_to_plot): for person_joint_info in person_to_joint_assoc: joint_indices = person_joint_info[edges_body[limb_type]].astype(int) if -1 in joint_indices: # Only draw actual limbs (connected joints), skip if not # connected continue # joint_coords[:,0] represents Y coords of both joints; # joint_coords[:,1], X coords joint_coords = joint_list[joint_indices, 0:2] for joint in joint_coords: # Draw circles at every joint cv2.circle(canvas, tuple(joint[0:2].astype(int)), 4, (255, 255, 255), thickness=-1) # mean along the axis=0 computes meanYcoord and meanXcoord -> Round # and make int to avoid errors coords_center = tuple(np.round(np.mean(joint_coords, 0)).astype(int)) # joint_coords[0,:] is the coords of joint_src; joint_coords[1,:] # is the coords of joint_dst limb_dir = joint_coords[0, :] - joint_coords[1, :] limb_length = np.linalg.norm(limb_dir) # Get the angle of limb_dir in degrees using atan2(limb_dir_x, # limb_dir_y) angle = math.degrees(math.atan2(limb_dir[1], limb_dir[0])) # For faster plotting, just plot over canvas instead of constantly # copying it cur_canvas = canvas if bool_fast_plot else canvas.copy() polygon = cv2.ellipse2Poly(coords_center, (int(limb_length / 2), limb_thickness), int(angle), 0, 360, 1) cv2.fillConvexPoly(cur_canvas, polygon, colors[limb_type]) if not bool_fast_plot: canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0) return to_plot, canvas
Example #15
Source File: post.py From EverybodyDanceNow_reproduce_pytorch with MIT License | 4 votes |
def plot_pose(img_orig, joint_list, person_to_joint_assoc, bool_fast_plot=True, plot_ear_to_shoulder=False): canvas = img_orig.copy() # Make a copy so we don't modify the original image # to_plot is the location of all joints found overlaid on top of the # original image to_plot = canvas.copy() if bool_fast_plot else cv2.addWeighted( img_orig, 0.3, canvas, 0.7, 0) limb_thickness = 4 # Last 2 limbs connect ears with shoulders and this looks very weird. # Disabled by default to be consistent with original rtpose output which_limbs_to_plot = NUM_LIMBS if plot_ear_to_shoulder else NUM_LIMBS - 2 for limb_type in range(which_limbs_to_plot): 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: # Only draw actual limbs (connected joints), skip if not # connected continue # joint_coords[:,0] represents Y coords of both joints; # joint_coords[:,1], X coords joint_coords = joint_list[joint_indices, 0:2] for joint in joint_coords: # Draw circles at every joint cv2.circle(canvas, tuple(joint[0:2].astype( int)), 4, (255,255,255), thickness=-1) # mean along the axis=0 computes meanYcoord and meanXcoord -> Round # and make int to avoid errors coords_center = tuple( np.round(np.mean(joint_coords, 0)).astype(int)) # joint_coords[0,:] is the coords of joint_src; joint_coords[1,:] # is the coords of joint_dst limb_dir = joint_coords[0, :] - joint_coords[1, :] limb_length = np.linalg.norm(limb_dir) # Get the angle of limb_dir in degrees using atan2(limb_dir_x, # limb_dir_y) angle = math.degrees(math.atan2(limb_dir[1], limb_dir[0])) # For faster plotting, just plot over canvas instead of constantly # copying it cur_canvas = canvas if bool_fast_plot else canvas.copy() polygon = cv2.ellipse2Poly( coords_center, (int(limb_length / 2), limb_thickness), int(angle), 0, 360, 1) cv2.fillConvexPoly(cur_canvas, polygon, colors[limb_type]) if not bool_fast_plot: canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0) return to_plot, canvas
Example #16
Source File: post.py From part-affinity with MIT License | 4 votes |
def plot_pose(img_orig, joint_list, person_to_joint_assoc, bool_fast_plot=True, plot_ear_to_shoulder=False): canvas = (img_orig.copy()*255).astype('uint8') # Make a copy so we don't modify the original image # to_plot is the location of all joints found overlaid on top of the # original image to_plot = canvas.copy() if bool_fast_plot else cv2.addWeighted( img_orig, 0.3, canvas, 0.7, 0) limb_thickness = 4 # Last 2 limbs connect ears with shoulders and this looks very weird. # Disabled by default to be consistent with original rtpose output which_limbs_to_plot = NUM_LIMBS for limb_type in range(which_limbs_to_plot): for person_joint_info in person_to_joint_assoc: limb = joint_to_limb_heatmap_relationship[limb_type] joint_indices = person_joint_info[[limb[0], limb[1]]].astype( int) if -1 in joint_indices: # Only draw actual limbs (connected joints), skip if not # connected continue # joint_coords[:,0] represents Y coords of both joints; # joint_coords[:,1], X coords joint_coords = joint_list[joint_indices, 0:2] for joint in joint_coords: # Draw circles at every joint cv2.circle(canvas, tuple(joint[0:2].astype( int)), 4, (255, 255, 255), thickness=-1) # mean along the axis=0 computes meanYcoord and meanXcoord -> Round # and make int to avoid errors coords_center = tuple( np.round(np.mean(joint_coords, 0)).astype(int)) # joint_coords[0,:] is the coords of joint_src; joint_coords[1,:] # is the coords of joint_dst limb_dir = joint_coords[0, :] - joint_coords[1, :] limb_length = np.linalg.norm(limb_dir) # Get the angle of limb_dir in degrees using atan2(limb_dir_x, # limb_dir_y) angle = math.degrees(math.atan2(limb_dir[1], limb_dir[0])) # For faster plotting, just plot over canvas instead of constantly # copying it cur_canvas = canvas if bool_fast_plot else canvas.copy() polygon = cv2.ellipse2Poly( coords_center, (int(limb_length / 2), limb_thickness), int(angle), 0, 360, 1) cv2.fillConvexPoly(cur_canvas, polygon, colors[limb_type]) if not bool_fast_plot: canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0) return to_plot, canvas