Enhance HVideoTool's detection and restoration features: added support for tracking the model used in detections, improved temporal coherence by allowing the use of already-restored frames in the restoration process, and updated the UI to reflect these changes with new indicators and configuration options. Documentation in CLAUDE.md has been updated accordingly.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
"""A horizontal QSlider that paints marks at frames where censorship was found.
|
||||
"""A horizontal QSlider that paints marks at frames along the sequence.
|
||||
|
||||
Used as the navigation scrubber under the image: the file list / `_results`
|
||||
cache is projected onto the groove as small vertical ticks, so you can see at a
|
||||
glance where the detected regions are along the whole sequence.
|
||||
Used as the navigation scrubber under the image. Two independent layers are
|
||||
projected onto the groove as small vertical ticks, so you can see at a glance how
|
||||
the whole sequence is processed:
|
||||
|
||||
* **cyan** (upper half) — frames where censorship was *detected* (`_results`);
|
||||
* **green** (lower half) — frames that have been *restored* (``restored/``).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -17,19 +20,29 @@ from PySide6.QtWidgets import QSlider, QStyle, QStyleOptionSlider
|
||||
class MarkerSlider(QSlider):
|
||||
def __init__(self, orientation=Qt.Horizontal, parent=None) -> None:
|
||||
super().__init__(orientation, parent)
|
||||
self._marks: set[int] = set()
|
||||
self._marks: set[int] = set() # detected (censorship found)
|
||||
self._restored_marks: set[int] = set() # restored (un-censored)
|
||||
# Bright cyan stands out against both the dark track and the orange fill.
|
||||
self._mark_color = QColor(0, 220, 255)
|
||||
self._restored_color = QColor(80, 230, 120) # green = restored
|
||||
|
||||
def set_marks(self, marks: Iterable[int]) -> None:
|
||||
"""Frames with detections (painted cyan, upper half)."""
|
||||
marks = set(marks)
|
||||
if marks != self._marks:
|
||||
self._marks = marks
|
||||
self.update()
|
||||
|
||||
def set_restored_marks(self, marks: Iterable[int]) -> None:
|
||||
"""Frames that have been restored (painted green, lower half)."""
|
||||
marks = set(marks)
|
||||
if marks != self._restored_marks:
|
||||
self._restored_marks = marks
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, event) -> None:
|
||||
super().paintEvent(event)
|
||||
if not self._marks or self.maximum() <= self.minimum():
|
||||
if (not self._marks and not self._restored_marks) or self.maximum() <= self.minimum():
|
||||
return
|
||||
|
||||
opt = QStyleOptionSlider()
|
||||
@@ -45,22 +58,32 @@ class MarkerSlider(QSlider):
|
||||
return
|
||||
lo, hi = self.minimum(), self.maximum()
|
||||
half = handle.width() // 2
|
||||
# Span (almost) the full widget height so marks read over the fill/handle.
|
||||
top = self.rect().top() + 1
|
||||
bottom = self.rect().bottom() - 1
|
||||
mid = (top + bottom) // 2
|
||||
|
||||
painter = QPainter(self)
|
||||
# Detections in the upper half, restored in the lower half, so a frame that's
|
||||
# both detected and restored shows both ticks instead of one hiding the other.
|
||||
self._paint_layer(painter, self._marks, self._mark_color, top, mid,
|
||||
groove.x(), half, span, lo, hi, opt.upsideDown)
|
||||
self._paint_layer(painter, self._restored_marks, self._restored_color, mid, bottom,
|
||||
groove.x(), half, span, lo, hi, opt.upsideDown)
|
||||
painter.end()
|
||||
|
||||
def _paint_layer(self, painter, marks, color, y0, y1, gx, half, span, lo, hi, upside) -> None:
|
||||
if not marks:
|
||||
return
|
||||
pen = painter.pen()
|
||||
pen.setColor(self._mark_color)
|
||||
pen.setColor(color)
|
||||
pen.setWidth(2)
|
||||
painter.setPen(pen)
|
||||
# Many frames can collapse onto the same pixel column — dedupe to keep
|
||||
# repaint cheap on big folders (tens of thousands of frames).
|
||||
seen_x: set[int] = set()
|
||||
for m in self._marks:
|
||||
pos = QStyle.sliderPositionFromValue(lo, hi, m, span, opt.upsideDown)
|
||||
x = groove.x() + half + pos
|
||||
for m in marks:
|
||||
pos = QStyle.sliderPositionFromValue(lo, hi, m, span, upside)
|
||||
x = gx + half + pos
|
||||
if x not in seen_x:
|
||||
seen_x.add(x)
|
||||
painter.drawLine(x, top, x, bottom)
|
||||
painter.end()
|
||||
painter.drawLine(x, y0, x, y1)
|
||||
|
||||
Reference in New Issue
Block a user