darwinharianto commited on
Commit
cf53428
·
1 Parent(s): 62c744a

added total result

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -22,7 +22,7 @@ class BinPacking:
22
  self.width = width
23
  self.height = height
24
  self.pgrp = None
25
- print(image.shape)
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,7 @@ class BinPacking:
57
 
58
  max_item = int(self.width*self.height/item.area)
59
  self.pgrp = nest([item,]*max_item, self.box)
60
-
61
  return self
62
 
63
  def visualize(self):
@@ -110,7 +110,7 @@ def process(width:int, height:int, scale:float, image: np.ndarray):
110
 
111
  packer.pack()
112
  figure = packer.visualize()
113
- return figure
114
 
115
 
116
  if __name__ == "__main__":
@@ -132,7 +132,8 @@ if __name__ == "__main__":
132
  fit = gr.Button("Submit")
133
 
134
  plot_output = gr.Plot()
 
135
 
136
- fit.click(fn=process, inputs=[width, height, scale, image], outputs=plot_output)
137
 
138
  demo.launch()
 
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
 
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):
 
110
 
111
  packer.pack()
112
  figure = packer.visualize()
113
+ return [figure, packer.total]
114
 
115
 
116
  if __name__ == "__main__":
 
132
  fit = gr.Button("Submit")
133
 
134
  plot_output = gr.Plot()
135
+ total = gr.Number(label="Total")
136
 
137
+ fit.click(fn=process, inputs=[width, height, scale, image], outputs=[plot_output, total])
138
 
139
  demo.launch()