darwinharianto commited on
Commit
59a5e68
·
1 Parent(s): a75ebd2

removed negative values, and fixed error

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -22,7 +22,7 @@ class BinPacking:
22
  self.width = width
23
  self.height = height
24
  self.pgrp = None
25
- self.total = None
26
  self.image = cv2.resize(image, (int(image.shape[1]*imageScale), int(image.shape[0]*imageScale)))
27
  if self.image.shape[2] == 4:
28
  x,y = np.where(self.image[:,:,3]==0)
@@ -57,7 +57,10 @@ class BinPacking:
57
 
58
  max_item = int(self.width*self.height/item.area)
59
  self.pgrp = nest([item,]*max_item, self.box)
60
- self.total = len(self.pgrp[0])
 
 
 
61
  return self
62
 
63
  def visualize(self):
@@ -75,7 +78,7 @@ class BinPacking:
75
  ),
76
  paper_bgcolor="LightSteelBlue",
77
  )
78
- if self.pgrp == None:
79
  return fig
80
 
81
  _, thresh = cv2.threshold(self.imgray, 127, 255, 0)
@@ -137,7 +140,7 @@ if __name__ == "__main__":
137
 
138
  with gr.Column():
139
  plot_output = gr.Plot()
140
- text = gr.Text()
141
 
142
  fit.click(fn=process, inputs=[width, height, scale, image], outputs=[plot_output, text])
143
 
 
22
  self.width = width
23
  self.height = height
24
  self.pgrp = None
25
+ self.total = 0
26
  self.image = cv2.resize(image, (int(image.shape[1]*imageScale), int(image.shape[0]*imageScale)))
27
  if self.image.shape[2] == 4:
28
  x,y = np.where(self.image[:,:,3]==0)
 
57
 
58
  max_item = int(self.width*self.height/item.area)
59
  self.pgrp = nest([item,]*max_item, self.box)
60
+ if self.pgrp is None or len(self.pgrp) == 0:
61
+ self.total = 0
62
+ else:
63
+ self.total = len(self.pgrp[0])
64
  return self
65
 
66
  def visualize(self):
 
78
  ),
79
  paper_bgcolor="LightSteelBlue",
80
  )
81
+ if self.pgrp == None or len(self.pgrp) == 0:
82
  return fig
83
 
84
  _, thresh = cv2.threshold(self.imgray, 127, 255, 0)
 
140
 
141
  with gr.Column():
142
  plot_output = gr.Plot()
143
+ text = gr.Text(label="Message")
144
 
145
  fit.click(fn=process, inputs=[width, height, scale, image], outputs=[plot_output, text])
146