freealise commited on
Commit
ecd0ae3
·
verified ·
1 Parent(s): 4487001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -4
app.py CHANGED
@@ -220,10 +220,6 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
220
  thumbnail_old = thumbnail
221
 
222
  blur_frame = blur_image(cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA), depth_color, blur_data)
223
- comb_frame = np.concatenate((blur_frame, depth_color), axis=0)
224
-
225
- cv2.imwrite(f"f{count}_comb.png", comb_frame)
226
- comb_frames.append(f"f{count}_comb.png")
227
 
228
  cv2.imwrite(f"f{count}.png", blur_frame)
229
  orig_frames.append(f"f{count}.png")
@@ -241,6 +237,16 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
241
  masks.append(f"f{count}_mask.png")
242
  count += 1
243
 
 
 
 
 
 
 
 
 
 
 
244
  final_vid = create_video(comb_frames, frame_rate, "orig")
245
 
246
  final_zip = zip_files(comb_frames, ["orig_result.vtt"])
@@ -452,6 +458,49 @@ def draw_mask(o, b, v, d, evt: gr.EventData):
452
 
453
  return gr.ImageEditor(value=d)
454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  js = """
456
  async()=>{
457
 
 
220
  thumbnail_old = thumbnail
221
 
222
  blur_frame = blur_image(cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA), depth_color, blur_data)
 
 
 
 
223
 
224
  cv2.imwrite(f"f{count}.png", blur_frame)
225
  orig_frames.append(f"f{count}.png")
 
237
  masks.append(f"f{count}_mask.png")
238
  count += 1
239
 
240
+ color_transfer(0)
241
+
242
+ j=0
243
+ while j<len(orig_frames):
244
+ comb_frame = np.concatenate(cv2.imread(orig_frames, cv2.IMREAD_UNCHANGED), cv2.imread(depth_frames, cv2.IMREAD_UNCHANGED), axis=0)
245
+
246
+ cv2.imwrite(f"f{count}_comb.png", comb_frame)
247
+ comb_frames.append(f"f{count}_comb.png")
248
+ j=j+1
249
+
250
  final_vid = create_video(comb_frames, frame_rate, "orig")
251
 
252
  final_zip = zip_files(comb_frames, ["orig_result.vtt"])
 
458
 
459
  return gr.ImageEditor(value=d)
460
 
461
+
462
+ def read_file(sn,tn):
463
+ s = cv2.imread(sn)
464
+ s = cv2.cvtColor(s,cv2.COLOR_BGRA2LAB)
465
+ t = cv2.imread(tn)
466
+ t = cv2.cvtColor(t,cv2.COLOR_BGRA2LAB)
467
+ return s, t
468
+
469
+ def get_mean_and_std(x):
470
+ x_mean, x_std = cv2.meanStdDev(x)
471
+ x_mean = np.hstack(np.around(x_mean,2))
472
+ x_std = np.hstack(np.around(x_std,2))
473
+ return x_mean, x_std
474
+
475
+ def color_transfer(base):
476
+ global frames
477
+ targets = []
478
+
479
+ for n in range(len(frames)):
480
+ targets.append(frames[base])
481
+ if n != base:
482
+ print("Converting picture "+str(n)+"...")
483
+ s, t = read_file(frames[n],targets[n])
484
+ s_mean, s_std = get_mean_and_std(s)
485
+ t_mean, t_std = get_mean_and_std(t)
486
+
487
+ height, width, channel = s.shape
488
+ for i in range(0,height):
489
+ for j in range(0,width):
490
+ for k in range(0,channel):
491
+ x = s[i,j,k]
492
+ x = ((x-s_mean[k])*(t_std[k]/s_std[k]))+t_mean[k]
493
+ # round or +0.5
494
+ x = round(x)
495
+ # boundary check
496
+ x = 0 if x<0 else x
497
+ x = 255 if x>255 else x
498
+ s[i,j,k] = x
499
+
500
+ s = cv2.cvtColor(s,cv2.COLOR_LAB2BGRA)
501
+ cv2.imwrite(frames[n],s)
502
+
503
+
504
  js = """
505
  async()=>{
506