Compare commits
10 Commits
20637d3c27
...
b3e73956d2
Author | SHA1 | Date |
---|---|---|
|
b3e73956d2 | |
|
693c9bb268 | |
|
5132f86cdc | |
|
cab2efa200 | |
|
6e29e4061b | |
|
2a7ae010a8 | |
|
a834811974 | |
|
d2aaf46e69 | |
|
d07d4a6a26 | |
|
aed933c1db |
22
README.md
22
README.md
|
@ -20,19 +20,14 @@
|
||||||
|
|
||||||
###### Users are expected to use this software responsibly and legally. If using a real person's face, obtain their consent and clearly label any output as a deepfake when sharing online. We are not responsible for end-user actions.
|
###### Users are expected to use this software responsibly and legally. If using a real person's face, obtain their consent and clearly label any output as a deepfake when sharing online. We are not responsible for end-user actions.
|
||||||
|
|
||||||
## Quick Start - Download Prebuilt
|
## Quick Start - Pre-built
|
||||||
|
<div align="center">
|
||||||
<div style="margin: 28px 0;">
|
<a href="https://hacksider.gumroad.com/l/vccdmm">
|
||||||
<div style="margin-bottom: 20px;">
|
<img src="https://github.com/user-attachments/assets/7d993b32-e3e8-4cd3-bbfb-a549152ebdd5" width="285" height="77" />
|
||||||
<a href="https://hacksider.gumroad.com/l/vccdmm" target="_blank">
|
</a>
|
||||||
<img src="https://github.com/user-attachments/assets/c702bb7d-d9c0-466a-9ad2-02849294e540" alt="Download Button 1" style="width: 280px; display: block;">
|
<a href="https://krshh.gumroad.com/l/Deep-Live-Cam-Mac">
|
||||||
</a>
|
<img src="https://github.com/user-attachments/assets/d5d913b5-a7de-4609-96b9-979a5749a703" width="285" height="77" />
|
||||||
</div>
|
</a>
|
||||||
<div>
|
|
||||||
<a href="https://krshh.gumroad.com/l/Deep-Live-Cam-Mac" target="_blank">
|
|
||||||
<img src="https://github.com/user-attachments/assets/9a302750-2d54-457d-bdc8-6ed7c6af0e1a" alt="Download Button 2" style="width: 280px; display: block;">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## Features - Everything is real-time
|
## Features - Everything is real-time
|
||||||
|
@ -261,6 +256,7 @@ Looking for a CLI mode? Using the -s/--source argument will make the run program
|
||||||
- [pereiraroland26](https://github.com/pereiraroland26): Multiple faces support
|
- [pereiraroland26](https://github.com/pereiraroland26): Multiple faces support
|
||||||
- [vic4key](https://github.com/vic4key): For supporting/contributing to this project
|
- [vic4key](https://github.com/vic4key): For supporting/contributing to this project
|
||||||
- [kier007](https://github.com/kier007): for improving the user experience
|
- [kier007](https://github.com/kier007): for improving the user experience
|
||||||
|
- [qitianai](https://github.com/qitianai): for multi-lingual support
|
||||||
- and [all developers](https://github.com/hacksider/Deep-Live-Cam/graphs/contributors) behind libraries used in this project.
|
- and [all developers](https://github.com/hacksider/Deep-Live-Cam/graphs/contributors) behind libraries used in this project.
|
||||||
- Footnote: Please be informed that the base author of the code is [s0md3v](https://github.com/s0md3v/roop)
|
- Footnote: Please be informed that the base author of the code is [s0md3v](https://github.com/s0md3v/roop)
|
||||||
- All the wonderful users who helped make this project go viral by starring the repo ❤️
|
- All the wonderful users who helped make this project go viral by starring the repo ❤️
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"Source x Target Mapper": "Source x Target Mapper",
|
||||||
|
"select an source image": "选择一个源图像",
|
||||||
|
"Preview": "预览",
|
||||||
|
"select an target image or video": "选择一个目标图像或视频",
|
||||||
|
"save image output file": "保存图像输出文件",
|
||||||
|
"save video output file": "保存视频输出文件",
|
||||||
|
"select an target image": "选择一个目标图像",
|
||||||
|
"source": "源",
|
||||||
|
"Select a target": "选择一个目标",
|
||||||
|
"Select a face": "选择一张脸",
|
||||||
|
"Keep audio": "保留音频",
|
||||||
|
"Face Enhancer": "面纹增强器",
|
||||||
|
"Many faces": "多脸",
|
||||||
|
"Show FPS": "显示帧率",
|
||||||
|
"Keep fps": "保持帧率",
|
||||||
|
"Keep frames": "保持帧数",
|
||||||
|
"Fix Blueish Cam": "修复偏蓝的摄像头",
|
||||||
|
"Mouth Mask": "口罩",
|
||||||
|
"Show Mouth Mask Box": "显示口罩盒",
|
||||||
|
"Start": "开始",
|
||||||
|
"Live": "直播",
|
||||||
|
"Destroy": "结束",
|
||||||
|
"Map faces": "识别人脸",
|
||||||
|
"Processing...": "处理中...",
|
||||||
|
"Processing succeed!": "处理成功!",
|
||||||
|
"Processing ignored!": "处理被忽略!",
|
||||||
|
"Failed to start camera": "启动相机失败",
|
||||||
|
"Please complete pop-up or close it.": "请先完成弹出窗口或者关闭它",
|
||||||
|
"Getting unique faces": "获取独特面部",
|
||||||
|
"Please select a source image first": "请先选择一个源图像",
|
||||||
|
"No faces found in target": "目标图像中没有人脸",
|
||||||
|
"Add": "添加",
|
||||||
|
"Clear": "清除",
|
||||||
|
"Submit": "确认",
|
||||||
|
"Select source image": "请选取源图像",
|
||||||
|
"Select target image": "请选取目标图像",
|
||||||
|
"Please provide mapping!": "请提供映射",
|
||||||
|
"Atleast 1 source with target is required!": "至少需要一个来源图像与目标图像相关!",
|
||||||
|
"At least 1 source with target is required!": "至少需要一个来源图像与目标图像相关!",
|
||||||
|
"Face could not be detected in last upload!": "最近上传的图像中没有检测到人脸!",
|
||||||
|
"Select Camera:": "选择摄像头",
|
||||||
|
"All mappings cleared!": "所有映射均已清除!",
|
||||||
|
"Mappings successfully submitted!": "成功提交映射!",
|
||||||
|
"Source x Target Mapper is already open.": "源 x 目标映射器已打开。"
|
||||||
|
}
|
|
@ -44,6 +44,7 @@ def parse_args() -> None:
|
||||||
program.add_argument('--mouth-mask', help='mask the mouth region', dest='mouth_mask', action='store_true', default=False)
|
program.add_argument('--mouth-mask', help='mask the mouth region', dest='mouth_mask', action='store_true', default=False)
|
||||||
program.add_argument('--video-encoder', help='adjust output video encoder', dest='video_encoder', default='libx264', choices=['libx264', 'libx265', 'libvpx-vp9'])
|
program.add_argument('--video-encoder', help='adjust output video encoder', dest='video_encoder', default='libx264', choices=['libx264', 'libx265', 'libvpx-vp9'])
|
||||||
program.add_argument('--video-quality', help='adjust output video quality', dest='video_quality', type=int, default=18, choices=range(52), metavar='[0-51]')
|
program.add_argument('--video-quality', help='adjust output video quality', dest='video_quality', type=int, default=18, choices=range(52), metavar='[0-51]')
|
||||||
|
program.add_argument('-l', '--lang', help='Ui language', default="en")
|
||||||
program.add_argument('--live-mirror', help='The live camera display as you see it in the front-facing camera frame', dest='live_mirror', action='store_true', default=False)
|
program.add_argument('--live-mirror', help='The live camera display as you see it in the front-facing camera frame', dest='live_mirror', action='store_true', default=False)
|
||||||
program.add_argument('--live-resizable', help='The live camera frame is resizable', dest='live_resizable', action='store_true', default=False)
|
program.add_argument('--live-resizable', help='The live camera frame is resizable', dest='live_resizable', action='store_true', default=False)
|
||||||
program.add_argument('--max-memory', help='maximum amount of RAM in GB', dest='max_memory', type=int, default=suggest_max_memory())
|
program.add_argument('--max-memory', help='maximum amount of RAM in GB', dest='max_memory', type=int, default=suggest_max_memory())
|
||||||
|
@ -78,6 +79,7 @@ def parse_args() -> None:
|
||||||
modules.globals.max_memory = args.max_memory
|
modules.globals.max_memory = args.max_memory
|
||||||
modules.globals.execution_providers = decode_execution_providers(args.execution_provider)
|
modules.globals.execution_providers = decode_execution_providers(args.execution_provider)
|
||||||
modules.globals.execution_threads = args.execution_threads
|
modules.globals.execution_threads = args.execution_threads
|
||||||
|
modules.globals.lang = args.lang
|
||||||
|
|
||||||
#for ENHANCER tumbler:
|
#for ENHANCER tumbler:
|
||||||
if 'face_enhancer' in args.frame_processor:
|
if 'face_enhancer' in args.frame_processor:
|
||||||
|
@ -253,5 +255,5 @@ def run() -> None:
|
||||||
if modules.globals.headless:
|
if modules.globals.headless:
|
||||||
start()
|
start()
|
||||||
else:
|
else:
|
||||||
window = ui.init(start, destroy)
|
window = ui.init(start, destroy, modules.globals.lang)
|
||||||
window.mainloop()
|
window.mainloop()
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
class LanguageManager:
|
||||||
|
def __init__(self, default_language="en"):
|
||||||
|
self.current_language = default_language
|
||||||
|
self.translations = {}
|
||||||
|
self.load_language(default_language)
|
||||||
|
|
||||||
|
def load_language(self, language_code) -> bool:
|
||||||
|
"""load language file"""
|
||||||
|
if language_code == "en":
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
file_path = Path(__file__).parent.parent / f"locales/{language_code}.json"
|
||||||
|
with open(file_path, "r", encoding="utf-8") as file:
|
||||||
|
self.translations = json.load(file)
|
||||||
|
self.current_language = language_code
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"Language file not found: {language_code}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _(self, key, default=None) -> str:
|
||||||
|
"""get translate text"""
|
||||||
|
return self.translations.get(key, default if default else key)
|
157
modules/ui.py
157
modules/ui.py
|
@ -26,6 +26,7 @@ from modules.utilities import (
|
||||||
has_image_extension,
|
has_image_extension,
|
||||||
)
|
)
|
||||||
from modules.video_capture import VideoCapturer
|
from modules.video_capture import VideoCapturer
|
||||||
|
from modules.gettext import LanguageManager
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
@ -63,6 +64,7 @@ RECENT_DIRECTORY_SOURCE = None
|
||||||
RECENT_DIRECTORY_TARGET = None
|
RECENT_DIRECTORY_TARGET = None
|
||||||
RECENT_DIRECTORY_OUTPUT = None
|
RECENT_DIRECTORY_OUTPUT = None
|
||||||
|
|
||||||
|
_ = None
|
||||||
preview_label = None
|
preview_label = None
|
||||||
preview_slider = None
|
preview_slider = None
|
||||||
source_label = None
|
source_label = None
|
||||||
|
@ -77,9 +79,11 @@ target_label_dict_live = {}
|
||||||
img_ft, vid_ft = modules.globals.file_types
|
img_ft, vid_ft = modules.globals.file_types
|
||||||
|
|
||||||
|
|
||||||
def init(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.CTk:
|
def init(start: Callable[[], None], destroy: Callable[[], None], lang: str) -> ctk.CTk:
|
||||||
global ROOT, PREVIEW
|
global ROOT, PREVIEW, _
|
||||||
|
|
||||||
|
lang_manager = LanguageManager(lang)
|
||||||
|
_ = lang_manager._
|
||||||
ROOT = create_root(start, destroy)
|
ROOT = create_root(start, destroy)
|
||||||
PREVIEW = create_preview(ROOT)
|
PREVIEW = create_preview(ROOT)
|
||||||
|
|
||||||
|
@ -154,7 +158,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25)
|
target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25)
|
||||||
|
|
||||||
select_face_button = ctk.CTkButton(
|
select_face_button = ctk.CTkButton(
|
||||||
root, text="Select a face", cursor="hand2", command=lambda: select_source_path()
|
root, text=_("Select a face"), cursor="hand2", command=lambda: select_source_path()
|
||||||
)
|
)
|
||||||
select_face_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
|
select_face_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
|
||||||
|
|
||||||
|
@ -165,7 +169,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
|
|
||||||
select_target_button = ctk.CTkButton(
|
select_target_button = ctk.CTkButton(
|
||||||
root,
|
root,
|
||||||
text="Select a target",
|
text=_("Select a target"),
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: select_target_path(),
|
command=lambda: select_target_path(),
|
||||||
)
|
)
|
||||||
|
@ -174,7 +178,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
keep_fps_value = ctk.BooleanVar(value=modules.globals.keep_fps)
|
keep_fps_value = ctk.BooleanVar(value=modules.globals.keep_fps)
|
||||||
keep_fps_checkbox = ctk.CTkSwitch(
|
keep_fps_checkbox = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Keep fps",
|
text=_("Keep fps"),
|
||||||
variable=keep_fps_value,
|
variable=keep_fps_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -187,7 +191,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
keep_frames_value = ctk.BooleanVar(value=modules.globals.keep_frames)
|
keep_frames_value = ctk.BooleanVar(value=modules.globals.keep_frames)
|
||||||
keep_frames_switch = ctk.CTkSwitch(
|
keep_frames_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Keep frames",
|
text=_("Keep frames"),
|
||||||
variable=keep_frames_value,
|
variable=keep_frames_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -200,7 +204,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
enhancer_value = ctk.BooleanVar(value=modules.globals.fp_ui["face_enhancer"])
|
enhancer_value = ctk.BooleanVar(value=modules.globals.fp_ui["face_enhancer"])
|
||||||
enhancer_switch = ctk.CTkSwitch(
|
enhancer_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Face Enhancer",
|
text=_("Face Enhancer"),
|
||||||
variable=enhancer_value,
|
variable=enhancer_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -213,7 +217,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
keep_audio_value = ctk.BooleanVar(value=modules.globals.keep_audio)
|
keep_audio_value = ctk.BooleanVar(value=modules.globals.keep_audio)
|
||||||
keep_audio_switch = ctk.CTkSwitch(
|
keep_audio_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Keep audio",
|
text=_("Keep audio"),
|
||||||
variable=keep_audio_value,
|
variable=keep_audio_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -226,7 +230,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
many_faces_value = ctk.BooleanVar(value=modules.globals.many_faces)
|
many_faces_value = ctk.BooleanVar(value=modules.globals.many_faces)
|
||||||
many_faces_switch = ctk.CTkSwitch(
|
many_faces_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Many faces",
|
text=_("Many faces"),
|
||||||
variable=many_faces_value,
|
variable=many_faces_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -239,7 +243,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
color_correction_value = ctk.BooleanVar(value=modules.globals.color_correction)
|
color_correction_value = ctk.BooleanVar(value=modules.globals.color_correction)
|
||||||
color_correction_switch = ctk.CTkSwitch(
|
color_correction_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Fix Blueish Cam",
|
text=_("Fix Blueish Cam"),
|
||||||
variable=color_correction_value,
|
variable=color_correction_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -256,12 +260,13 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
map_faces = ctk.BooleanVar(value=modules.globals.map_faces)
|
map_faces = ctk.BooleanVar(value=modules.globals.map_faces)
|
||||||
map_faces_switch = ctk.CTkSwitch(
|
map_faces_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Map faces",
|
text=_("Map faces"),
|
||||||
variable=map_faces,
|
variable=map_faces,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
setattr(modules.globals, "map_faces", map_faces.get()),
|
setattr(modules.globals, "map_faces", map_faces.get()),
|
||||||
save_switch_states(),
|
save_switch_states(),
|
||||||
|
close_mapper_window() if not map_faces.get() else None
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
map_faces_switch.place(relx=0.1, rely=0.75)
|
map_faces_switch.place(relx=0.1, rely=0.75)
|
||||||
|
@ -269,7 +274,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
show_fps_value = ctk.BooleanVar(value=modules.globals.show_fps)
|
show_fps_value = ctk.BooleanVar(value=modules.globals.show_fps)
|
||||||
show_fps_switch = ctk.CTkSwitch(
|
show_fps_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Show FPS",
|
text=_("Show FPS"),
|
||||||
variable=show_fps_value,
|
variable=show_fps_value,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: (
|
command=lambda: (
|
||||||
|
@ -282,7 +287,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
mouth_mask_var = ctk.BooleanVar(value=modules.globals.mouth_mask)
|
mouth_mask_var = ctk.BooleanVar(value=modules.globals.mouth_mask)
|
||||||
mouth_mask_switch = ctk.CTkSwitch(
|
mouth_mask_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Mouth Mask",
|
text=_("Mouth Mask"),
|
||||||
variable=mouth_mask_var,
|
variable=mouth_mask_var,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: setattr(modules.globals, "mouth_mask", mouth_mask_var.get()),
|
command=lambda: setattr(modules.globals, "mouth_mask", mouth_mask_var.get()),
|
||||||
|
@ -292,7 +297,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
show_mouth_mask_box_var = ctk.BooleanVar(value=modules.globals.show_mouth_mask_box)
|
show_mouth_mask_box_var = ctk.BooleanVar(value=modules.globals.show_mouth_mask_box)
|
||||||
show_mouth_mask_box_switch = ctk.CTkSwitch(
|
show_mouth_mask_box_switch = ctk.CTkSwitch(
|
||||||
root,
|
root,
|
||||||
text="Show Mouth Mask Box",
|
text=_("Show Mouth Mask Box"),
|
||||||
variable=show_mouth_mask_box_var,
|
variable=show_mouth_mask_box_var,
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: setattr(
|
command=lambda: setattr(
|
||||||
|
@ -302,22 +307,22 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
show_mouth_mask_box_switch.place(relx=0.6, rely=0.55)
|
show_mouth_mask_box_switch.place(relx=0.6, rely=0.55)
|
||||||
|
|
||||||
start_button = ctk.CTkButton(
|
start_button = ctk.CTkButton(
|
||||||
root, text="Start", cursor="hand2", command=lambda: analyze_target(start, root)
|
root, text=_("Start"), cursor="hand2", command=lambda: analyze_target(start, root)
|
||||||
)
|
)
|
||||||
start_button.place(relx=0.15, rely=0.80, relwidth=0.2, relheight=0.05)
|
start_button.place(relx=0.15, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
stop_button = ctk.CTkButton(
|
stop_button = ctk.CTkButton(
|
||||||
root, text="Destroy", cursor="hand2", command=lambda: destroy()
|
root, text=_("Destroy"), cursor="hand2", command=lambda: destroy()
|
||||||
)
|
)
|
||||||
stop_button.place(relx=0.4, rely=0.80, relwidth=0.2, relheight=0.05)
|
stop_button.place(relx=0.4, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
preview_button = ctk.CTkButton(
|
preview_button = ctk.CTkButton(
|
||||||
root, text="Preview", cursor="hand2", command=lambda: toggle_preview()
|
root, text=_("Preview"), cursor="hand2", command=lambda: toggle_preview()
|
||||||
)
|
)
|
||||||
preview_button.place(relx=0.65, rely=0.80, relwidth=0.2, relheight=0.05)
|
preview_button.place(relx=0.65, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
# --- Camera Selection ---
|
# --- Camera Selection ---
|
||||||
camera_label = ctk.CTkLabel(root, text="Select Camera:")
|
camera_label = ctk.CTkLabel(root, text=_("Select Camera:"))
|
||||||
camera_label.place(relx=0.1, rely=0.86, relwidth=0.2, relheight=0.05)
|
camera_label.place(relx=0.1, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
available_cameras = get_available_cameras()
|
available_cameras = get_available_cameras()
|
||||||
|
@ -341,7 +346,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
|
|
||||||
live_button = ctk.CTkButton(
|
live_button = ctk.CTkButton(
|
||||||
root,
|
root,
|
||||||
text="Live",
|
text=_("Live"),
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: webcam_preview(
|
command=lambda: webcam_preview(
|
||||||
root,
|
root,
|
||||||
|
@ -376,6 +381,15 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
def close_mapper_window():
|
||||||
|
global POPUP, POPUP_LIVE
|
||||||
|
if POPUP and POPUP.winfo_exists():
|
||||||
|
POPUP.destroy()
|
||||||
|
POPUP = None
|
||||||
|
if POPUP_LIVE and POPUP_LIVE.winfo_exists():
|
||||||
|
POPUP_LIVE.destroy()
|
||||||
|
POPUP_LIVE = None
|
||||||
|
|
||||||
|
|
||||||
def analyze_target(start: Callable[[], None], root: ctk.CTk):
|
def analyze_target(start: Callable[[], None], root: ctk.CTk):
|
||||||
if POPUP != None and POPUP.winfo_exists():
|
if POPUP != None and POPUP.winfo_exists():
|
||||||
|
@ -401,12 +415,12 @@ def analyze_target(start: Callable[[], None], root: ctk.CTk):
|
||||||
|
|
||||||
|
|
||||||
def create_source_target_popup(
|
def create_source_target_popup(
|
||||||
start: Callable[[], None], root: ctk.CTk, map: list
|
start: Callable[[], None], root: ctk.CTk, map: list
|
||||||
) -> None:
|
) -> None:
|
||||||
global POPUP, popup_status_label
|
global POPUP, popup_status_label
|
||||||
|
|
||||||
POPUP = ctk.CTkToplevel(root)
|
POPUP = ctk.CTkToplevel(root)
|
||||||
POPUP.title("Source x Target Mapper")
|
POPUP.title(_("Source x Target Mapper"))
|
||||||
POPUP.geometry(f"{POPUP_WIDTH}x{POPUP_HEIGHT}")
|
POPUP.geometry(f"{POPUP_WIDTH}x{POPUP_HEIGHT}")
|
||||||
POPUP.focus()
|
POPUP.focus()
|
||||||
|
|
||||||
|
@ -430,7 +444,7 @@ def create_source_target_popup(
|
||||||
|
|
||||||
button = ctk.CTkButton(
|
button = ctk.CTkButton(
|
||||||
scrollable_frame,
|
scrollable_frame,
|
||||||
text="Select source image",
|
text=_("Select source image"),
|
||||||
command=lambda id=id: on_button_click(map, id),
|
command=lambda id=id: on_button_click(map, id),
|
||||||
width=DEFAULT_BUTTON_WIDTH,
|
width=DEFAULT_BUTTON_WIDTH,
|
||||||
height=DEFAULT_BUTTON_HEIGHT,
|
height=DEFAULT_BUTTON_HEIGHT,
|
||||||
|
@ -464,18 +478,18 @@ def create_source_target_popup(
|
||||||
popup_status_label.grid(row=1, column=0, pady=15)
|
popup_status_label.grid(row=1, column=0, pady=15)
|
||||||
|
|
||||||
close_button = ctk.CTkButton(
|
close_button = ctk.CTkButton(
|
||||||
POPUP, text="Submit", command=lambda: on_submit_click(start)
|
POPUP, text=_("Submit"), command=lambda: on_submit_click(start)
|
||||||
)
|
)
|
||||||
close_button.grid(row=2, column=0, pady=10)
|
close_button.grid(row=2, column=0, pady=10)
|
||||||
|
|
||||||
|
|
||||||
def update_popup_source(
|
def update_popup_source(
|
||||||
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
||||||
) -> list:
|
) -> list:
|
||||||
global source_label_dict
|
global source_label_dict
|
||||||
|
|
||||||
source_path = ctk.filedialog.askopenfilename(
|
source_path = ctk.filedialog.askopenfilename(
|
||||||
title="select an source image",
|
title=_("select an source image"),
|
||||||
initialdir=RECENT_DIRECTORY_SOURCE,
|
initialdir=RECENT_DIRECTORY_SOURCE,
|
||||||
filetypes=[img_ft],
|
filetypes=[img_ft],
|
||||||
)
|
)
|
||||||
|
@ -495,7 +509,7 @@ def update_popup_source(
|
||||||
x_min, y_min, x_max, y_max = face["bbox"]
|
x_min, y_min, x_max, y_max = face["bbox"]
|
||||||
|
|
||||||
map[button_num]["source"] = {
|
map[button_num]["source"] = {
|
||||||
"cv2": cv2_img[int(y_min) : int(y_max), int(x_min) : int(x_max)],
|
"cv2": cv2_img[int(y_min): int(y_max), int(x_min): int(x_max)],
|
||||||
"face": face,
|
"face": face,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +540,7 @@ def create_preview(parent: ctk.CTkToplevel) -> ctk.CTkToplevel:
|
||||||
|
|
||||||
preview = ctk.CTkToplevel(parent)
|
preview = ctk.CTkToplevel(parent)
|
||||||
preview.withdraw()
|
preview.withdraw()
|
||||||
preview.title("Preview")
|
preview.title(_("Preview"))
|
||||||
preview.configure()
|
preview.configure()
|
||||||
preview.protocol("WM_DELETE_WINDOW", lambda: toggle_preview())
|
preview.protocol("WM_DELETE_WINDOW", lambda: toggle_preview())
|
||||||
preview.resizable(width=True, height=True)
|
preview.resizable(width=True, height=True)
|
||||||
|
@ -542,16 +556,16 @@ def create_preview(parent: ctk.CTkToplevel) -> ctk.CTkToplevel:
|
||||||
|
|
||||||
|
|
||||||
def update_status(text: str) -> None:
|
def update_status(text: str) -> None:
|
||||||
status_label.configure(text=text)
|
status_label.configure(text=_(text))
|
||||||
ROOT.update()
|
ROOT.update()
|
||||||
|
|
||||||
|
|
||||||
def update_pop_status(text: str) -> None:
|
def update_pop_status(text: str) -> None:
|
||||||
popup_status_label.configure(text=text)
|
popup_status_label.configure(text=_(text))
|
||||||
|
|
||||||
|
|
||||||
def update_pop_live_status(text: str) -> None:
|
def update_pop_live_status(text: str) -> None:
|
||||||
popup_status_label_live.configure(text=text)
|
popup_status_label_live.configure(text=_(text))
|
||||||
|
|
||||||
|
|
||||||
def update_tumbler(var: str, value: bool) -> None:
|
def update_tumbler(var: str, value: bool) -> None:
|
||||||
|
@ -570,7 +584,7 @@ def select_source_path() -> None:
|
||||||
|
|
||||||
PREVIEW.withdraw()
|
PREVIEW.withdraw()
|
||||||
source_path = ctk.filedialog.askopenfilename(
|
source_path = ctk.filedialog.askopenfilename(
|
||||||
title="select an source image",
|
title=_("select an source image"),
|
||||||
initialdir=RECENT_DIRECTORY_SOURCE,
|
initialdir=RECENT_DIRECTORY_SOURCE,
|
||||||
filetypes=[img_ft],
|
filetypes=[img_ft],
|
||||||
)
|
)
|
||||||
|
@ -613,7 +627,7 @@ def select_target_path() -> None:
|
||||||
|
|
||||||
PREVIEW.withdraw()
|
PREVIEW.withdraw()
|
||||||
target_path = ctk.filedialog.askopenfilename(
|
target_path = ctk.filedialog.askopenfilename(
|
||||||
title="select an target image or video",
|
title=_("select an target image or video"),
|
||||||
initialdir=RECENT_DIRECTORY_TARGET,
|
initialdir=RECENT_DIRECTORY_TARGET,
|
||||||
filetypes=[img_ft, vid_ft],
|
filetypes=[img_ft, vid_ft],
|
||||||
)
|
)
|
||||||
|
@ -637,7 +651,7 @@ def select_output_path(start: Callable[[], None]) -> None:
|
||||||
|
|
||||||
if is_image(modules.globals.target_path):
|
if is_image(modules.globals.target_path):
|
||||||
output_path = ctk.filedialog.asksaveasfilename(
|
output_path = ctk.filedialog.asksaveasfilename(
|
||||||
title="save image output file",
|
title=_("save image output file"),
|
||||||
filetypes=[img_ft],
|
filetypes=[img_ft],
|
||||||
defaultextension=".png",
|
defaultextension=".png",
|
||||||
initialfile="output.png",
|
initialfile="output.png",
|
||||||
|
@ -645,7 +659,7 @@ def select_output_path(start: Callable[[], None]) -> None:
|
||||||
)
|
)
|
||||||
elif is_video(modules.globals.target_path):
|
elif is_video(modules.globals.target_path):
|
||||||
output_path = ctk.filedialog.asksaveasfilename(
|
output_path = ctk.filedialog.asksaveasfilename(
|
||||||
title="save video output file",
|
title=_("save video output file"),
|
||||||
filetypes=[vid_ft],
|
filetypes=[vid_ft],
|
||||||
defaultextension=".mp4",
|
defaultextension=".mp4",
|
||||||
initialfile="output.mp4",
|
initialfile="output.mp4",
|
||||||
|
@ -704,7 +718,7 @@ def render_image_preview(image_path: str, size: Tuple[int, int]) -> ctk.CTkImage
|
||||||
|
|
||||||
|
|
||||||
def render_video_preview(
|
def render_video_preview(
|
||||||
video_path: str, size: Tuple[int, int], frame_number: int = 0
|
video_path: str, size: Tuple[int, int], frame_number: int = 0
|
||||||
) -> ctk.CTkImage:
|
) -> ctk.CTkImage:
|
||||||
capture = cv2.VideoCapture(video_path)
|
capture = cv2.VideoCapture(video_path)
|
||||||
if frame_number:
|
if frame_number:
|
||||||
|
@ -744,7 +758,7 @@ def update_preview(frame_number: int = 0) -> None:
|
||||||
if modules.globals.nsfw_filter and check_and_ignore_nsfw(temp_frame):
|
if modules.globals.nsfw_filter and check_and_ignore_nsfw(temp_frame):
|
||||||
return
|
return
|
||||||
for frame_processor in get_frame_processors_modules(
|
for frame_processor in get_frame_processors_modules(
|
||||||
modules.globals.frame_processors
|
modules.globals.frame_processors
|
||||||
):
|
):
|
||||||
temp_frame = frame_processor.process_frame(
|
temp_frame = frame_processor.process_frame(
|
||||||
get_one_face(cv2.imread(modules.globals.source_path)), temp_frame
|
get_one_face(cv2.imread(modules.globals.source_path)), temp_frame
|
||||||
|
@ -760,6 +774,13 @@ def update_preview(frame_number: int = 0) -> None:
|
||||||
|
|
||||||
|
|
||||||
def webcam_preview(root: ctk.CTk, camera_index: int):
|
def webcam_preview(root: ctk.CTk, camera_index: int):
|
||||||
|
global POPUP_LIVE
|
||||||
|
|
||||||
|
if POPUP_LIVE and POPUP_LIVE.winfo_exists():
|
||||||
|
update_status("Source x Target Mapper is already open.")
|
||||||
|
POPUP_LIVE.focus()
|
||||||
|
return
|
||||||
|
|
||||||
if not modules.globals.map_faces:
|
if not modules.globals.map_faces:
|
||||||
if modules.globals.source_path is None:
|
if modules.globals.source_path is None:
|
||||||
update_status("Please select a source image first")
|
update_status("Please select a source image first")
|
||||||
|
@ -772,6 +793,7 @@ def webcam_preview(root: ctk.CTk, camera_index: int):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_available_cameras():
|
def get_available_cameras():
|
||||||
"""Returns a list of available camera names and indices."""
|
"""Returns a list of available camera names and indices."""
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
@ -819,7 +841,7 @@ def get_available_cameras():
|
||||||
camera_indices.append(0)
|
camera_indices.append(0)
|
||||||
camera_names.append("FaceTime Camera")
|
camera_names.append("FaceTime Camera")
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
||||||
# On macOS, additional cameras typically use indices 1 and 2
|
# On macOS, additional cameras typically use indices 1 and 2
|
||||||
for i in [1, 2]:
|
for i in [1, 2]:
|
||||||
cap = cv2.VideoCapture(i)
|
cap = cv2.VideoCapture(i)
|
||||||
|
@ -935,20 +957,20 @@ def create_webcam_preview(camera_index: int):
|
||||||
|
|
||||||
|
|
||||||
def create_source_target_popup_for_webcam(
|
def create_source_target_popup_for_webcam(
|
||||||
root: ctk.CTk, map: list, camera_index: int
|
root: ctk.CTk, map: list, camera_index: int
|
||||||
) -> None:
|
) -> None:
|
||||||
global POPUP_LIVE, popup_status_label_live
|
global POPUP_LIVE, popup_status_label_live
|
||||||
|
|
||||||
POPUP_LIVE = ctk.CTkToplevel(root)
|
POPUP_LIVE = ctk.CTkToplevel(root)
|
||||||
POPUP_LIVE.title("Source x Target Mapper")
|
POPUP_LIVE.title(_("Source x Target Mapper"))
|
||||||
POPUP_LIVE.geometry(f"{POPUP_LIVE_WIDTH}x{POPUP_LIVE_HEIGHT}")
|
POPUP_LIVE.geometry(f"{POPUP_LIVE_WIDTH}x{POPUP_LIVE_HEIGHT}")
|
||||||
POPUP_LIVE.focus()
|
POPUP_LIVE.focus()
|
||||||
|
|
||||||
def on_submit_click():
|
def on_submit_click():
|
||||||
if has_valid_map():
|
if has_valid_map():
|
||||||
POPUP_LIVE.destroy()
|
|
||||||
simplify_maps()
|
simplify_maps()
|
||||||
create_webcam_preview(camera_index)
|
update_pop_live_status("Mappings successfully submitted!")
|
||||||
|
create_webcam_preview(camera_index) # Open the preview window
|
||||||
else:
|
else:
|
||||||
update_pop_live_status("At least 1 source with target is required!")
|
update_pop_live_status("At least 1 source with target is required!")
|
||||||
|
|
||||||
|
@ -957,16 +979,43 @@ def create_source_target_popup_for_webcam(
|
||||||
refresh_data(map)
|
refresh_data(map)
|
||||||
update_pop_live_status("Please provide mapping!")
|
update_pop_live_status("Please provide mapping!")
|
||||||
|
|
||||||
|
def on_clear_click():
|
||||||
|
clear_source_target_images(map)
|
||||||
|
refresh_data(map)
|
||||||
|
update_pop_live_status("All mappings cleared!")
|
||||||
|
|
||||||
popup_status_label_live = ctk.CTkLabel(POPUP_LIVE, text=None, justify="center")
|
popup_status_label_live = ctk.CTkLabel(POPUP_LIVE, text=None, justify="center")
|
||||||
popup_status_label_live.grid(row=1, column=0, pady=15)
|
popup_status_label_live.grid(row=1, column=0, pady=15)
|
||||||
|
|
||||||
add_button = ctk.CTkButton(POPUP_LIVE, text="Add", command=lambda: on_add_click())
|
add_button = ctk.CTkButton(POPUP_LIVE, text=_("Add"), command=lambda: on_add_click())
|
||||||
add_button.place(relx=0.2, rely=0.92, relwidth=0.2, relheight=0.05)
|
add_button.place(relx=0.1, rely=0.92, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
|
clear_button = ctk.CTkButton(POPUP_LIVE, text=_("Clear"), command=lambda: on_clear_click())
|
||||||
|
clear_button.place(relx=0.4, rely=0.92, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
close_button = ctk.CTkButton(
|
close_button = ctk.CTkButton(
|
||||||
POPUP_LIVE, text="Submit", command=lambda: on_submit_click()
|
POPUP_LIVE, text=_("Submit"), command=lambda: on_submit_click()
|
||||||
)
|
)
|
||||||
close_button.place(relx=0.6, rely=0.92, relwidth=0.2, relheight=0.05)
|
close_button.place(relx=0.7, rely=0.92, relwidth=0.2, relheight=0.05)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def clear_source_target_images(map: list):
|
||||||
|
global source_label_dict_live, target_label_dict_live
|
||||||
|
|
||||||
|
for item in map:
|
||||||
|
if "source" in item:
|
||||||
|
del item["source"]
|
||||||
|
if "target" in item:
|
||||||
|
del item["target"]
|
||||||
|
|
||||||
|
for button_num in list(source_label_dict_live.keys()):
|
||||||
|
source_label_dict_live[button_num].destroy()
|
||||||
|
del source_label_dict_live[button_num]
|
||||||
|
|
||||||
|
for button_num in list(target_label_dict_live.keys()):
|
||||||
|
target_label_dict_live[button_num].destroy()
|
||||||
|
del target_label_dict_live[button_num]
|
||||||
|
|
||||||
|
|
||||||
def refresh_data(map: list):
|
def refresh_data(map: list):
|
||||||
|
@ -988,7 +1037,7 @@ def refresh_data(map: list):
|
||||||
|
|
||||||
button = ctk.CTkButton(
|
button = ctk.CTkButton(
|
||||||
scrollable_frame,
|
scrollable_frame,
|
||||||
text="Select source image",
|
text=_("Select source image"),
|
||||||
command=lambda id=id: on_sbutton_click(map, id),
|
command=lambda id=id: on_sbutton_click(map, id),
|
||||||
width=DEFAULT_BUTTON_WIDTH,
|
width=DEFAULT_BUTTON_WIDTH,
|
||||||
height=DEFAULT_BUTTON_HEIGHT,
|
height=DEFAULT_BUTTON_HEIGHT,
|
||||||
|
@ -1005,7 +1054,7 @@ def refresh_data(map: list):
|
||||||
|
|
||||||
button = ctk.CTkButton(
|
button = ctk.CTkButton(
|
||||||
scrollable_frame,
|
scrollable_frame,
|
||||||
text="Select target image",
|
text=_("Select target image"),
|
||||||
command=lambda id=id: on_tbutton_click(map, id),
|
command=lambda id=id: on_tbutton_click(map, id),
|
||||||
width=DEFAULT_BUTTON_WIDTH,
|
width=DEFAULT_BUTTON_WIDTH,
|
||||||
height=DEFAULT_BUTTON_HEIGHT,
|
height=DEFAULT_BUTTON_HEIGHT,
|
||||||
|
@ -1050,12 +1099,12 @@ def refresh_data(map: list):
|
||||||
|
|
||||||
|
|
||||||
def update_webcam_source(
|
def update_webcam_source(
|
||||||
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
||||||
) -> list:
|
) -> list:
|
||||||
global source_label_dict_live
|
global source_label_dict_live
|
||||||
|
|
||||||
source_path = ctk.filedialog.askopenfilename(
|
source_path = ctk.filedialog.askopenfilename(
|
||||||
title="select an source image",
|
title=_("select an source image"),
|
||||||
initialdir=RECENT_DIRECTORY_SOURCE,
|
initialdir=RECENT_DIRECTORY_SOURCE,
|
||||||
filetypes=[img_ft],
|
filetypes=[img_ft],
|
||||||
)
|
)
|
||||||
|
@ -1075,7 +1124,7 @@ def update_webcam_source(
|
||||||
x_min, y_min, x_max, y_max = face["bbox"]
|
x_min, y_min, x_max, y_max = face["bbox"]
|
||||||
|
|
||||||
map[button_num]["source"] = {
|
map[button_num]["source"] = {
|
||||||
"cv2": cv2_img[int(y_min) : int(y_max), int(x_min) : int(x_max)],
|
"cv2": cv2_img[int(y_min): int(y_max), int(x_min): int(x_max)],
|
||||||
"face": face,
|
"face": face,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1102,12 +1151,12 @@ def update_webcam_source(
|
||||||
|
|
||||||
|
|
||||||
def update_webcam_target(
|
def update_webcam_target(
|
||||||
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
|
||||||
) -> list:
|
) -> list:
|
||||||
global target_label_dict_live
|
global target_label_dict_live
|
||||||
|
|
||||||
target_path = ctk.filedialog.askopenfilename(
|
target_path = ctk.filedialog.askopenfilename(
|
||||||
title="select an target image",
|
title=_("select an target image"),
|
||||||
initialdir=RECENT_DIRECTORY_SOURCE,
|
initialdir=RECENT_DIRECTORY_SOURCE,
|
||||||
filetypes=[img_ft],
|
filetypes=[img_ft],
|
||||||
)
|
)
|
||||||
|
@ -1127,7 +1176,7 @@ def update_webcam_target(
|
||||||
x_min, y_min, x_max, y_max = face["bbox"]
|
x_min, y_min, x_max, y_max = face["bbox"]
|
||||||
|
|
||||||
map[button_num]["target"] = {
|
map[button_num]["target"] = {
|
||||||
"cv2": cv2_img[int(y_min) : int(y_max), int(x_min) : int(x_max)],
|
"cv2": cv2_img[int(y_min): int(y_max), int(x_min): int(x_max)],
|
||||||
"face": face,
|
"face": face,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1150,4 +1199,4 @@ def update_webcam_target(
|
||||||
target_label_dict_live[button_num] = target_image
|
target_label_dict_live[button_num] = target_image
|
||||||
else:
|
else:
|
||||||
update_pop_live_status("Face could not be detected in last upload!")
|
update_pop_live_status("Face could not be detected in last upload!")
|
||||||
return map
|
return map
|
Loading…
Reference in New Issue