Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
·
a865450
1
Parent(s):
ea75eb1
imtool: pass id, this commit actually allows to start training
Browse files- python/imtool.py +6 -4
python/imtool.py
CHANGED
|
@@ -64,7 +64,7 @@ def cut_logo(im, l):
|
|
| 64 |
(x, y, w, h) = floor_logo(l)
|
| 65 |
return im[x:w, y:h]
|
| 66 |
|
| 67 |
-
def crop(fn, logos):
|
| 68 |
basename = os.path.basename(fn).replace('.png', '')
|
| 69 |
img_out = f"./data/squares/images"
|
| 70 |
txt_out = f"./data/squares/labels"
|
|
@@ -156,7 +156,7 @@ def crop(fn, logos):
|
|
| 156 |
cx = p.w/2 + p.x
|
| 157 |
cy = p.h/2 + p.y
|
| 158 |
|
| 159 |
-
a = f"{
|
| 160 |
f.write(a)
|
| 161 |
print(a)
|
| 162 |
cv2.imwrite(f'{debug_out}/{basename}{x}{y}.debug.png', dim)
|
|
@@ -164,13 +164,15 @@ def crop(fn, logos):
|
|
| 164 |
cv2.imwrite(f'{debug_out}/{basename}.debug.png', im)
|
| 165 |
|
| 166 |
if __name__ == '__main__':
|
|
|
|
| 167 |
with os.scandir('./data/') as it:
|
| 168 |
for e in it:
|
| 169 |
if e.name.endswith('.txt') and e.is_file():
|
| 170 |
print(e.name)
|
| 171 |
try:
|
| 172 |
-
|
| 173 |
-
|
|
|
|
| 174 |
except Exception as err:
|
| 175 |
print(err)
|
| 176 |
|
|
|
|
| 64 |
(x, y, w, h) = floor_logo(l)
|
| 65 |
return im[x:w, y:h]
|
| 66 |
|
| 67 |
+
def crop(id, fn, logos):
|
| 68 |
basename = os.path.basename(fn).replace('.png', '')
|
| 69 |
img_out = f"./data/squares/images"
|
| 70 |
txt_out = f"./data/squares/labels"
|
|
|
|
| 156 |
cx = p.w/2 + p.x
|
| 157 |
cy = p.h/2 + p.y
|
| 158 |
|
| 159 |
+
a = f"{int(id)} {cx/TILE_SIZE} {cy/TILE_SIZE} {p.w/TILE_SIZE} {p.h/TILE_SIZE}\n"
|
| 160 |
f.write(a)
|
| 161 |
print(a)
|
| 162 |
cv2.imwrite(f'{debug_out}/{basename}{x}{y}.debug.png', dim)
|
|
|
|
| 164 |
cv2.imwrite(f'{debug_out}/{basename}.debug.png', im)
|
| 165 |
|
| 166 |
if __name__ == '__main__':
|
| 167 |
+
i = 0
|
| 168 |
with os.scandir('./data/') as it:
|
| 169 |
for e in it:
|
| 170 |
if e.name.endswith('.txt') and e.is_file():
|
| 171 |
print(e.name)
|
| 172 |
try:
|
| 173 |
+
i+=1
|
| 174 |
+
bco, boxes = read_bounding_boxes(e.path)
|
| 175 |
+
crop(i, e.path.replace('.txt', '.png'), boxes)
|
| 176 |
except Exception as err:
|
| 177 |
print(err)
|
| 178 |
|