Candle commited on
Commit ·
d6d7b2c
1
Parent(s): c022f02
fix
Browse files- loop_labeler_ui.py +31 -11
loop_labeler_ui.py
CHANGED
|
@@ -108,9 +108,10 @@ class LoopLabeler(QWidget):
|
|
| 108 |
start = candidate["start"]
|
| 109 |
end = candidate["end"]
|
| 110 |
nframes = len(self.frames)
|
|
|
|
| 111 |
self.start_slider.setMinimum(0)
|
| 112 |
-
self.start_slider.setMaximum(nframes-
|
| 113 |
-
self.end_slider.setMinimum(
|
| 114 |
self.end_slider.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 115 |
self.start_slider.setValue(start)
|
| 116 |
self.end_slider.setValue(end)
|
|
@@ -120,27 +121,46 @@ class LoopLabeler(QWidget):
|
|
| 120 |
def on_slider_changed(self):
|
| 121 |
start = self.start_slider.value()
|
| 122 |
end = self.end_slider.value()
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
if end <= start:
|
| 126 |
-
|
| 127 |
-
|
| 128 |
self.preview_idx = 0
|
| 129 |
|
| 130 |
def update_preview(self):
|
| 131 |
start = self.start_slider.value()
|
| 132 |
end = self.end_slider.value()
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
import numpy as np
|
| 136 |
import cv2
|
| 137 |
frame_resized = frame.resize((320,320))
|
| 138 |
arr = np.array(frame_resized)
|
| 139 |
# Draw progress indicator line at bottom
|
| 140 |
indicator_height = 2
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
arr[-indicator_height:, :320] = [220, 220, 220] # light gray background
|
| 145 |
arr[-indicator_height:, :bar_w] = [100, 100, 255] # red progress
|
| 146 |
# Convert RGB to BGR for OpenCV, then to QImage
|
|
|
|
| 108 |
start = candidate["start"]
|
| 109 |
end = candidate["end"]
|
| 110 |
nframes = len(self.frames)
|
| 111 |
+
# Set both sliders to cover full range from 0 to N
|
| 112 |
self.start_slider.setMinimum(0)
|
| 113 |
+
self.start_slider.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 114 |
+
self.end_slider.setMinimum(0)
|
| 115 |
self.end_slider.setMaximum(nframes-1 if nframes > 0 else 0)
|
| 116 |
self.start_slider.setValue(start)
|
| 117 |
self.end_slider.setValue(end)
|
|
|
|
| 121 |
def on_slider_changed(self):
|
| 122 |
start = self.start_slider.value()
|
| 123 |
end = self.end_slider.value()
|
| 124 |
+
# Ensure valid start and end values for preview
|
| 125 |
+
# We'll allow any values but for preview we need end > start
|
| 126 |
if end <= start:
|
| 127 |
+
# For preview purposes, we'll adjust temporarily in the update_preview method
|
| 128 |
+
pass
|
| 129 |
self.preview_idx = 0
|
| 130 |
|
| 131 |
def update_preview(self):
|
| 132 |
start = self.start_slider.value()
|
| 133 |
end = self.end_slider.value()
|
| 134 |
+
|
| 135 |
+
# Handle case where end ≤ start by showing a single frame or appropriate range
|
| 136 |
+
if self.frames:
|
| 137 |
+
if end <= start:
|
| 138 |
+
# Show just the start frame when end <= start
|
| 139 |
+
frame_idx = start
|
| 140 |
+
frame = self.frames[frame_idx]
|
| 141 |
+
show_progress = False
|
| 142 |
+
else:
|
| 143 |
+
# Normal case: show animation between start and end
|
| 144 |
+
frame_idx = start + (self.preview_idx % (end-start))
|
| 145 |
+
frame = self.frames[frame_idx]
|
| 146 |
+
show_progress = True
|
| 147 |
+
|
| 148 |
import numpy as np
|
| 149 |
import cv2
|
| 150 |
frame_resized = frame.resize((320,320))
|
| 151 |
arr = np.array(frame_resized)
|
| 152 |
# Draw progress indicator line at bottom
|
| 153 |
indicator_height = 2
|
| 154 |
+
|
| 155 |
+
# Only show progress bar when we have a valid range
|
| 156 |
+
if show_progress:
|
| 157 |
+
total = end - start
|
| 158 |
+
pos = self.preview_idx % total
|
| 159 |
+
bar_w = int(320 * (pos / max(total-1, 1)))
|
| 160 |
+
else:
|
| 161 |
+
# Just show a full bar for single frame
|
| 162 |
+
bar_w = 320
|
| 163 |
+
|
| 164 |
arr[-indicator_height:, :320] = [220, 220, 220] # light gray background
|
| 165 |
arr[-indicator_height:, :bar_w] = [100, 100, 255] # red progress
|
| 166 |
# Convert RGB to BGR for OpenCV, then to QImage
|