Added LFS
Browse files- examples/0d4e4df2-7b69-91b1-1985-c8421f2f3253.jpg +3 -0
- examples/18cef191-74ed-2b5e-55a5-f58bd3d483ff.jpg +3 -0
- examples/1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg +3 -0
- examples/1d3c85e9-ee24-f290-e7e1-6e338f2eaebb.jpg +3 -0
- examples/3e043302-af1c-75a7-4057-3a2f25c123bf.jpg +3 -0
- examples/43ecc08d-502a-7a51-9d68-3e40a76439a2.jpg +3 -0
- examples/479058af-e774-e6aa-a2b0-9a42dd6ff8b1.jpg +3 -0
- examples/7c910b87-ae3a-f580-d431-03cd89793803.jpg +3 -0
- examples/8fa04489-cd94-7d8f-7e2e-5f0fe2f7ae76.jpg +3 -0
- examples/bb7b4345-b98a-c727-4c94-6090f0aa4355.jpg +3 -0
- tests/test_tile.py +89 -0
examples/0d4e4df2-7b69-91b1-1985-c8421f2f3253.jpg
ADDED
|
Git LFS Details
|
examples/18cef191-74ed-2b5e-55a5-f58bd3d483ff.jpg
ADDED
|
Git LFS Details
|
examples/1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg
ADDED
|
Git LFS Details
|
examples/1d3c85e9-ee24-f290-e7e1-6e338f2eaebb.jpg
ADDED
|
Git LFS Details
|
examples/3e043302-af1c-75a7-4057-3a2f25c123bf.jpg
ADDED
|
Git LFS Details
|
examples/43ecc08d-502a-7a51-9d68-3e40a76439a2.jpg
ADDED
|
Git LFS Details
|
examples/479058af-e774-e6aa-a2b0-9a42dd6ff8b1.jpg
ADDED
|
Git LFS Details
|
examples/7c910b87-ae3a-f580-d431-03cd89793803.jpg
ADDED
|
Git LFS Details
|
examples/8fa04489-cd94-7d8f-7e2e-5f0fe2f7ae76.jpg
ADDED
|
Git LFS Details
|
examples/bb7b4345-b98a-c727-4c94-6090f0aa4355.jpg
ADDED
|
Git LFS Details
|
tests/test_tile.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from os.path import abspath, exists, join, relpath
|
| 3 |
+
|
| 4 |
+
import cv2
|
| 5 |
+
import numpy as np
|
| 6 |
+
import utool as ut
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_tile_grid():
|
| 10 |
+
from scoutbot.tile import TILE_WIDTH, tile_grid
|
| 11 |
+
|
| 12 |
+
img_filepath = abspath(join('examples', '1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'))
|
| 13 |
+
assert exists(img_filepath)
|
| 14 |
+
img = cv2.imread(img_filepath)
|
| 15 |
+
|
| 16 |
+
assert img.shape == (4000, 6016, 3)
|
| 17 |
+
|
| 18 |
+
grid1 = tile_grid(img.shape)
|
| 19 |
+
grid2 = tile_grid(img.shape, offset=TILE_WIDTH // 2, borders=False)
|
| 20 |
+
grid = grid1 + grid2
|
| 21 |
+
|
| 22 |
+
assert len(grid1) == 682
|
| 23 |
+
assert len(grid2) == 570
|
| 24 |
+
assert len(set(map(str, grid))) == len(grid)
|
| 25 |
+
|
| 26 |
+
assert grid1[0] == {'x': 0, 'y': 0, 'w': 256, 'h': 256, 'b': True}
|
| 27 |
+
assert grid2[0] == {'x': 128, 'y': 176, 'w': 256, 'h': 256, 'b': False}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_tile_filepath():
|
| 31 |
+
from scoutbot.tile import tile_filepath
|
| 32 |
+
|
| 33 |
+
img_filepath = abspath(join('examples', '1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'))
|
| 34 |
+
assert exists(img_filepath)
|
| 35 |
+
|
| 36 |
+
grid = {'x': 0, 'y': 0, 'w': 256, 'h': 256, 'b': True}
|
| 37 |
+
|
| 38 |
+
filepath = tile_filepath(img_filepath, grid)
|
| 39 |
+
filepath = relpath(filepath)
|
| 40 |
+
assert filepath == join(
|
| 41 |
+
'examples', '1be4d40a-6fd0-42ce-da6c-294e45781f41_x_0_y_0_w_256_h_256.jpg'
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
if exists(filepath):
|
| 45 |
+
ut.delete(filepath, verbose=False)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def test_tile_write():
|
| 49 |
+
from scoutbot.tile import tile_filepath, tile_write
|
| 50 |
+
|
| 51 |
+
img_filepath = abspath(join('examples', '1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'))
|
| 52 |
+
assert exists(img_filepath)
|
| 53 |
+
img = cv2.imread(img_filepath)
|
| 54 |
+
|
| 55 |
+
grid = {'x': 0, 'y': 0, 'w': 256, 'h': 256, 'b': True}
|
| 56 |
+
filepath = tile_filepath(img_filepath, grid, ext='.png') # Use lossless here
|
| 57 |
+
assert tile_write(img, grid, filepath)
|
| 58 |
+
|
| 59 |
+
assert exists(filepath)
|
| 60 |
+
tile_img = cv2.imread(filepath)
|
| 61 |
+
|
| 62 |
+
x0 = grid.get('x')
|
| 63 |
+
y0 = grid.get('y')
|
| 64 |
+
w = grid.get('w')
|
| 65 |
+
h = grid.get('h')
|
| 66 |
+
y1 = y0 + h
|
| 67 |
+
x1 = x0 + w
|
| 68 |
+
tile = img[y0:y1, x0:x1]
|
| 69 |
+
|
| 70 |
+
assert tile_img.shape == (256, 256, 3)
|
| 71 |
+
assert tile.shape == (256, 256, 3)
|
| 72 |
+
|
| 73 |
+
tile = tile.astype(np.float32)
|
| 74 |
+
tile_img = tile_img.astype(np.float32)
|
| 75 |
+
|
| 76 |
+
assert np.all(np.abs(tile - tile_img) <= 0)
|
| 77 |
+
ut.delete(filepath, verbose=False)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_tile_compute():
|
| 81 |
+
from scoutbot.tile import compute
|
| 82 |
+
|
| 83 |
+
img_filepath = abspath(join('examples', '1be4d40a-6fd0-42ce-da6c-294e45781f41.jpg'))
|
| 84 |
+
filepaths = compute(img_filepath)
|
| 85 |
+
|
| 86 |
+
assert len(filepaths) == 1252
|
| 87 |
+
for filepath in filepaths:
|
| 88 |
+
assert exists(filepath)
|
| 89 |
+
ut.delete(filepath, verbose=False)
|