Niv Sardi commited on
Commit
05c71b4
1 Parent(s): b658b84

imtool:bb: add factor to intersect method

Browse files

Signed-off-by: Niv Sardi <xaiki@evilgiggle.com>

Files changed (1) hide show
  1. python/imtool.py +7 -5
python/imtool.py CHANGED
@@ -48,14 +48,12 @@ class BoundingBox(NamedTuple):
48
  , w=math.ceil(self.w)/w
49
  , h=math.ceil(self.h)/h)
50
 
51
- def intersect(self, f):
52
  six = self.x - f.x
53
  siy = self.y - f.y
54
  eix = six + self.w
55
  eiy = siy + self.h
56
 
57
-
58
-
59
  if six < 0:
60
  if six + self.w < 0:
61
  return None
@@ -73,7 +71,11 @@ class BoundingBox(NamedTuple):
73
  return None
74
  eiy = f.h
75
 
76
- return BoundingBox(six, siy, eix - six, eiy - siy)
 
 
 
 
77
 
78
  class Centroid(BoundingBox):
79
  def to_bounding_box(self, shape):
@@ -225,7 +227,7 @@ def crop(id, fn, logos: List[Centroid], out = './data/squares'):
225
  for l in logos:
226
  bl = l.to_bounding_box(im.shape)
227
  rim = cv2.rectangle(rim, bl.start, bl.end, logo_color, 5)
228
- p = bl.intersect(f)
229
  if p:
230
  li.append(p)
231
 
 
48
  , w=math.ceil(self.w)/w
49
  , h=math.ceil(self.h)/h)
50
 
51
+ def intersect(self, f, r: float = 0.8):
52
  six = self.x - f.x
53
  siy = self.y - f.y
54
  eix = six + self.w
55
  eiy = siy + self.h
56
 
 
 
57
  if six < 0:
58
  if six + self.w < 0:
59
  return None
 
71
  return None
72
  eiy = f.h
73
 
74
+ i = BoundingBox(six, siy, eix - six, eiy - siy)
75
+ if (i.w*i.h) < (self.w*self.h)*r:
76
+ return None
77
+
78
+ return i
79
 
80
  class Centroid(BoundingBox):
81
  def to_bounding_box(self, shape):
 
227
  for l in logos:
228
  bl = l.to_bounding_box(im.shape)
229
  rim = cv2.rectangle(rim, bl.start, bl.end, logo_color, 5)
230
+ p = bl.intersect(f, 0.5)
231
  if p:
232
  li.append(p)
233