Quality Slider Corrections

This commit is contained in:
Lahfir 2023-07-20 08:28:55 +05:30
parent df731fcef1
commit 86100e28da
7 changed files with 144 additions and 137 deletions

View File

@ -1,45 +0,0 @@
---
name: Bug
about: Report a bug
title: '[Bug]'
labels: 'bug'
---
## Description
A concise description of the bug and how to reproduce it.
## Error
Paste the error or exception from your console:
```
```
## Details
What operating system are you using?
- [ ] Windows
- [ ] MacOS (Apple Silicon)
- [ ] MacOS (Apple Legacy)
- [ ] Linux
- [ ] Linux in WSL
What execution provider are you using?
- [ ] CPU
- [ ] CUDA
- [ ] CoreML
- [ ] DirectML
- [ ] OpenVINO
- [ ] Other
What version of Roop are you using?
- [ ] 1.0.0
- [ ] 1.1.0
- [ ] 1.2.0
- [ ] next

View File

@ -1,12 +0,0 @@
---
name: Installation
about: Platform and installation issues
title: '[Installation]'
labels: 'installation'
---
Please **DO NOT OPEN** platform and installation issues!
- Check the [troubleshooting](https://github.com/s0md3v/roop/wiki/4.-Troubleshooting) that covers many issues.
- Join our helpful community on [Discord](https://discord.gg/Y9p4ZQ2sB9) for instant help.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 537 KiB

Binary file not shown.

View File

@ -1,33 +0,0 @@
name: ci
on: [ push, pull_request ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- run: pip install flake8
- run: pip install mypy
- run: flake8 run.py roop
- run: mypy run.py roop
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- run: pip install -r requirements-ci.txt
- run: python run.py -s=.github/examples/source.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4
- run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null -

View File

@ -11,7 +11,11 @@ import roop.globals
import roop.metadata
from roop.face_analyser import get_one_face
from roop.capturer import get_video_frame, get_video_frame_total
from roop.face_reference import get_face_reference, set_face_reference, clear_face_reference
from roop.face_reference import (
get_face_reference,
set_face_reference,
clear_face_reference,
)
from roop.predictor import predict_frame, clear_predictor
from roop.processors.frame.core import get_frame_processors_modules
from roop.utilities import is_image, is_video, resolve_relative_path
@ -55,67 +59,132 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
global source_label, target_label, status_label
ctk.deactivate_automatic_dpi_awareness()
ctk.set_appearance_mode('system')
ctk.set_default_color_theme(resolve_relative_path('ui.json'))
ctk.set_appearance_mode("system")
ctk.set_default_color_theme(resolve_relative_path("ui.json"))
root = CTk()
root.minsize(ROOT_WIDTH, ROOT_HEIGHT)
root.title(f'{roop.metadata.name} {roop.metadata.version}')
root.title(f"{roop.metadata.name} {roop.metadata.version}")
root.configure()
root.protocol('WM_DELETE_WINDOW', lambda: destroy())
root.protocol("WM_DELETE_WINDOW", lambda: destroy())
source_label = ctk.CTkLabel(root, text=None, fg_color=ctk.ThemeManager.theme.get('RoopDropArea').get('fg_color'))
source_label = ctk.CTkLabel(
root,
text=None,
fg_color=ctk.ThemeManager.theme.get("RoopDropArea").get("fg_color"),
)
source_label.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.25)
source_label.drop_target_register(DND_ALL)
source_label.dnd_bind('<<Drop>>', lambda event: select_source_path(event.data))
source_label.dnd_bind("<<Drop>>", lambda event: select_source_path(event.data))
if roop.globals.source_path:
select_source_path(roop.globals.source_path)
target_label = ctk.CTkLabel(root, text=None, fg_color=ctk.ThemeManager.theme.get('RoopDropArea').get('fg_color'))
target_label = ctk.CTkLabel(
root,
text=None,
fg_color=ctk.ThemeManager.theme.get("RoopDropArea").get("fg_color"),
)
target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25)
target_label.drop_target_register(DND_ALL)
target_label.dnd_bind('<<Drop>>', lambda event: select_target_path(event.data))
target_label.dnd_bind("<<Drop>>", lambda event: select_target_path(event.data))
if roop.globals.target_path:
select_target_path(roop.globals.target_path)
source_button = ctk.CTkButton(root, text='Select a face', cursor='hand2', command=lambda: select_source_path())
source_button = ctk.CTkButton(
root, text="Select a face", cursor="hand2", command=lambda: select_source_path()
)
source_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
target_button = ctk.CTkButton(root, text='Select a target', cursor='hand2', command=lambda: select_target_path())
target_button = ctk.CTkButton(
root,
text="Select a target",
cursor="hand2",
command=lambda: select_target_path(),
)
target_button.place(relx=0.6, rely=0.4, relwidth=0.3, relheight=0.1)
keep_fps_value = ctk.BooleanVar(value=roop.globals.keep_fps)
keep_fps_checkbox = ctk.CTkSwitch(root, text='Keep target fps', variable=keep_fps_value, cursor='hand2', command=lambda: setattr(roop.globals, 'keep_fps', not roop.globals.keep_fps))
keep_fps_checkbox = ctk.CTkSwitch(
root,
text="Keep target fps",
variable=keep_fps_value,
cursor="hand2",
command=lambda: setattr(roop.globals, "keep_fps", not roop.globals.keep_fps),
)
keep_fps_checkbox.place(relx=0.1, rely=0.6)
keep_frames_value = ctk.BooleanVar(value=roop.globals.keep_frames)
keep_frames_switch = ctk.CTkSwitch(root, text='Keep temporary frames', variable=keep_frames_value, cursor='hand2', command=lambda: setattr(roop.globals, 'keep_frames', keep_frames_value.get()))
keep_frames_switch = ctk.CTkSwitch(
root,
text="Keep temporary frames",
variable=keep_frames_value,
cursor="hand2",
command=lambda: setattr(roop.globals, "keep_frames", keep_frames_value.get()),
)
keep_frames_switch.place(relx=0.1, rely=0.65)
skip_audio_value = ctk.BooleanVar(value=roop.globals.skip_audio)
skip_audio_switch = ctk.CTkSwitch(root, text='Skip target audio', variable=skip_audio_value, cursor='hand2', command=lambda: setattr(roop.globals, 'skip_audio', skip_audio_value.get()))
skip_audio_switch = ctk.CTkSwitch(
root,
text="Skip target audio",
variable=skip_audio_value,
cursor="hand2",
command=lambda: setattr(roop.globals, "skip_audio", skip_audio_value.get()),
)
skip_audio_switch.place(relx=0.6, rely=0.6)
many_faces_value = ctk.BooleanVar(value=roop.globals.many_faces)
many_faces_switch = ctk.CTkSwitch(root, text='Many faces', variable=many_faces_value, cursor='hand2', command=lambda: setattr(roop.globals, 'many_faces', many_faces_value.get()))
many_faces_switch = ctk.CTkSwitch(
root,
text="Many faces",
variable=many_faces_value,
cursor="hand2",
command=lambda: setattr(roop.globals, "many_faces", many_faces_value.get()),
)
many_faces_switch.place(relx=0.6, rely=0.65)
start_button = ctk.CTkButton(root, text='Start', cursor='hand2', command=lambda: select_output_path(start))
# Add a slider for video quality
video_quality_label = ctk.CTkLabel(root, text="Quality", justify="center")
video_quality_label.place(relx=0.1, rely=0.5, relwidth=0.3, relheight=0.1)
video_quality_value = ctk.IntVar(value=25) # Set a default value for video quality
video_quality_slider = ctk.CTkSlider(
root,
from_=0,
to=51,
variable=video_quality_value,
cursor="hand2",
)
video_quality_slider.place(relx=0.4, rely=0.5, relwidth=0.9, relheight=0.01)
start_button = ctk.CTkButton(
root, text="Start", cursor="hand2", command=lambda: select_output_path(start)
)
start_button.place(relx=0.15, rely=0.75, relwidth=0.2, relheight=0.05)
stop_button = ctk.CTkButton(root, text='Destroy', cursor='hand2', command=lambda: destroy())
stop_button = ctk.CTkButton(
root, text="Destroy", cursor="hand2", command=lambda: destroy()
)
stop_button.place(relx=0.4, rely=0.75, relwidth=0.2, relheight=0.05)
preview_button = ctk.CTkButton(root, text='Preview', cursor='hand2', command=lambda: toggle_preview())
preview_button = ctk.CTkButton(
root, text="Preview", cursor="hand2", command=lambda: toggle_preview()
)
preview_button.place(relx=0.65, rely=0.75, relwidth=0.2, relheight=0.05)
status_label = ctk.CTkLabel(root, text=None, justify='center')
status_label = ctk.CTkLabel(root, text=None, justify="center")
status_label.place(relx=0.1, rely=0.9, relwidth=0.8)
donate_label = ctk.CTkLabel(root, text='^_^ Donate to project ^_^', justify='center', cursor='hand2')
donate_label = ctk.CTkLabel(
root, text="^_^ Donate to project ^_^", justify="center", cursor="hand2"
)
donate_label.place(relx=0.1, rely=0.95, relwidth=0.8)
donate_label.configure(text_color=ctk.ThemeManager.theme.get('RoopDonate').get('text_color'))
donate_label.bind('<Button>', lambda event: webbrowser.open('https://github.com/sponsors/s0md3v'))
donate_label.configure(
text_color=ctk.ThemeManager.theme.get("RoopDonate").get("text_color")
)
donate_label.bind(
"<Button>", lambda event: webbrowser.open("https://github.com/sponsors/s0md3v")
)
return root
@ -126,16 +195,18 @@ def create_preview(parent: ctk.CTkToplevel) -> ctk.CTkToplevel:
preview = ctk.CTkToplevel(parent)
preview.withdraw()
preview.configure()
preview.protocol('WM_DELETE_WINDOW', lambda: toggle_preview())
preview.protocol("WM_DELETE_WINDOW", lambda: toggle_preview())
preview.resizable(width=False, height=False)
preview_label = ctk.CTkLabel(preview, text=None)
preview_label.pack(fill='both', expand=True)
preview_label.pack(fill="both", expand=True)
preview_slider = ctk.CTkSlider(preview, from_=0, to=0, command=lambda frame_value: update_preview(frame_value))
preview_slider = ctk.CTkSlider(
preview, from_=0, to=0, command=lambda frame_value: update_preview(frame_value)
)
preview.bind('<Up>', lambda event: update_face_reference(1))
preview.bind('<Down>', lambda event: update_face_reference(-1))
preview.bind("<Up>", lambda event: update_face_reference(1))
preview.bind("<Down>", lambda event: update_face_reference(-1))
return preview
@ -150,7 +221,9 @@ def select_source_path(source_path: Optional[str] = None) -> None:
if PREVIEW:
PREVIEW.withdraw()
if source_path is None:
source_path = ctk.filedialog.askopenfilename(title='select an source image', initialdir=RECENT_DIRECTORY_SOURCE)
source_path = ctk.filedialog.askopenfilename(
title="select an source image", initialdir=RECENT_DIRECTORY_SOURCE
)
if is_image(source_path):
roop.globals.source_path = source_path # type: ignore
RECENT_DIRECTORY_SOURCE = os.path.dirname(roop.globals.source_path)
@ -168,7 +241,9 @@ def select_target_path(target_path: Optional[str] = None) -> None:
PREVIEW.withdraw()
clear_face_reference()
if target_path is None:
target_path = ctk.filedialog.askopenfilename(title='select an target image or video', initialdir=RECENT_DIRECTORY_TARGET)
target_path = ctk.filedialog.askopenfilename(
title="select an target image or video", initialdir=RECENT_DIRECTORY_TARGET
)
if is_image(target_path):
roop.globals.target_path = target_path # type: ignore
RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path)
@ -188,9 +263,19 @@ def select_output_path(start: Callable[[], None]) -> None:
global RECENT_DIRECTORY_OUTPUT
if is_image(roop.globals.target_path):
output_path = ctk.filedialog.asksaveasfilename(title='save image output file', defaultextension='.png', initialfile='output.png', initialdir=RECENT_DIRECTORY_OUTPUT)
output_path = ctk.filedialog.asksaveasfilename(
title="save image output file",
defaultextension=".png",
initialfile="output.png",
initialdir=RECENT_DIRECTORY_OUTPUT,
)
elif is_video(roop.globals.target_path):
output_path = ctk.filedialog.asksaveasfilename(title='save video output file', defaultextension='.mp4', initialfile='output.mp4', initialdir=RECENT_DIRECTORY_OUTPUT)
output_path = ctk.filedialog.asksaveasfilename(
title="save video output file",
defaultextension=".mp4",
initialfile="output.mp4",
initialdir=RECENT_DIRECTORY_OUTPUT,
)
else:
output_path = None
if output_path:
@ -206,7 +291,9 @@ def render_image_preview(image_path: str, size: Tuple[int, int]) -> ctk.CTkImage
return ctk.CTkImage(image, size=image.size)
def render_video_preview(video_path: str, size: Tuple[int, int], frame_number: int = 0) -> ctk.CTkImage:
def render_video_preview(
video_path: str, size: Tuple[int, int], frame_number: int = 0
) -> ctk.CTkImage:
capture = cv2.VideoCapture(video_path)
if frame_number:
capture.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
@ -221,9 +308,9 @@ def render_video_preview(video_path: str, size: Tuple[int, int], frame_number: i
def toggle_preview() -> None:
if PREVIEW.state() == 'normal':
PREVIEW.unbind('<Right>')
PREVIEW.unbind('<Left>')
if PREVIEW.state() == "normal":
PREVIEW.unbind("<Right>")
PREVIEW.unbind("<Left>")
PREVIEW.withdraw()
clear_predictor()
elif roop.globals.source_path and roop.globals.target_path:
@ -233,17 +320,21 @@ def toggle_preview() -> None:
def init_preview() -> None:
PREVIEW.title('Preview [ ↕ Reference face ]')
PREVIEW.title("Preview [ ↕ Reference face ]")
if is_image(roop.globals.target_path):
preview_slider.pack_forget()
if is_video(roop.globals.target_path):
video_frame_total = get_video_frame_total(roop.globals.target_path)
if video_frame_total > 0:
PREVIEW.title('Preview [ ↕ Reference face ] [ ↔ Frame number ]')
PREVIEW.bind('<Right>', lambda event: update_frame(int(video_frame_total / 20)))
PREVIEW.bind('<Left>', lambda event: update_frame(int(video_frame_total / -20)))
PREVIEW.title("Preview [ ↕ Reference face ] [ ↔ Frame number ]")
PREVIEW.bind(
"<Right>", lambda event: update_frame(int(video_frame_total / 20))
)
PREVIEW.bind(
"<Left>", lambda event: update_frame(int(video_frame_total / -20))
)
preview_slider.configure(to=video_frame_total)
preview_slider.pack(fill='x')
preview_slider.pack(fill="x")
preview_slider.set(roop.globals.reference_frame_number)
@ -254,19 +345,25 @@ def update_preview(frame_number: int = 0) -> None:
sys.exit()
source_face = get_one_face(cv2.imread(roop.globals.source_path))
if not get_face_reference():
reference_frame = get_video_frame(roop.globals.target_path, roop.globals.reference_frame_number)
reference_face = get_one_face(reference_frame, roop.globals.reference_face_position)
reference_frame = get_video_frame(
roop.globals.target_path, roop.globals.reference_frame_number
)
reference_face = get_one_face(
reference_frame, roop.globals.reference_face_position
)
set_face_reference(reference_face)
else:
reference_face = get_face_reference()
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
for frame_processor in get_frame_processors_modules(
roop.globals.frame_processors
):
temp_frame = frame_processor.process_frame(
source_face,
reference_face,
temp_frame
source_face, reference_face, temp_frame
)
image = Image.fromarray(cv2.cvtColor(temp_frame, cv2.COLOR_BGR2RGB))
image = ImageOps.contain(image, (PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT), Image.LANCZOS)
image = ImageOps.contain(
image, (PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT), Image.LANCZOS
)
image = ctk.CTkImage(image, size=image.size)
preview_label.configure(image=image)