Skip to content
Snippets Groups Projects
Commit d101463c authored by Leelow's avatar Leelow
Browse files

Add dataset and dependencies

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 144 additions and 0 deletions
import glob
import cv2
import numpy as np
FOLDER = "./fail/*.png"
THRESHOLD = 240
RES = 240
MARGIN = 20
for fname in glob.glob(FOLDER):
print(fname)
color = cv2.imread(fname, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(color, cv2.COLOR_RGB2GRAY)
topY = -1
topX = -1
bottomY = -1
bottomX = -1
leftY = -1
leftX = -1
rightY = -1
rightX = -1
for y in range(MARGIN, RES - MARGIN):
for x in range(MARGIN, RES - MARGIN):
if gray[y][x] <= THRESHOLD:
bottomY = y
bottomX = x
break
if bottomY != -1:
break
for y in range(RES - MARGIN, MARGIN, -1):
for x in range(MARGIN, RES - MARGIN):
if gray[y][x] <= THRESHOLD:
topY = y
topX = x
break
if topY != -1:
break
for x in range(RES - MARGIN, MARGIN, -1):
for y in range(MARGIN, RES - MARGIN):
if gray[y][x] <= THRESHOLD:
rightY = y
rightX = x
break
if rightY != -1:
break
for x in range(MARGIN, RES - MARGIN):
for y in range(MARGIN, RES - MARGIN):
if gray[y][x] <= THRESHOLD:
leftY = y
leftX = x
break
if leftY != -1:
break
cropped = color[bottomY:topY, leftX:rightX]
height, width, _ = cropped.shape
x_offset = 0
y_offset = 0
if width>height:
img = np.full((width,width,3), 255)
y_offset = round((width - height) / 2)
img[y_offset:y_offset+cropped.shape[0], x_offset:x_offset+cropped.shape[1]] = cropped
cv2.imwrite(fname, img)
else:
img = np.full((height,height,3), 255)
x_offset = round((height - width) / 2)
img[y_offset:y_offset+cropped.shape[0], x_offset:x_offset+cropped.shape[1]] = cropped
cv2.imwrite(fname, img)
\ No newline at end of file
import glob
import shutil
SRC = "NicIconExtracted/"
DEST = "split/"
FILTER = "*.png"
CLASS_NAMES = ["accident", "bomb", "car", "casualty", "electricity", "fire", "firebrigade", "flood", "gaz", "injury", "paramedics", "person", "police", "roadblock"]
filenames = [[] for _ in range(14)]
for fname in glob.glob(SRC + FILTER):
label_string = fname[fname.find("\\")+1:fname.find("_")]
label_index = CLASS_NAMES.index(label_string)
fname_ext = fname[fname.find("\\")+1:]
fname_noext = fname_ext[:fname_ext.find(".")]
filenames[label_index].append(fname_noext)
for classList in filenames:
for fIndex in range(0, round(len(classList) / 3)):
shutil.move(SRC + classList[fIndex] + ".png", DEST + classList[fIndex] + ".png")
shutil.move(SRC + classList[fIndex] + ".txt", DEST + classList[fIndex] + ".txt")
\ No newline at end of file
dataset/NicIconExtracted/tav/accident_011_10_4_2.png

10 KiB

label accident
form 01110
scripter 011
page 10
row 4
column 2
dataset/NicIconExtracted/tav/accident_011_10_4_3.png

8.77 KiB

label accident
form 01110
scripter 011
page 10
row 4
column 3
dataset/NicIconExtracted/tav/accident_011_10_4_4.png

8.55 KiB

label accident
form 01110
scripter 011
page 10
row 4
column 4
dataset/NicIconExtracted/tav/accident_011_14_6_0.png

6.15 KiB

label accident
form 01114
scripter 011
page 14
row 6
column 0
dataset/NicIconExtracted/tav/accident_011_14_6_1.png

7.14 KiB

label accident
form 01114
scripter 011
page 14
row 6
column 1
dataset/NicIconExtracted/tav/accident_011_14_6_2.png

6.2 KiB

label accident
form 01114
scripter 011
page 14
row 6
column 2
dataset/NicIconExtracted/tav/accident_011_14_6_3.png

7.27 KiB

label accident
form 01114
scripter 011
page 14
row 6
column 3
dataset/NicIconExtracted/tav/accident_011_14_6_4.png

7.18 KiB

label accident
form 01114
scripter 011
page 14
row 6
column 4
dataset/NicIconExtracted/tav/accident_011_20_1_0.png

9.05 KiB

label accident
form 01120
scripter 011
page 20
row 1
column 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment