diff --git a/services/paddle_services/paddle_detection/detector.py b/services/paddle_services/paddle_detection/detector.py index a121682..5be9f03 100644 --- a/services/paddle_services/paddle_detection/detector.py +++ b/services/paddle_services/paddle_detection/detector.py @@ -4,7 +4,6 @@ from collections import defaultdict import cv2 import numpy as np -from util import image_util from . import PADDLE_DET, MODEL_DIR from .deploy.third_engine.onnx.infer import PredictConfig from .deploy.third_engine.onnx.preprocess import Compose @@ -37,11 +36,25 @@ def detect_image(img_path): return predict_image(infer_config, PADDLE_DET, img_path) +def capture(image, rectangle): + x1, y1, x2, y2 = rectangle + height, width = image.shape[:2] + if x1 < 0: + x1 = 0 + if y1 < 0: + y1 = 0 + if x2 > width: + x2 = width + if y2 > height: + y2 = height + return image[int(y1):int(y2), int(x1):int(x2)] + + def get_book_areas(img_path): detect_result = detect_image(img_path) book_areas = detect_result[73] result = [] image = cv2.imread(img_path) for book_area in book_areas: - result.append(image_util.capture(image, book_area['box'])) + result.append(capture(image, book_area['box'])) return result