From b867c5ddb71b971b2738eb4ded547ab9c3ba7743 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Thu, 29 Aug 2024 14:39:17 +0800 Subject: [PATCH] =?UTF-8?q?feat=20fix=20=20=20design=20mask=E6=A0=87?= =?UTF-8?q?=E6=B3=A8=E6=8F=90=E5=8F=96=20=E8=AE=BE=E7=BD=AE=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E7=9A=84=E4=B8=8A=E7=95=8C=E4=B8=8B=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design/items/pipelines/segmentation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/service/design/items/pipelines/segmentation.py b/app/service/design/items/pipelines/segmentation.py index ac38b34..2937df6 100644 --- a/app/service/design/items/pipelines/segmentation.py +++ b/app/service/design/items/pipelines/segmentation.py @@ -23,12 +23,18 @@ class Segmentation(object): # 转换颜色空间为 RGB(OpenCV 默认是 BGR) image_rgb = cv2.cvtColor(seg_mask, cv2.COLOR_BGR2RGB) - front_color = np.array([255, 0, 0], dtype=np.uint8) - back_color = np.array([0, 255, 0], dtype=np.uint8) + # 定义红色和绿色的颜色范围 + # 红色范围: 下界 [R-10, G-10, B-10], 上界 [R+10, G+10, B+10] + red_lower = np.array([50, 0, 0], dtype=np.uint8) + red_upper = np.array([255, 50, 50], dtype=np.uint8) + + # 绿色范围: 下界 [R-10, G-10, B-10], 上界 [R+10, G+10, B+10] + green_lower = np.array([0, 50, 0], dtype=np.uint8) + green_upper = np.array([50, 255, 50], dtype=np.uint8) # 创建红色和绿色掩码 - result['front_mask'] = cv2.inRange(image_rgb, front_color, front_color) - result['back_mask'] = cv2.inRange(image_rgb, back_color, back_color) + result['front_mask'] = cv2.inRange(image_rgb, red_lower, red_upper) + result['back_mask'] = cv2.inRange(image_rgb, green_lower, green_upper) result['mask'] = result['front_mask'] + result['back_mask'] else: # 本地查询seg 缓存是否存在