7
7
import random
8
8
9
9
10
+ def safeInt (ss ):
11
+ return int (float (ss ))
12
+
10
13
class BBX :
11
14
def __init__ (self ):
12
15
pass
@@ -16,17 +19,17 @@ def str2bbx(self, str):
16
19
17
20
self .name = chrs [0 ]
18
21
19
- self .x = int (chrs [1 ])
20
- self .y = int (chrs [2 ])
21
- self .w = int (chrs [3 ])
22
- self .h = int (chrs [4 ])
22
+ self .x = safeInt (chrs [1 ])
23
+ self .y = safeInt (chrs [2 ])
24
+ self .w = safeInt (chrs [3 ])
25
+ self .h = safeInt (chrs [4 ])
23
26
self .score = float (chrs [5 ])
24
27
25
28
def resize (self , scale , x_d , y_d ):
26
- self .x = int (self .x * scale ) + x_d
27
- self .y = int (self .y * scale ) + y_d
28
- self .w = int (self .w * scale )
29
- self .h = int (self .h * scale )
29
+ self .x = safeInt (self .x * scale ) + x_d
30
+ self .y = safeInt (self .y * scale ) + y_d
31
+ self .w = safeInt (self .w * scale )
32
+ self .h = safeInt (self .h * scale )
30
33
31
34
32
35
class IMGLIB :
@@ -38,10 +41,10 @@ def setBBXs(self, bboxs, name0):
38
41
for bbox in bboxs :
39
42
bbx = BBX ()
40
43
bbx .name = name0
41
- bbx .x = int (bbox [0 ])
42
- bbx .y = int (bbox [1 ])
43
- bbx .w = int (bbox [2 ])
44
- bbx .h = int (bbox [3 ])
44
+ bbx .x = safeInt (bbox [0 ])
45
+ bbx .y = safeInt (bbox [1 ])
46
+ bbx .w = safeInt (bbox [2 ])
47
+ bbx .h = safeInt (bbox [3 ])
45
48
bbx .score = bbox [4 ]
46
49
self .bbxs .append (bbx )
47
50
@@ -96,20 +99,20 @@ def resizeBBXs(self, r, x_d, y_d):
96
99
97
100
def resize (self , width , height , scale = 1.0 ):
98
101
o_width , o_height = self .img .size
99
- t_width = int (width * scale )
100
- t_height = int (height * scale )
102
+ t_width = safeInt (width * scale )
103
+ t_height = safeInt (height * scale )
101
104
102
105
o_ratio = o_width / float (o_height )
103
106
n_ratio = width / float (height )
104
107
105
108
if o_ratio > n_ratio :
106
109
re_ration = t_width / float (o_width )
107
- a_height = int (re_ration * o_height )
110
+ a_height = safeInt (re_ration * o_height )
108
111
a_width = t_width
109
112
self .img = self .img .resize ((a_width , a_height ), Image .ANTIALIAS )
110
113
else :
111
114
re_ration = t_height / float (o_height )
112
- a_width = int (re_ration * o_width )
115
+ a_width = safeInt (re_ration * o_width )
113
116
a_height = t_height
114
117
self .img = self .img .resize ((a_width , a_height ), Image .ANTIALIAS )
115
118
0 commit comments