Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -333,6 +333,55 @@ async def process_complete(
|
|
| 333 |
"num_surfaces": 0
|
| 334 |
}
|
| 335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
if __name__ == "__main__":
|
| 337 |
import uvicorn
|
| 338 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 333 |
"num_surfaces": 0
|
| 334 |
}
|
| 335 |
|
| 336 |
+
@app.post("/api/process-manual")
|
| 337 |
+
async def process_manual(
|
| 338 |
+
interior: UploadFile = File(...),
|
| 339 |
+
pattern: UploadFile = File(...),
|
| 340 |
+
manual_corners: str = Form(...)
|
| 341 |
+
):
|
| 342 |
+
"""
|
| 343 |
+
Process with manually selected corners
|
| 344 |
+
"""
|
| 345 |
+
try:
|
| 346 |
+
import json
|
| 347 |
+
|
| 348 |
+
interior_pil = Image.open(interior.file)
|
| 349 |
+
pattern_pil = Image.open(pattern.file)
|
| 350 |
+
|
| 351 |
+
interior_cv = pil_to_cv2(interior_pil)
|
| 352 |
+
pattern_cv = pil_to_cv2(pattern_pil)
|
| 353 |
+
|
| 354 |
+
# Parse manual corners from JSON
|
| 355 |
+
corners_list = json.loads(manual_corners)
|
| 356 |
+
corners = np.array(corners_list, dtype=np.float32)
|
| 357 |
+
|
| 358 |
+
if len(corners) != 4:
|
| 359 |
+
return {
|
| 360 |
+
"success": False,
|
| 361 |
+
"error": "Exact 4 hoeken vereist",
|
| 362 |
+
"num_surfaces": 0
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
# Apply texture with manual corners
|
| 366 |
+
result = mapper.apply_texture_with_perspective(interior_cv, pattern_cv, corners)
|
| 367 |
+
|
| 368 |
+
# Convert to base64
|
| 369 |
+
_, result_buffer = cv2.imencode('.jpg', result, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
| 370 |
+
result_base64 = base64.b64encode(result_buffer).decode('utf-8')
|
| 371 |
+
|
| 372 |
+
return {
|
| 373 |
+
"success": True,
|
| 374 |
+
"result": f"data:image/jpeg;base64,{result_base64}",
|
| 375 |
+
"info": "Patroon toegepast met handmatige hoeken"
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
except Exception as e:
|
| 379 |
+
return {
|
| 380 |
+
"success": False,
|
| 381 |
+
"error": f"Processing error: {str(e)}",
|
| 382 |
+
"num_surfaces": 0
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
if __name__ == "__main__":
|
| 386 |
import uvicorn
|
| 387 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|