RavindranadhM's picture
Deploy manufacturing monitoring system
201b13c verified
Raw
History Blame Contribute Delete
1.04 kB
from typing import Dict
from core.config import settings
def classify_defect(area: float, length: float, area_ratio: float) -> Dict[str, str]:
"""
Classify defect severity based on geometric features.
Args:
area: Pixel area of defect
length: Contour length of defect
area_ratio: Area relative to image
Returns:
Dictionary with severity and decision
"""
# Thresholds (move to config later if needed)
CRITICAL_AREA_RATIO = 0.01
CRITICAL_LENGTH = 180
MODERATE_AREA_RATIO = 0.003
MODERATE_LENGTH = 60
# Critical defects
if area_ratio > CRITICAL_AREA_RATIO or length > CRITICAL_LENGTH:
severity = "Critical"
decision = "FAIL"
# Moderate defects
elif area_ratio > MODERATE_AREA_RATIO or length > MODERATE_LENGTH:
severity = "Moderate"
decision = "REVIEW"
# Minor defects
else:
severity = "Minor"
decision = "PASS"
return {
"severity": severity,
"decision": decision
}