@@ -27,10 +27,9 @@ def get_params(self) -> Dict[str, Any]:
2727 'mode' : {'type' : 'enum' , 'default' : 'EXTERNAL' , 'options' : list (self .mode_map .keys ()), 'label' : '轮廓检索模式' , 'tooltip' : 'EXTERNAL:只找最外层轮廓。LIST:查找所有轮廓,不建立层次结构。TREE:建立完整层次结构。' },
2828 'method' : {'type' : 'enum' , 'default' : 'SIMPLE' , 'options' : list (self .method_map .keys ()), 'label' : '轮廓逼近方法' , 'tooltip' : 'SIMPLE:压缩水平、垂直和对角线段,只保留端点。NONE:存储所有轮廓点。' },
2929 'draw_contours' : {'type' : 'bool' , 'default' : True , 'label' : '绘制轮廓' , 'tooltip' : '是否在调试图像上用绿色线条画出找到的轮廓。' },
30- 'noise_threshold_ratio' : {'type' : 'float' , 'default' : 0.25 , 'range' : (0.0 , 1.0 ), 'label' : '噪点比例阈值' , 'tooltip' : '输入图像的白色像素比例若高于此值,则跳过轮廓查找以防止卡死。建议范围:0.1-0.4' },
3130 }
3231
33- def _execute (self , context : CvPipelineContext , mode : str = 'EXTERNAL' , method : str = 'SIMPLE' , draw_contours : bool = True , noise_threshold_ratio : float = 0.25 , ** _kwargs ):
32+ def _execute (self , context : CvPipelineContext , mode : str = 'EXTERNAL' , method : str = 'SIMPLE' , draw_contours : bool = True , ** _kwargs ):
3433 if context .mask_image is None :
3534 return
3635
@@ -42,16 +41,6 @@ def _execute(self, context: CvPipelineContext, mode: str = 'EXTERNAL', method: s
4241 context .success = False
4342 return
4443
45- white_pixels = cv2 .countNonZero (context .mask_image )
46- white_ratio = white_pixels / total_pixels
47-
48- if white_ratio > noise_threshold_ratio :
49- context .error_str = f"输入图像噪点过多 (白色像素比例 { white_ratio :.2f} > { noise_threshold_ratio } ),跳过轮廓查找以防止卡死"
50- context .success = False
51- context .analysis_results .append (f"跳过轮廓查找:噪点比例 { white_ratio :.2f} 超过阈值 { noise_threshold_ratio } " )
52- context .contours = [] # 清空轮廓列表
53- return
54-
5544 cv2_mode = self .mode_map .get (mode )
5645 cv2_method = self .method_map .get (method )
5746 if cv2_mode is None or cv2_method is None :
@@ -69,4 +58,4 @@ def _execute(self, context: CvPipelineContext, mode: str = 'EXTERNAL', method: s
6958 # 在一个新图像上绘制轮廓,以免影响下一步的处理
7059 display_with_contours = context .display_image .copy ()
7160 cv2 .drawContours (display_with_contours , contours , - 1 , (0 , 255 , 0 ), 2 )
72- context .display_image = display_with_contours
61+ context .display_image = display_with_contours
0 commit comments