You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB
Python

8 months ago
# 这是一个示例 Python 脚本。
# 按 Shift+F10 执行或将其替换为您的代码。
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。
import SimpleView_SaveImage as simple
import config
from Point import tiff_depth_to_point_clouds
from flask import Flask, jsonify, request
app = Flask(__name__)
# 示例接口GET 请求
@app.route("/config/update")
def home():
config.load_configs()
return "Hello, this service config update!"
# 示例接口:返回 JSON 数据
@app.route("/api/data")
def get_data():
data = {"message": "This is some data", "status": "OK"}
return jsonify(data)
# 示例接口:接收参数
# 示例接口:接收参数
@app.route("/api/compute/<direction>")
def compute(direction):
try:
sn = config.DIRECTION_CAMERA[direction]
except KeyError:
return jsonify({"message": "", "status": "ERROR", "error": f"Direction '{direction}' not found in DIRECTION_CAMERA"}), 400
try:
tiff_paths = simple.pic(sn)
except Exception as e:
return jsonify({"message": "", "status": "ERROR", "error": f"Failed to get TIFF paths: {str(e)}"}), 500
try:
rest = tiff_depth_to_point_clouds(tiff_paths, sn, dedup=True)
except Exception as e:
return jsonify({"message": "", "status": "ERROR", "error": f"Point cloud processing failed: {str(e)}"}), 500
print(rest)
return jsonify({"message": rest, "status": "OK"})
@app.errorhandler(Exception)
def handle_exception(e):
# 处理所有未被捕获的异常
return jsonify({
"message": "",
"status": "ERROR",
"error": str(e)
}), 500
if __name__ == "__main__":
from waitress import serve
print("Serving on http://0.0.0.0:5000")
serve(app, host='0.0.0.0', port=5000)