This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
forked from ankush-me/SynthText
-
Notifications
You must be signed in to change notification settings - Fork 6
/
visualize_results.py
75 lines (63 loc) · 2.14 KB
/
visualize_results.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
# Author: Ankush Gupta
# Date: 2015
"""
Visualize the generated localization synthetic
data stored in h5 data-bases
"""
from __future__ import division
import os
import os.path as osp
import numpy as np
import matplotlib.pyplot as plt
import h5py
from common import *
def viz_textbb(text_im, charBB_list, wordBB, alpha=1.0):
"""
text_im : image containing text
charBB_list : list of 2x4xn_i bounding-box matrices
wordBB : 2x4xm matrix of word coordinates
"""
plt.close(1)
plt.figure(1)
plt.imshow(text_im)
#plt.hold(True)
H,W = text_im.shape[:2]
# plot the character-BB:
for i in range(len(charBB_list)):
bbs = charBB_list[i]
ni = bbs.shape[-1]
for j in range(ni):
bb = bbs[:,:,j]
bb = np.c_[bb,bb[:,0]]
plt.plot(bb[0,:], bb[1,:], 'r', alpha=alpha/2)
# plot the word-BB:
for i in range(wordBB.shape[-1]):
bb = wordBB[:,:,i]
bb = np.c_[bb,bb[:,0]]
plt.plot(bb[0,:], bb[1,:], 'g', alpha=alpha)
# visualize the indiv vertices:
vcol = ['r','g','b','k']
for j in range(4):
plt.scatter(bb[0,j],bb[1,j],color=vcol[j])
plt.gca().set_xlim([0,W-1])
plt.gca().set_ylim([H-1,0])
plt.show(block=False)
def main(db_fname):
db = h5py.File(db_fname, 'r')
dsets = sorted(db['data'].keys())
print ("total number of images : ", colorize(Color.RED, len(dsets), highlight=True))
for k in dsets:
rgb = db['data'][k][...]
charBB = db['data'][k].attrs['charBB']
wordBB = db['data'][k].attrs['wordBB']
txt = ", ".join(a.decode('utf-8') for a in db['data'][k].attrs['txt'])
viz_textbb(rgb, [charBB], wordBB)
print ("image name : ", colorize(Color.RED, k, bold=True))
print (" ** no. of chars : ", colorize(Color.YELLOW, charBB.shape[-1]))
print (" ** no. of words : ", colorize(Color.YELLOW, wordBB.shape[-1]))
print (" ** text : ", colorize(Color.GREEN, txt))
if 'q' in input("next? ('q' to exit) : "):
break
db.close()
if __name__=='__main__':
main('results/SynthText.h5')