cad area update con autocontorno
This commit is contained in:
+40
-1
@@ -3,6 +3,7 @@ from flask_cors import CORS
|
||||
import traceback
|
||||
|
||||
from cad_vector_area import calculate_pdf_vector_area
|
||||
from auto_contour import propose_contour_from_image_bytes
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
@@ -110,9 +111,47 @@ def calculate():
|
||||
}), 500
|
||||
|
||||
|
||||
@app.route("/auto-contour-image", methods=["POST"])
|
||||
def auto_contour_image():
|
||||
try:
|
||||
if "image" not in request.files:
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"message": "No image received"
|
||||
}), 400
|
||||
|
||||
uploaded_image = request.files["image"]
|
||||
image_bytes = uploaded_image.read()
|
||||
|
||||
max_points_raw = request.form.get("max_points", "90").strip()
|
||||
|
||||
try:
|
||||
max_points = int(max_points_raw)
|
||||
except ValueError:
|
||||
max_points = 90
|
||||
|
||||
max_points = max(12, min(max_points, 250))
|
||||
|
||||
result = propose_contour_from_image_bytes(
|
||||
image_bytes=image_bytes,
|
||||
max_points=max_points
|
||||
)
|
||||
|
||||
status_code = 200 if result.get("success") else 422
|
||||
|
||||
return jsonify(result), status_code
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"message": str(e),
|
||||
"trace": traceback.format_exc()
|
||||
}), 500
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(
|
||||
host="127.0.0.1",
|
||||
port=5055,
|
||||
debug=True
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user