fallback_analysis.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import matplotlib.pyplot as plt
  2. import matplotlib.patches as patches
  3. import numpy as np
  4. fig, ax = plt.subplots(figsize=(11, 9))
  5. fig.patch.set_facecolor('#1a1a2e')
  6. ax.set_facecolor('#1a1a2e')
  7. ax.set_xlim(490, 560)
  8. ax.set_ylim(380, 590)
  9. ax.set_aspect('equal')
  10. ax.invert_yaxis()
  11. plt.tight_layout()
  12. # Colors
  13. BBOX_COLOR = '#4a90d9'
  14. WALL_COLOR = '#e94560'
  15. INT_COLOR = '#50fa7b'
  16. EXP_COLOR = '#f1fa8c'
  17. EP_COLOR = '#ff79c6'
  18. OTHER = '#555'
  19. # Other walls
  20. other_segs = [
  21. [[420,266],[420,360]], [[420,360],[537,360]], [[537,360],[537,266]],
  22. [[458,424],[509,424]], [[509,424],[698,424]], [[698,424],[698,379]],
  23. [[740,379],[740,266]], [[740,266],[560,266]], [[560,266],[560,304]],
  24. [[560,304],[537,304]], [[537,304],[537,360]], [[537,360],[458,360]],
  25. [[458,360],[458,424]],
  26. ]
  27. for s in other_segs:
  28. ax.plot([s[0][0], s[1][0]], [s[0][1], s[1][1]], color=OTHER, linewidth=1.5, alpha=0.5)
  29. # Target segment
  30. ax.plot([521, 521], [424, 575], color=WALL_COLOR, linewidth=3, label='Wall seg50 (x=521, y=424->575)')
  31. # Door bbox
  32. rect = patches.Rectangle((515, 399), 12, 38, linewidth=2, edgecolor=BBOX_COLOR, facecolor=(0.29, 0.56, 0.85, 0.2), label='Door bbox (12x38px)')
  33. ax.add_patch(rect)
  34. # Expand +10px
  35. rect_exp = patches.Rectangle((505, 389), 32, 58, linewidth=1.5, edgecolor=EXP_COLOR, facecolor=(0.945, 0.98, 0.545, 0.08), linestyle='--', label='expand +10px')
  36. ax.add_patch(rect_exp)
  37. # Intersection
  38. ax.plot(521, 437, 'o', markersize=10, color=INT_COLOR, label='Intersection (only 1)')
  39. ax.annotate('(x=521, y=437)', xy=(521, 437), xytext=(540, 445),
  40. fontsize=10, color=INT_COLOR,
  41. arrowprops=dict(arrowstyle='->', color=INT_COLOR))
  42. # Endpoint
  43. ax.plot(521, 424, 'o', markersize=10, color=EP_COLOR, label='Seg endpoint (inside bbox)')
  44. ax.annotate('(x=521, y=424)', xy=(521, 424), xytext=(540, 418),
  45. fontsize=10, color=EP_COLOR,
  46. arrowprops=dict(arrowstyle='->', color=EP_COLOR))
  47. # Arrow from endpoint to bottom edge
  48. ax.annotate('', xy=(521, 437), xytext=(521, 424),
  49. arrowprops=dict(arrowstyle='<->', color=EP_COLOR, lw=1.5))
  50. ax.text(503, 430, '13px\ngap', fontsize=9, color=EP_COLOR, ha='center', va='center')
  51. # Dimension labels
  52. ax.plot([513, 513], [399, 437], color=EXP_COLOR, linewidth=1)
  53. ax.text(510, 418, '38px', fontsize=9, color=EXP_COLOR, ha='center', va='center', rotation=90)
  54. ax.plot([515, 527], [440, 440], color=EXP_COLOR, linewidth=1)
  55. ax.text(521, 445, '12px', fontsize=9, color=EXP_COLOR, ha='center', va='top')
  56. ax.text(521, 394, 'top edge y=399', fontsize=9, color=BBOX_COLOR, ha='center')
  57. ax.text(521, 456, 'bottom edge y=437', fontsize=9, color=BBOX_COLOR, ha='center')
  58. # Wall annotation
  59. ax.text(518, 560, 'Seg enters bbox\nfrom top edge\nendpoint stops at\ny=424 (inside)', fontsize=9, color=WALL_COLOR, ha='right', va='bottom',
  60. bbox=dict(boxstyle='round,pad=0.3', facecolor=(0.914, 0.271, 0.376, 0.1), edgecolor=WALL_COLOR))
  61. # Summary
  62. summary = (
  63. 'Door 21: Projection Fallback Case\n\n'
  64. 'Wall enters bbox from top, endpoint inside bbox\n'
  65. 'Intersection detection: only 1 point\n'
  66. 'expand +10px: still only 1 point\n\n'
  67. 'Result: falls back to projection\n'
  68. ' - Project door center to wall\n'
  69. ' - Use bbox long edge = 38px = 0.76m\n'
  70. ' - Generate door line along wall direction\n\n'
  71. 'This is correct fallback behavior, door size is OK'
  72. )
  73. ax.text(0.5, 0.02, summary, transform=ax.transAxes, fontsize=10,
  74. color='#e0e0e0', ha='center', va='bottom',
  75. bbox=dict(boxstyle='round,pad=0.5', facecolor=(0.29, 0.56, 0.85, 0.1), edgecolor='#4a90d9'))
  76. ax.set_title('Door 21: Segment Endpoint Inside Bbox -> Projection Fallback', fontsize=14, color='#e94560', pad=20)
  77. ax.legend(loc='upper right', fontsize=9, facecolor='#1a1a2e', edgecolor='#555')
  78. plt.savefig('/media/dage/KESU/temp/floorplan/fallback_analysis.png', dpi=150, bbox_inches='tight',
  79. facecolor='#1a1a2e', edgecolor='none')
  80. plt.close()
  81. print('Saved to fallback_analysis.png')