freealise commited on
Commit
1e09d51
1 Parent(s): cc93339

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -24,6 +24,7 @@ from moviepy.editor import *
24
  edge = []
25
  gradient = None
26
  params = { "fnum":0, "l":16 }
 
27
  frame_selected = 0
28
  frames = []
29
  depths = []
@@ -370,6 +371,7 @@ def show_json(txt):
370
 
371
 
372
  def select_frame(v, evt: gr.SelectData):
 
373
  global frame_selected
374
  global masks
375
  global edge
@@ -379,7 +381,7 @@ def select_frame(v, evt: gr.SelectData):
379
  frame_selected = evt.index
380
  edge = []
381
 
382
- return masks[frame_selected], frame_selected
383
 
384
  def switch_rows(v):
385
  global frames
@@ -392,6 +394,8 @@ def switch_rows(v):
392
  return frames
393
 
394
  def optimize(v, d):
 
 
395
  global frames
396
  global depths
397
 
@@ -411,17 +415,17 @@ def optimize(v, d):
411
  frame = cv2.imread(frames[k]).astype(np.uint8)
412
  frame = cv2.convertScaleAbs(palette[frame]).astype(np.uint8) # Converting image back to uint
413
  cv2.imwrite(frames[k], frame)
414
- dcolor = bincount(frame)
415
- print(dcolor)
416
  depth = cv2.imread(depths[k]).astype(np.uint8)
417
- mask = cv2.inRange(frame, np.array([dcolor[0]-8, dcolor[1]-8, dcolor[2]-8]), np.array([dcolor[0]+8, dcolor[1]+8, dcolor[2]+8]))
418
  depth[mask>0] = (255,255,255)
419
  cv2.imwrite(depths[k], depth)
420
 
421
  if d == False:
422
- return frames, dcolor
423
  else:
424
- return depths, dcolor
425
 
426
  def bincount(a):
427
  a2D = a.reshape(-1,a.shape[-1])
@@ -931,7 +935,7 @@ with gr.Blocks(css=css, js=js) as demo:
931
  <a id='move' href='#'>move</a> <a id='rotate' href='#'>rotate</a> <a id='scale' href='#'>scale</a>
932
  </pre>""")
933
  selected = gr.Number(elem_id="fnum", value=0, minimum=0, maximum=256, interactive=False)
934
- output_frame.select(fn=select_frame, inputs=[output_mask], outputs=[output_mask, selected])
935
  example_coords = """[
936
  {"lat": 50.07379596793083, "lng": 14.437146122950555, "heading": 152.70303, "pitch": 2.607833999999997},
937
  {"lat": 50.073799567020004, "lng": 14.437146774240507, "heading": 151.12973, "pitch": 2.8672300000000064},
 
24
  edge = []
25
  gradient = None
26
  params = { "fnum":0, "l":16 }
27
+ dcolor = []
28
  frame_selected = 0
29
  frames = []
30
  depths = []
 
371
 
372
 
373
  def select_frame(v, evt: gr.SelectData):
374
+ global dcolor
375
  global frame_selected
376
  global masks
377
  global edge
 
381
  frame_selected = evt.index
382
  edge = []
383
 
384
+ return masks[frame_selected], frame_selected, dcolor[frame_selected]
385
 
386
  def switch_rows(v):
387
  global frames
 
394
  return frames
395
 
396
  def optimize(v, d):
397
+ global dcolor
398
+ global frame_selected
399
  global frames
400
  global depths
401
 
 
415
  frame = cv2.imread(frames[k]).astype(np.uint8)
416
  frame = cv2.convertScaleAbs(palette[frame]).astype(np.uint8) # Converting image back to uint
417
  cv2.imwrite(frames[k], frame)
418
+ dcolor[k] = bincount(frame)
419
+ print(dcolor[k])
420
  depth = cv2.imread(depths[k]).astype(np.uint8)
421
+ mask = cv2.inRange(frame, np.array([dcolor[k][0]-8, dcolor[k][1]-8, dcolor[k][2]-8]), np.array([dcolor[k][0]+8, dcolor[k][1]+8, dcolor[k][2]+8]))
422
  depth[mask>0] = (255,255,255)
423
  cv2.imwrite(depths[k], depth)
424
 
425
  if d == False:
426
+ return frames, dcolor[frame_selected]
427
  else:
428
+ return depths, dcolor[frame_selected]
429
 
430
  def bincount(a):
431
  a2D = a.reshape(-1,a.shape[-1])
 
935
  <a id='move' href='#'>move</a> <a id='rotate' href='#'>rotate</a> <a id='scale' href='#'>scale</a>
936
  </pre>""")
937
  selected = gr.Number(elem_id="fnum", value=0, minimum=0, maximum=256, interactive=False)
938
+ output_frame.select(fn=select_frame, inputs=[output_mask], outputs=[output_mask, selected, bgcolor])
939
  example_coords = """[
940
  {"lat": 50.07379596793083, "lng": 14.437146122950555, "heading": 152.70303, "pitch": 2.607833999999997},
941
  {"lat": 50.073799567020004, "lng": 14.437146774240507, "heading": 151.12973, "pitch": 2.8672300000000064},