Skip to content

Commit 9d53d5c

Browse files
author
Albert_Huang
committed
u
1 parent 3bb59ea commit 9d53d5c

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

image_pylib.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import random
88

99

10+
def safeInt(ss):
11+
return int(float(ss))
12+
1013
class BBX:
1114
def __init__(self):
1215
pass
@@ -16,17 +19,17 @@ def str2bbx(self, str):
1619

1720
self.name = chrs[0]
1821

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])
2326
self.score = float(chrs[5])
2427

2528
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)
3033

3134

3235
class IMGLIB:
@@ -38,10 +41,10 @@ def setBBXs(self, bboxs, name0):
3841
for bbox in bboxs:
3942
bbx = BBX()
4043
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])
4548
bbx.score = bbox[4]
4649
self.bbxs.append(bbx)
4750

@@ -96,20 +99,20 @@ def resizeBBXs(self, r, x_d, y_d):
9699

97100
def resize(self, width, height, scale=1.0):
98101
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)
101104

102105
o_ratio = o_width / float(o_height)
103106
n_ratio = width / float(height)
104107

105108
if o_ratio > n_ratio:
106109
re_ration = t_width / float(o_width)
107-
a_height = int(re_ration * o_height)
110+
a_height = safeInt(re_ration * o_height)
108111
a_width = t_width
109112
self.img = self.img.resize((a_width, a_height), Image.ANTIALIAS)
110113
else:
111114
re_ration = t_height / float(o_height)
112-
a_width = int(re_ration * o_width)
115+
a_width = safeInt(re_ration * o_width)
113116
a_height = t_height
114117
self.img = self.img.resize((a_width, a_height), Image.ANTIALIAS)
115118

0 commit comments

Comments
 (0)