def preprocess_image(anno, H): image = imread(anno.imageName) # skip greyscale images if len(image.shape) < 3: return [] # 4 channels images check if image.shape[2] == 4: image = image[:, :, :3] if 'rotate90' in H['data'] and H['data']['rotate90']: image, anno = Rotate90.do(image, anno) if image.shape[0] != H["image_height"] or image.shape[1] != H[ "image_width"]: anno = rescale_boxes(image.shape, anno, H["image_height"], H["image_width"]) image = imresize(image, (H["image_height"], H["image_width"]), interp='cubic') result = [(image, anno)] if 'augmentations' in H['data']: new_res = [] for i, a in result: augmented = Augmentations(H['data']).process(i, a) new_res.append(augmented) result = new_res return result
def rect_predict(image_path, parameters, to_json, H, options): orig_img = imread(image_path)[:, :, :3] img = Rotate90.do( orig_img )[0] if 'rotate90' in H['data'] and H['data']['rotate90'] else orig_img img = imresize(img, (H['image_height'], H['image_width']), interp='cubic') np_pred_boxes, np_pred_confidences = parameters['sess']. \ run([parameters['pred_boxes'], parameters['pred_confidences']], feed_dict={parameters['x_in']: img}) image_info = { 'path': image_path, 'original_shape': img.shape[:2], 'transformed': img } pred_anno = postprocess_regular(image_info, np_pred_boxes, np_pred_confidences, H, options) ret_list = [{ 'x1': r.x1, 'x2': r.x2, 'y1': r.y1, 'y2': r.y2, } for r in pred_anno] return ret_list
def preprocess_image(anno, H): image = imread(anno.imageName) # skip greyscale images if len(image.shape) < 3: return [] if 'rotate90' in H['data'] and H['data']['rotate90']: image, anno = Rotate90.do(image, anno) result = [(image, anno)] if 'augmentations' in H['data']: new_res = [] for i, a in result: augmented = Augmentations(H['data']).process(i, a) new_res.append(augmented) result = new_res return result
def sliding_predict(image_path, parameters, to_json, H, options): orig_img = imread(image_path)[:, :, :3] height, width, _ = orig_img.shape if options.get('verbose', False): print(width, height) sl_win_options = H['sliding_predict'] assert (sl_win_options['window_height'] > sl_win_options['overlap']) slides = propose_slides(height, sl_win_options['window_height'], sl_win_options['overlap']) result = [] for top, bottom in slides: bottom = min(height, top + sl_win_options['window_height']) if options.get('verbose', False): print('Slide: ', 0, top, width, bottom) img = orig_img[top:bottom, 0:width] img = Rotate90.do( img )[0] if 'rotate90' in H['data'] and H['data']['rotate90'] else img img = imresize(img, (H['image_height'], H['image_width']), interp='cubic') np_pred_boxes, np_pred_confidences = parameters['sess']. \ run([parameters['pred_boxes'], parameters['pred_confidences']], feed_dict={parameters['x_in']: img}) image_info = { 'path': image_path, 'original_shape': (bottom - top, width), 'transformed': img, 'a': orig_img[top:bottom, 0:width] } pred_boxes = postprocess_regular(image_info, np_pred_boxes, np_pred_confidences, H, options) shift_boxes(pred_boxes, top) result.extend(pred_boxes) result = combine_boxes(result, sl_win_options['iou_min'], sl_win_options['nms']) result = [r.writeJSON() for r in result] if to_json else result return result