From 10fb804c14701d9ab2ea075177bd2b6ccb0ee75e Mon Sep 17 00:00:00 2001 From: SkyLi Date: Fri, 27 Mar 2026 08:51:59 +0800 Subject: [PATCH] fix: fix image duplicate loading in diagnose function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将cv2.imread从循环内移至循环前,避免对同一张图片重复加载 --- src/diagnose.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/diagnose.py b/src/diagnose.py index 1b0f266..c2d2dcd 100644 --- a/src/diagnose.py +++ b/src/diagnose.py @@ -50,16 +50,16 @@ class FaultDiagnoser: detections = self.detector.detect(image) result['detections'] = detections + import cv2 + if isinstance(image, str): + img = cv2.imread(image, cv2.IMREAD_GRAYSCALE) + else: + img = image + for det in detections: bbox = det['bbox'] x1, y1, x2, y2 = map(int, bbox) - if isinstance(image, str): - import cv2 - img = cv2.imread(image, cv2.IMREAD_GRAYSCALE) - else: - img = image - roi = img[y1:y2, x1:x2] temp_features = self.extractor.extract_from_roi(roi)