feat: 增加位置字段

This commit is contained in:
2025-10-27 14:37:03 +08:00
parent 551555d526
commit 75fe7dc58b
2 changed files with 97 additions and 30 deletions

View File

@@ -145,15 +145,26 @@ def get_images_api():
try:
cursor.execute("""
SELECT id, left_filename, right_filename, left_marked_filename, right_marked_filename,
timestamp, metadata, comment, created_at, manual_detections, is_manual_labeled
timestamp, metadata, comment, created_at, manual_detections, is_manual_labeled,
left_position, right_position
FROM images
ORDER BY timestamp DESC
""")
except sqlite3.OperationalError:
# 如果字段不存在,使用基本查询
try:
cursor.execute("""
SELECT id, left_filename, right_filename, left_marked_filename, right_marked_filename,
timestamp, metadata, comment, created_at, NULL as manual_detections, 0 as is_manual_labeled
timestamp, metadata, comment, created_at, manual_detections, is_manual_labeled,
0 as left_position, 0 as right_position
FROM images
ORDER BY timestamp DESC
""")
except sqlite3.OperationalError:
cursor.execute("""
SELECT id, left_filename, right_filename, left_marked_filename, right_marked_filename,
timestamp, metadata, comment, created_at, NULL as manual_detections, 0 as is_manual_labeled,
0 as left_position, 0 as right_position
FROM images
ORDER BY timestamp DESC
""")
@@ -174,7 +185,9 @@ def get_images_api():
"comment": row[7] or "", # 如果没有 comment 则显示空字符串
"created_at": row[8],
"manual_detections": row[9] or "[]", # 人工标注检测框结果
"is_manual_labeled": bool(row[10]) if row[10] is not None else False # 是否已完成人工标注
"is_manual_labeled": bool(row[10]) if row[10] is not None else False, # 是否已完成人工标注
"left_position": row[11] if row[11] is not None else 0, # 左侧位置编号
"right_position": row[12] if row[12] is not None else 0 # 右侧位置编号
})
return jsonify(images)
@@ -438,6 +451,43 @@ def update_image_comment():
return jsonify({"message": f"Comment for image {image_id} updated successfully"})
@app.route('/api/images/position', methods=['PUT'])
def update_image_position():
"""API: 更新图片的位置编号"""
data = request.json
image_id = data.get('id')
left_position = data.get('left_position', 0)
right_position = data.get('right_position', 0)
if not image_id:
return jsonify({"error": "Image ID is required"}), 400
conn = sqlite3.connect(DATABASE_PATH)
cursor = conn.cursor()
# 添加位置字段(如果不存在)
try:
cursor.execute("""
ALTER TABLE images ADD COLUMN left_position INTEGER DEFAULT 0
""")
except sqlite3.OperationalError:
pass
try:
cursor.execute("""
ALTER TABLE images ADD COLUMN right_position INTEGER DEFAULT 0
""")
except sqlite3.OperationalError:
pass
# 更新位置字段
cursor.execute("UPDATE images SET left_position = ?, right_position = ? WHERE id = ?",
(left_position, right_position, image_id))
conn.commit()
conn.close()
return jsonify({"message": f"Position for image {image_id} updated successfully"})
@app.route('/status')
def status():
with frame_lock:

View File

@@ -174,25 +174,42 @@
// Timestamp
row.insertCell(4).textContent = new Date(image.timestamp * 1000).toISOString();
// Comment
const commentCell = row.insertCell(5);
const commentInput = document.createElement('input');
commentInput.type = 'text';
commentInput.value = image.comment || '';
commentInput.dataset.id = image.id;
commentInput.className = 'comment-input';
commentInput.style.width = '100%';
commentInput.addEventListener('change', function () {
updateComment(image.id, this.value);
});
commentCell.appendChild(commentInput);
// 评论
row += `<td><input type="text" id="comment-${image.id}" value="${image.comment}" onchange="updateComment(${image.id})"></td>`;
// Actions
row.insertCell(6).innerHTML = `
<button onclick="deleteImage(${image.id})">Delete</button>
<button onclick="window.open('/manual-annotation?id=${image.id}&side=left', '_blank')">LBL</button>
<button onclick="window.open('/manual-annotation?id=${image.id}&side=right', '_blank')">LBR</button>
`;
row += `<td>
<button onclick="deleteImage(${image.id})">删除</button>
<button onclick="manualLabelLeft(${image.id})">人工标注 (左)</button>
<button onclick="manualLabelRight(${image.id})">人工标注 (右)</button>
<!-- 添加位置编号下拉框 -->
<label>左:</label>
<select id="left-position-${image.id}" onchange="updatePosition(${image.id})">
<option value="0" ${image.left_position == 0 ? 'selected' : ''}>未设置</option>
<option value="1" ${image.left_position == 1 ? 'selected' : ''}>1</option>
<option value="2" ${image.left_position == 2 ? 'selected' : ''}>2</option>
<option value="3" ${image.left_position == 3 ? 'selected' : ''}>3</option>
<option value="4" ${image.left_position == 4 ? 'selected' : ''}>4</option>
<option value="5" ${image.left_position == 5 ? 'selected' : ''}>5</option>
<option value="6" ${image.left_position == 6 ? 'selected' : ''}>6</option>
<option value="7" ${image.left_position == 7 ? 'selected' : ''}>7</option>
<option value="8" ${image.left_position == 8 ? 'selected' : ''}>8</option>
<option value="9" ${image.left_position == 9 ? 'selected' : ''}>9</option>
</select>
<label>右:</label>
<select id="right-position-${image.id}" onchange="updatePosition(${image.id})">
<option value="0" ${image.right_position == 0 ? 'selected' : ''}>未设置</option>
<option value="1" ${image.right_position == 1 ? 'selected' : ''}>1</option>
<option value="2" ${image.right_position == 2 ? 'selected' : ''}>2</option>
<option value="3" ${image.right_position == 3 ? 'selected' : ''}>3</option>
<option value="4" ${image.right_position == 4 ? 'selected' : ''}>4</option>
<option value="5" ${image.right_position == 5 ? 'selected' : ''}>5</option>
<option value="6" ${image.right_position == 6 ? 'selected' : ''}>6</option>
<option value="7" ${image.right_position == 7 ? 'selected' : ''}>7</option>
<option value="8" ${image.right_position == 8 ? 'selected' : ''}>8</option>
<option value="9" ${image.right_position == 9 ? 'selected' : ''}>9</option>
</select>
</td>`;
row += '</tr>';
});
}