50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""
|
|
快速测试单个标注文件格式
|
|
用于验证从CVAT导出的多边形标注是否正确
|
|
"""
|
|
import sys
|
|
from verify_seg_labels import verify_yolo_seg_format, visualize_seg_label
|
|
|
|
def test_label_file(label_path, img_path=None):
|
|
"""测试单个标注文件"""
|
|
print(f"验证标注文件: {label_path}")
|
|
print("-" * 60)
|
|
|
|
result = verify_yolo_seg_format(label_path, img_path, show_visualization=(img_path is not None))
|
|
|
|
if result["valid"]:
|
|
print("✓ 格式正确!")
|
|
print(f" 类别ID: {result['class_id']}")
|
|
print(f" 多边形顶点数: {result['num_points']}")
|
|
print(f" 坐标值数量: {result['coords_count']}")
|
|
else:
|
|
print("✗ 格式错误!")
|
|
|
|
if result["errors"]:
|
|
print("错误信息:")
|
|
for error in result["errors"]:
|
|
print(f" - {error}")
|
|
|
|
if result["warnings"]:
|
|
print("警告信息:")
|
|
for warning in result["warnings"]:
|
|
print(f" - {warning}")
|
|
|
|
if img_path and result["valid"]:
|
|
print("\n显示可视化结果...")
|
|
visualize_seg_label(img_path, label_path)
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("使用方法: python test_seg_label.py <label_file> [image_file]")
|
|
print("\n示例:")
|
|
print(" python test_seg_label.py datasets/搭电设备/train/labels/your_file.txt")
|
|
print(" python test_seg_label.py datasets/搭电设备/train/labels/your_file.txt datasets/搭电设备/train/images/your_file.jpg")
|
|
sys.exit(1)
|
|
|
|
label_path = sys.argv[1]
|
|
img_path = sys.argv[2] if len(sys.argv) > 2 else None
|
|
|
|
test_label_file(label_path, img_path)
|
|
|