-
Notifications
You must be signed in to change notification settings - Fork 11
/
check_images.py
91 lines (66 loc) · 2.7 KB
/
check_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import csv
import cv2
import os
import numpy as np
csv_files = ['train_labels.csv', 'test_labels.csv']
folders = ['train', 'test']
for i in range(len(folders)):
FOLDER = folders[i]
CSV_FILE = csv_files[i]
with open(CSV_FILE, 'r') as fid:
print('Checking file:', CSV_FILE, 'in folder:', FOLDER)
file = csv.reader(fid, delimiter=',')
first = True
cnt = 0
error_cnt = 0
error = False
for row in file:
if error == True:
error_cnt += 1
error = False
if first == True:
first = False
continue
cnt += 1
name, width, height, xmin, ymin, xmax, ymax = row[0], int(row[1]), int(row[2]), int(row[4]), int(row[5]), int(row[6]), int(row[7])
path = os.path.join(FOLDER, name)
img = cv2.imread(path)
if type(img) == type(None):
error = True
print('Could not read image', img)
continue
org_height, org_width = img.shape[:2]
if org_width != width:
error = True
print('Width mismatch for image: ', name, width, '!=', org_width)
if org_height != height:
error = True
print('Height mismatch for image: ', name, height, '!=', org_height)
if xmin > org_width:
error = True
print('XMIN > org_width for file', name)
if xmin <= 0:
error = True
print('XMIN < 0 for file', name)
if xmax > org_width:
error = True
print('XMAX > org_width for file', name)
if ymin > org_height:
error = True
print('YMIN > org_height for file', name)
if ymin <= 0:
error = True
print('YMIN < 0 for file', name)
if ymax > org_height:
error = True
print('YMAX > org_height for file', name)
if xmin >= xmax:
error = True
print('xmin >= xmax for file', name)
if ymin >= ymax:
error = True
print('ymin >= ymax for file', name)
if error == True:
print('Error for file: %s' % name)
print()
print('Checked %d files and realized %d errors' % (cnt, error_cnt))