|
def is_mouth_open(self, image_path, threshold=15):
"""检测嘴部是否张开 - 优化版本"""
try:
image_path = Path(image_path)
dflimg = DFLIMG.load(image_path)
if dflimg is None or not dflimg.has_data():
return None, f"{image_path.name} 不符合DFL规范"
landmarks = dflimg.get_landmarks()
if landmarks is None or len(landmarks) < 67:
return None, f"{image_path.name} 的关键点提取失败"
# 提取嘴部关键点 - 使用numpy切片优化
mouth_points = landmarks[[62, 63, 64, 65, 66], :]
# 计算嘴巴的高度差
mouth_height_diff = mouth_points[4][1] - mouth_points[0][1] # 66y - 62y
if mouth_height_diff > threshold:
output_dir = image_path.parent / '张嘴的'
return output_dir, None
else:
return None, None # 闭嘴的不进行处理
except Exception as e:
return None, f"处理 {image_path.name} 时出错: {str(e)}" |
|