freealise commited on
Commit
045da54
1 Parent(s): f79b1a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -186,6 +186,23 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', remove_bg
186
 
187
  raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA)
188
  raw_frame[:, :, 3] = 255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  cv2.imwrite(f"f{count}.png", raw_frame)
190
  orig_frames.append(f"f{count}.png")
191
 
@@ -1281,28 +1298,22 @@ with gr.Blocks(css=css, js=js) as demo:
1281
  locations = []
1282
  avg = [0, 0]
1283
 
1284
- if not coordinates:
1285
- locations = json.loads(example_coords)
1286
- for k, location in enumerate(locations):
 
 
 
 
 
 
 
 
1287
  avg[0] = avg[0] + locations[k]["lat"]
1288
  avg[1] = avg[1] + locations[k]["lng"]
1289
- else:
1290
- locations = json.loads(coordinates)
1291
- for k, location in enumerate(locations):
1292
- if "tiles" in locations[k]:
1293
- locations[k]["heading"] = locations[k]["tiles"]["originHeading"]
1294
- locations[k]["pitch"] = locations[k]["tiles"]["originPitch"]
1295
- else:
1296
- locations[k]["heading"] = 0
1297
- locations[k]["pitch"] = 0
1298
-
1299
- if "location" in locations[k]:
1300
- locations[k] = locations[k]["location"]["latLng"]
1301
- avg[0] = avg[0] + locations[k]["lat"]
1302
- avg[1] = avg[1] + locations[k]["lng"]
1303
- else:
1304
- locations[k]["lat"] = 0
1305
- locations[k]["lng"] = 0
1306
 
1307
  if len(locations) > 0:
1308
  avg[0] = avg[0] / len(locations)
 
186
 
187
  raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2BGRA)
188
  raw_frame[:, :, 3] = 255
189
+
190
+ if remove_bg == True:
191
+ if count >= int(len(cframes)/2):
192
+ depth_gray_bg = cv2.imread(f"f{count-int(len(cframes)/2)}_mask.png").astype(np.uint8)
193
+ raw_frame_bg = cv2.imread(f"f{count-int(len(cframes)/2)}.png").astype(np.uint8)
194
+
195
+ mask_bg = cv2.inRange(np.abs(depth_gray-depth_gray_bg), 0, 16)
196
+ mask_no_shadow = cv2.inRange(np.abs(raw_frame-raw_frame_bg), np.array([0,0,0,0]), np.array([16,16,16,0]))
197
+
198
+ depth_gray[cv2.bitwise_and(mask_no_shadow, mask_bg)>0] = 0
199
+ depth_color[cv2.bitwise_and(mask_no_shadow, mask_bg)>0] = (0,0,0)
200
+
201
+ m = cv2.inRange(raw_frame, np.array([255,255,255,255]), np.array([255,255,255,255]))
202
+ raw_frame[m>0] = (253,253,253,255)
203
+ raw_frame[mask_bg>0] = (254,254,254,255)
204
+ raw_frame[cv2.bitwise_and(mask_no_shadow, mask_bg)>0] = (255,255,255,255)
205
+
206
  cv2.imwrite(f"f{count}.png", raw_frame)
207
  orig_frames.append(f"f{count}.png")
208
 
 
1298
  locations = []
1299
  avg = [0, 0]
1300
 
1301
+ locations = json.loads(coordinates)
1302
+ for k, location in enumerate(locations):
1303
+ if "tiles" in locations[k]:
1304
+ locations[k]["heading"] = locations[k]["tiles"]["originHeading"]
1305
+ locations[k]["pitch"] = locations[k]["tiles"]["originPitch"]
1306
+ else:
1307
+ locations[k]["heading"] = 0
1308
+ locations[k]["pitch"] = 0
1309
+
1310
+ if "location" in locations[k]:
1311
+ locations[k] = locations[k]["location"]["latLng"]
1312
  avg[0] = avg[0] + locations[k]["lat"]
1313
  avg[1] = avg[1] + locations[k]["lng"]
1314
+ else:
1315
+ locations[k]["lat"] = 0
1316
+ locations[k]["lng"] = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1317
 
1318
  if len(locations) > 0:
1319
  avg[0] = avg[0] / len(locations)