florislindeman commited on
Commit
471898c
·
verified ·
1 Parent(s): 78b0997

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -7
app.py CHANGED
@@ -351,17 +351,46 @@ async def process_manual(
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
 
@@ -376,9 +405,10 @@ async def process_manual(
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
 
 
351
  interior_cv = pil_to_cv2(interior_pil)
352
  pattern_cv = pil_to_cv2(pattern_pil)
353
 
354
+ # Parse manual corners from JSON string
355
+ try:
356
+ corners_data = json.loads(manual_corners)
357
+ except:
358
+ # If already parsed, use as is
359
+ corners_data = manual_corners
360
+
361
+ # Convert to numpy array - handle both formats
362
+ if isinstance(corners_data, str):
363
+ corners_data = json.loads(corners_data)
364
+
365
+ # Ensure it's a list of [x, y] coordinates
366
+ corners_list = []
367
+ for corner in corners_data:
368
+ if isinstance(corner, (list, tuple)) and len(corner) == 2:
369
+ corners_list.append([float(corner[0]), float(corner[1])])
370
+ else:
371
+ raise ValueError(f"Invalid corner format: {corner}")
372
+
373
+ if len(corners_list) != 4:
374
  return {
375
  "success": False,
376
+ "error": f"Exact 4 hoeken vereist, maar {len(corners_list)} ontvangen",
377
  "num_surfaces": 0
378
  }
379
 
380
+ corners = np.array(corners_list, dtype=np.float32)
381
+
382
+ # Scale corners to match image dimensions if needed
383
+ img_h, img_w = interior_cv.shape[:2]
384
+
385
+ # Check if corners need scaling (if they're normalized 0-1)
386
+ max_x = max(c[0] for c in corners_list)
387
+ max_y = max(c[1] for c in corners_list)
388
+
389
+ if max_x <= 1.0 and max_y <= 1.0:
390
+ # Corners are normalized, scale to image size
391
+ corners[:, 0] *= img_w
392
+ corners[:, 1] *= img_h
393
+
394
  # Apply texture with manual corners
395
  result = mapper.apply_texture_with_perspective(interior_cv, pattern_cv, corners)
396
 
 
405
  }
406
 
407
  except Exception as e:
408
+ import traceback
409
  return {
410
  "success": False,
411
+ "error": f"Processing error: {str(e)}\nTraceback: {traceback.format_exc()}",
412
  "num_surfaces": 0
413
  }
414