From 2e1c0a57c74adab758ffb92fb93ec2a78274e16f Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 26 Sep 2024 17:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=B9=E6=B3=95=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../paddle_detection/detector.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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