MCPcopy Index your code
hub / github.com/BIT-DataLab/Edit-Banana / _extract_polygon

Method _extract_polygon

modules/sam3_info_extractor.py:345–360  ·  view source on GitHub ↗

从mask提取多边形轮廓

(self, binary_mask: np.ndarray, 
                         min_area: int = 100, 
                         epsilon_factor: float = 0.02)

Source from the content-addressed store, hash-verified

343 return state, pil_image
344
345 def _extract_polygon(self, binary_mask: np.ndarray,
346 min_area: int = 100,
347 epsilon_factor: float = 0.02) -> List[List[int]]:
348 """从mask提取多边形轮廓"""
349 contours, _ = cv2.findContours(binary_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
350
351 for cnt in contours:
352 area = cv2.contourArea(cnt)
353 if area < min_area:
354 continue
355
356 epsilon = epsilon_factor * cv2.arcLength(cnt, True)
357 approx = cv2.approxPolyDP(cnt, epsilon, True)
358 return approx.reshape(-1, 2).tolist()
359
360 return []
361
362 def clear_cache(self):
363 """清空图像缓存"""

Callers 1

predictMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected