def estimate_paf(peaks, heat_mat, paf_mat): pafprocess.process_paf(peaks, heat_mat, paf_mat) humans = [] for human_id in range(pafprocess.get_num_humans()): human = Human([]) is_added = False for part_idx in range(18): c_idx = int(pafprocess.get_part_cid(human_id, part_idx)) if c_idx < 0: continue is_added = True human.body_parts[part_idx] = BodyPart( '%d-%d' % (human_id, part_idx), part_idx, float(pafprocess.get_part_x(c_idx)) / heat_mat.shape[1], float(pafprocess.get_part_y(c_idx)) / heat_mat.shape[0], pafprocess.get_part_score(c_idx)) if is_added: score = pafprocess.get_score(human_id) human.score = score humans.append(human) return humans
peaks[local_max, i] = heatMat[local_max, i] plt.figure() plt.imshow(np.sum(peaks[:, :, i] for i in range(19))) plt.show() #Particule Affinity Field to separate people pafprocess.process_paf(peaks.astype('float32'), heatMat.astype('float32'), pafMat.astype('float32')) humans = [] for human_id in range(pafprocess.get_num_humans()): body_parts = [(0.0, 0.0)] * 18 for part_idx in range(18): c_idx = int(pafprocess.get_part_cid(human_id, part_idx)) if c_idx < 0: continue is_added = True body_parts[part_idx] = (pafprocess.get_part_x(c_idx), pafprocess.get_part_y(c_idx)) body_parts = np.array( [[body_parts[i][0] * scale, body_parts[i][1] * scale] for i in range(18)]).flatten() humans.append(body_parts) # Draw human body parts d = ImageDraw.Draw(resized) for _data in humans: for pair in connections: