def __test_img(self, image_path, save_path): image_raw = ImageHelper.cv2_open_bgr(image_path) inputs = ImageHelper.bgr2rgb(image_raw) heatmap_avg = self.__get_heatmap(inputs) all_peaks = self.__extract_heatmap_info(heatmap_avg) image_save = self.__draw_key_point(all_peaks, image_raw) cv2.imwrite(save_path, image_save)
def __test_img(self, image_path, json_path, raw_path, vis_path): Log.info('Image Path: {}'.format(image_path)) ori_img_rgb = ImageHelper.img2np(ImageHelper.pil_open_rgb(image_path)) cur_img_rgb = ImageHelper.resize(ori_img_rgb, self.configer.get( 'data', 'input_size'), interpolation=Image.CUBIC) ori_img_bgr = ImageHelper.bgr2rgb(ori_img_rgb) paf_avg, heatmap_avg = self.__get_paf_and_heatmap(cur_img_rgb) all_peaks = self.__extract_heatmap_info(heatmap_avg) special_k, connection_all = self.__extract_paf_info( cur_img_rgb, paf_avg, all_peaks) subset, candidate = self.__get_subsets(connection_all, special_k, all_peaks) json_dict = self.__get_info_tree(cur_img_rgb, subset, candidate) for i in range(len(json_dict['objects'])): for index in range(len(json_dict['objects'][i]['keypoints'])): if json_dict['objects'][i]['keypoints'][index][2] == -1: continue json_dict['objects'][i]['keypoints'][index][0] *= ( ori_img_rgb.shape[1] / cur_img_rgb.shape[1]) json_dict['objects'][i]['keypoints'][index][1] *= ( ori_img_rgb.shape[0] / cur_img_rgb.shape[0]) image_canvas = self.pose_parser.draw_points(ori_img_bgr.copy(), json_dict) image_canvas = self.pose_parser.link_points(image_canvas, json_dict) cv2.imwrite(vis_path, image_canvas) cv2.imwrite(raw_path, ori_img_bgr) Log.info('Json Save Path: {}'.format(json_path)) with open(json_path, 'w') as save_stream: save_stream.write(json.dumps(json_dict))
def __test_img(self, image_path, save_path): Log.info('Image Path: {}'.format(image_path)) image_raw = ImageHelper.cv2_open_bgr(image_path) inputs = ImageHelper.bgr2rgb(image_raw) inputs = ImageHelper.resize(inputs, tuple(self.configer.get('data', 'input_size')), Image.CUBIC) inputs = ToTensor()(inputs) inputs = Normalize(mean=self.configer.get('trans_params', 'mean'), std=self.configer.get('trans_params', 'std'))(inputs) with torch.no_grad(): inputs = inputs.unsqueeze(0).to(self.device) bbox, cls = self.det_net(inputs) bbox = bbox.cpu().data.squeeze(0) cls = F.softmax(cls.cpu().squeeze(0), dim=-1).data boxes, lbls, scores, has_obj = self.__decode(bbox, cls) if has_obj: boxes = boxes.cpu().numpy() boxes = np.clip(boxes, 0, 1) lbls = lbls.cpu().numpy() scores = scores.cpu().numpy() img_canvas = self.__draw_box(image_raw, boxes, lbls, scores) else: # print('None obj detected!') img_canvas = image_raw Log.info('Save Path: {}'.format(save_path)) cv2.imwrite(save_path, img_canvas) # Boxes is within 0-1. self.__save_json(save_path, boxes, lbls, scores, image_raw) return image_raw, lbls, scores, boxes, has_obj
def __test_img(self, image_path, save_path): Log.info('Image Path: {}'.format(image_path)) image_raw = ImageHelper.cv2_open_bgr(image_path) inputs = ImageHelper.bgr2rgb(image_raw) paf_avg, heatmap_avg = self.__get_paf_and_heatmap(inputs) all_peaks = self.__extract_heatmap_info(heatmap_avg) special_k, connection_all = self.__extract_paf_info(image_raw, paf_avg, all_peaks) subset, candidate = self.__get_subsets(connection_all, special_k, all_peaks) subset, img_canvas = self.__draw_key_point(subset, all_peaks, image_raw) img_canvas = self.__link_key_point(img_canvas, candidate, subset) cv2.imwrite(save_path, img_canvas)
def __test_img(self, image_path, json_path, raw_path, vis_path): Log.info('Image Path: {}'.format(image_path)) ori_img_rgb = ImageHelper.img2np(ImageHelper.pil_open_rgb(image_path)) ori_img_bgr = ImageHelper.bgr2rgb(ori_img_rgb) paf_avg, heatmap_avg = self.__get_paf_and_heatmap(ori_img_rgb) all_peaks = self.__extract_heatmap_info(heatmap_avg) special_k, connection_all = self.__extract_paf_info( ori_img_rgb, paf_avg, all_peaks) subset, candidate = self.__get_subsets(connection_all, special_k, all_peaks) json_dict = self.__get_info_tree(ori_img_rgb, subset, candidate) image_canvas = self.pose_parser.draw_points(ori_img_bgr.copy(), json_dict) image_canvas = self.pose_parser.link_points(image_canvas, json_dict) cv2.imwrite(vis_path, image_canvas) cv2.imwrite(raw_path, ori_img_bgr) Log.info('Json Save Path: {}'.format(json_path)) JsonHelper.save_file(json_dict, json_path)