feat: 增加点云显示和打包下载功能
This commit is contained in:
54
cam_web.py
54
cam_web.py
@@ -255,6 +255,10 @@ def export_images_api():
|
||||
zipf.write(left_export_path, os.path.join('left', left_export_fn))
|
||||
if os.path.exists(right_export_path):
|
||||
zipf.write(right_export_path, os.path.join('right', right_export_fn))
|
||||
pcd_img_path = os.path.join('static', 'received', 'pcd_img', 'pointcloud.png')
|
||||
if os.path.exists(pcd_img_path):
|
||||
zipf.write(pcd_img_path, os.path.join('pcd_img', 'pointcloud.png'))
|
||||
|
||||
|
||||
logger.info(f"Exported {len(rows)} image pairs to {temp_zip_path}")
|
||||
return send_file(temp_zip_path, as_attachment=True, download_name='exported_images.zip')
|
||||
@@ -515,6 +519,56 @@ def simple_view():
|
||||
"""查看图片列表页面"""
|
||||
return render_template('view.html')
|
||||
|
||||
@app.route('/view_pcd')
|
||||
@auth.login_required
|
||||
def pointcloud_viewer():
|
||||
logger.info(f"User {auth.current_user()} accessed the point cloud viewer page.")
|
||||
return render_template('view_pcd.html')
|
||||
|
||||
@app.route('/api/pcd_files', methods=['GET'])
|
||||
@auth.login_required
|
||||
def get_pcd_files():
|
||||
logger.info(f"User {auth.current_user()} requested PCD file list.")
|
||||
pcd_dir = os.path.join(app.static_folder, 'pcd')
|
||||
try:
|
||||
pcd_files = [f for f in os.listdir(pcd_dir) if f.lower().endswith('.pcd')]
|
||||
pcd_files.sort()
|
||||
logger.info(f"Found {len(pcd_files)} PCD files in {pcd_dir}.")
|
||||
return jsonify(pcd_files)
|
||||
except FileNotFoundError:
|
||||
logger.warning(f"PCD directory {pcd_dir} does not exist.")
|
||||
return jsonify([])
|
||||
except Exception as e:
|
||||
logger.error(f"Error listing PCD files: {e}")
|
||||
return jsonify({"error": "Failed to list PCD files"}), 500
|
||||
|
||||
@app.route('/api/load_pcd_stream/<filename>', methods=['GET'])
|
||||
@auth.login_required
|
||||
def load_pcd_stream(filename):
|
||||
if '..' in filename or filename.startswith('/'):
|
||||
logger.warning(f"Invalid filename requested: {filename}")
|
||||
return jsonify({"error": "Invalid filename"}), 400
|
||||
|
||||
import os
|
||||
pcd_dir = os.path.join(app.static_folder, 'pcd')
|
||||
requested_path = os.path.abspath(os.path.join(pcd_dir, filename))
|
||||
base_dir = os.path.abspath(pcd_dir)
|
||||
|
||||
if not requested_path.startswith(base_dir + os.sep):
|
||||
logger.warning(f"Attempted path traversal with filename: {filename}")
|
||||
return jsonify({"error": "Invalid filename"}), 400
|
||||
|
||||
if not os.path.exists(requested_path):
|
||||
logger.error(f"PCD file not found: {requested_path}")
|
||||
return jsonify({"error": "File not found"}), 404
|
||||
|
||||
return send_file(
|
||||
requested_path,
|
||||
mimetype='application/octet-stream',
|
||||
as_attachment=False,
|
||||
download_name=filename
|
||||
)
|
||||
|
||||
# --- SocketIO 事件处理程序 ---
|
||||
@socketio.event
|
||||
def connect():
|
||||
|
||||
Reference in New Issue
Block a user