Spaces:
Running
on
Zero
Running
on
Zero
Fix
Browse files
app.py
CHANGED
|
@@ -424,7 +424,7 @@ class Drag:
|
|
| 424 |
image_end = Image.open(last_frame_path).convert("RGB")
|
| 425 |
image_end = image_end.resize((self.width, self.height))
|
| 426 |
|
| 427 |
-
input_all_points = tracking_points
|
| 428 |
|
| 429 |
sift_track_update = False
|
| 430 |
anchor_points_flag = None
|
|
@@ -545,10 +545,9 @@ class Drag:
|
|
| 545 |
|
| 546 |
|
| 547 |
def reset_states(first_frame_path, last_frame_path, tracking_points):
|
| 548 |
-
first_frame_path =
|
| 549 |
-
last_frame_path =
|
| 550 |
-
tracking_points =
|
| 551 |
-
|
| 552 |
return first_frame_path, last_frame_path, tracking_points
|
| 553 |
|
| 554 |
|
|
@@ -566,7 +565,7 @@ def preprocess_image(image):
|
|
| 566 |
|
| 567 |
image_pil.save(first_frame_path)
|
| 568 |
|
| 569 |
-
return first_frame_path, first_frame_path,
|
| 570 |
|
| 571 |
|
| 572 |
def preprocess_image_end(image_end):
|
|
@@ -583,22 +582,22 @@ def preprocess_image_end(image_end):
|
|
| 583 |
|
| 584 |
image_end_pil.save(last_frame_path)
|
| 585 |
|
| 586 |
-
return last_frame_path, last_frame_path,
|
| 587 |
|
| 588 |
|
| 589 |
def add_drag(tracking_points):
|
| 590 |
-
tracking_points.
|
| 591 |
return tracking_points
|
| 592 |
|
| 593 |
|
| 594 |
def delete_last_drag(tracking_points, first_frame_path, last_frame_path):
|
| 595 |
-
tracking_points.
|
| 596 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 597 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 598 |
w, h = transparent_background.size
|
| 599 |
transparent_layer = np.zeros((h, w, 4))
|
| 600 |
|
| 601 |
-
for track in tracking_points
|
| 602 |
if len(track) > 1:
|
| 603 |
for i in range(len(track) - 1):
|
| 604 |
start_point = track[i]
|
|
@@ -634,13 +633,13 @@ def delete_last_drag(tracking_points, first_frame_path, last_frame_path):
|
|
| 634 |
|
| 635 |
|
| 636 |
def delete_last_step(tracking_points, first_frame_path, last_frame_path):
|
| 637 |
-
tracking_points
|
| 638 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 639 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 640 |
w, h = transparent_background.size
|
| 641 |
transparent_layer = np.zeros((h, w, 4))
|
| 642 |
|
| 643 |
-
for track in tracking_points
|
| 644 |
if len(track) > 1:
|
| 645 |
for i in range(len(track) - 1):
|
| 646 |
start_point = track[i]
|
|
@@ -679,14 +678,14 @@ def add_tracking_points(
|
|
| 679 |
tracking_points, first_frame_path, last_frame_path, evt: gr.SelectData
|
| 680 |
): # SelectData is a subclass of EventData
|
| 681 |
print(f"You selected {evt.value} at {evt.index} from {evt.target}")
|
| 682 |
-
tracking_points
|
| 683 |
|
| 684 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 685 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 686 |
|
| 687 |
w, h = transparent_background.size
|
| 688 |
transparent_layer = 0
|
| 689 |
-
for idx, track in enumerate(tracking_points
|
| 690 |
# mask = cv2.imread(
|
| 691 |
# os.path.join(args.output_dir, f"mask_{idx+1}.jpg")
|
| 692 |
# )
|
|
|
|
| 424 |
image_end = Image.open(last_frame_path).convert("RGB")
|
| 425 |
image_end = image_end.resize((self.width, self.height))
|
| 426 |
|
| 427 |
+
input_all_points = tracking_points
|
| 428 |
|
| 429 |
sift_track_update = False
|
| 430 |
anchor_points_flag = None
|
|
|
|
| 545 |
|
| 546 |
|
| 547 |
def reset_states(first_frame_path, last_frame_path, tracking_points):
|
| 548 |
+
first_frame_path = None
|
| 549 |
+
last_frame_path = None
|
| 550 |
+
tracking_points = []
|
|
|
|
| 551 |
return first_frame_path, last_frame_path, tracking_points
|
| 552 |
|
| 553 |
|
|
|
|
| 565 |
|
| 566 |
image_pil.save(first_frame_path)
|
| 567 |
|
| 568 |
+
return first_frame_path, first_frame_path, []
|
| 569 |
|
| 570 |
|
| 571 |
def preprocess_image_end(image_end):
|
|
|
|
| 582 |
|
| 583 |
image_end_pil.save(last_frame_path)
|
| 584 |
|
| 585 |
+
return last_frame_path, last_frame_path, []
|
| 586 |
|
| 587 |
|
| 588 |
def add_drag(tracking_points):
|
| 589 |
+
tracking_points.append([])
|
| 590 |
return tracking_points
|
| 591 |
|
| 592 |
|
| 593 |
def delete_last_drag(tracking_points, first_frame_path, last_frame_path):
|
| 594 |
+
tracking_points.pop()
|
| 595 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 596 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 597 |
w, h = transparent_background.size
|
| 598 |
transparent_layer = np.zeros((h, w, 4))
|
| 599 |
|
| 600 |
+
for track in tracking_points:
|
| 601 |
if len(track) > 1:
|
| 602 |
for i in range(len(track) - 1):
|
| 603 |
start_point = track[i]
|
|
|
|
| 633 |
|
| 634 |
|
| 635 |
def delete_last_step(tracking_points, first_frame_path, last_frame_path):
|
| 636 |
+
tracking_points[-1].pop()
|
| 637 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 638 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 639 |
w, h = transparent_background.size
|
| 640 |
transparent_layer = np.zeros((h, w, 4))
|
| 641 |
|
| 642 |
+
for track in tracking_points:
|
| 643 |
if len(track) > 1:
|
| 644 |
for i in range(len(track) - 1):
|
| 645 |
start_point = track[i]
|
|
|
|
| 678 |
tracking_points, first_frame_path, last_frame_path, evt: gr.SelectData
|
| 679 |
): # SelectData is a subclass of EventData
|
| 680 |
print(f"You selected {evt.value} at {evt.index} from {evt.target}")
|
| 681 |
+
tracking_points[-1].append(evt.index)
|
| 682 |
|
| 683 |
transparent_background = Image.open(first_frame_path).convert("RGBA")
|
| 684 |
transparent_background_end = Image.open(last_frame_path).convert("RGBA")
|
| 685 |
|
| 686 |
w, h = transparent_background.size
|
| 687 |
transparent_layer = 0
|
| 688 |
+
for idx, track in enumerate(tracking_points):
|
| 689 |
# mask = cv2.imread(
|
| 690 |
# os.path.join(args.output_dir, f"mask_{idx+1}.jpg")
|
| 691 |
# )
|