scan, split, OCR, prepare for LLM
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from __future__ import annotations
  2. from src.split.slicer import detect_grid
  3. from tests.helpers import create_test_image
  4. class TestDetectGrid:
  5. def test_2x2(self) -> None:
  6. image = create_test_image(400, 300)
  7. image[:, :] = (255, 255, 255)
  8. dark = (0, 0, 0)
  9. gap = 20
  10. bw = (400 - 3 * gap) // 2
  11. bh = (300 - 3 * gap) // 2
  12. for r in range(2):
  13. for c in range(2):
  14. y = gap + r * (bh + gap)
  15. x = gap + c * (bw + gap)
  16. image[y : y + bh, x : x + bw] = dark
  17. cols, rows = detect_grid(image)
  18. assert cols == 2
  19. assert rows == 2
  20. def test_2x4(self) -> None:
  21. image = create_test_image(800, 400)
  22. image[:, :] = (255, 255, 255)
  23. gap = 15
  24. bw = (800 - 5 * gap) // 4
  25. bh = (400 - 3 * gap) // 2
  26. dark = (0, 0, 0)
  27. for r in range(2):
  28. for c in range(4):
  29. y = gap + r * (bh + gap)
  30. x = gap + c * (bw + gap)
  31. image[y : y + bh, x : x + bw] = dark
  32. cols, rows = detect_grid(image)
  33. assert cols == 4
  34. assert rows == 2
  35. def test_1x1(self) -> None:
  36. image = create_test_image(200, 200)
  37. image[:, :] = (255, 255, 255)
  38. image[20:180, 20:180] = (0, 0, 0)
  39. cols, rows = detect_grid(image)
  40. assert cols == 1
  41. assert rows == 1
  42. def test_3x3(self) -> None:
  43. image = create_test_image(600, 450)
  44. image[:, :] = (255, 255, 255)
  45. dark = (0, 0, 0)
  46. gap = 10
  47. bw = (600 - 4 * gap) // 3
  48. bh = (450 - 4 * gap) // 3
  49. for r in range(3):
  50. for c in range(3):
  51. y = gap + r * (bh + gap)
  52. x = gap + c * (bw + gap)
  53. image[y : y + bh, x : x + bw] = dark
  54. cols, rows = detect_grid(image)
  55. assert cols == 3
  56. assert rows == 3
  57. def test_uniform_image(self) -> None:
  58. image = create_test_image()
  59. cols, rows = detect_grid(image)
  60. assert cols == 1
  61. assert rows == 1