Add all untracked files and configure gitignore

This commit is contained in:
2025-12-03 13:56:23 +08:00
parent a97ca8cb7c
commit 641c8aa1f0
502 changed files with 1203 additions and 26 deletions

58
app.py
View File

@@ -23,6 +23,28 @@ def is_labeled(filename):
label_path = os.path.join(LABELS_DIR, name + '.txt')
return os.path.exists(label_path)
def get_yolo_boxes(filename):
name, _ = os.path.splitext(filename)
label_path = os.path.join(LABELS_DIR, name + '.txt')
boxes = []
if os.path.exists(label_path):
with open(label_path, 'r') as f:
for line in f:
parts = line.strip().split()
if len(parts) >= 5:
# format: class x_center y_center width height
try:
boxes.append({
'class': parts[0],
'x': float(parts[1]),
'y': float(parts[2]),
'w': float(parts[3]),
'h': float(parts[4])
})
except ValueError:
continue
return boxes
@app.route('/')
def index():
return render_template('index.html')
@@ -36,21 +58,51 @@ def get_next_image():
images = get_image_files()
total = len(images)
labeled_count = 0
next_index = None
next_image = None
for img in images:
for i, img in enumerate(images):
if is_labeled(img):
labeled_count += 1
elif next_image is None:
next_image = img
next_index = i
# If all labeled, next_image remains None
return jsonify({
'total': total,
'labeled': labeled_count,
'labeled_count': labeled_count,
'index': next_index if next_index is not None else -1,
'filename': next_image,
'completed': next_image is None
'completed': next_image is None,
'boxes': get_yolo_boxes(next_image) if next_image else []
})
@app.route('/api/image/<int:index>')
def get_image_by_index(index):
images = get_image_files()
total = len(images)
if total == 0:
return jsonify({'error': 'No images'}), 404
# Clamp index
if index < 0: index = 0
if index >= total: index = total - 1
filename = images[index]
# Calculate stats
labeled_count = sum(1 for img in images if is_labeled(img))
return jsonify({
'total': total,
'labeled_count': labeled_count,
'index': index,
'filename': filename,
'labeled': is_labeled(filename),
'boxes': get_yolo_boxes(filename)
})
@app.route('/api/save', methods=['POST'])