-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_dataset.py
More file actions
51 lines (36 loc) · 1.53 KB
/
visualize_dataset.py
File metadata and controls
51 lines (36 loc) · 1.53 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 6 18:15:11 2022
@author: Andres Fandos
Script to display the images in the dataset with their corresponding
bounding boxes around the face in the image.
"""
import os
import cv2
import json
import random
import numpy as np
if __name__ == "__main__":
images = os.listdir(os.path.join('data', 'images_resized'))
random.shuffle(images)
coords = [0, 0, 0, 0]
for image in images:
img = cv2.imread(os.path.join('data', 'images_resized', image))
if os.path.exists(os.path.join('data', 'labels', image.split('.')[0] + '.json')):
with open(os.path.join('data', 'labels', image.split('.')[0] + '.json'), 'r') as f:
label = json.load(f)
coords[0] = label['shapes'][0]['points'][0][0]
coords[1] = label['shapes'][0]['points'][0][1]
coords[2] = label['shapes'][0]['points'][1][0]
coords[3] = label['shapes'][0]['points'][1][1]
cv2.rectangle(img=img,
pt1=tuple(np.array(coords[:2]).astype(int)),
pt2=tuple(np.array(coords[2:]).astype(int)),
color=(0, 0, 255),
thickness=2)
cv2.imshow('Image', img)
key = cv2.waitKey(1000)
# Si se presiona la tecla ESC se sale del bucle
if key == 27:
break
cv2.destroyAllWindows()