Compare commits
1 Commits
3ba69ca00b
...
77909a07fa
Author | SHA1 | Date |
---|---|---|
|
77909a07fa |
modules
|
@ -3,7 +3,6 @@ import webbrowser
|
||||||
import customtkinter as ctk
|
import customtkinter as ctk
|
||||||
from typing import Callable, Tuple
|
from typing import Callable, Tuple
|
||||||
import cv2
|
import cv2
|
||||||
from cv2_enumerate_cameras import enumerate_cameras
|
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
import tkinterdnd2 as tkdnd
|
import tkinterdnd2 as tkdnd
|
||||||
import time
|
import time
|
||||||
|
@ -404,12 +403,20 @@ def create_root(
|
||||||
)
|
)
|
||||||
preview_button.pack(side="left", padx=10, expand=True)
|
preview_button.pack(side="left", padx=10, expand=True)
|
||||||
|
|
||||||
|
live_button = ModernButton(
|
||||||
|
button_frame,
|
||||||
|
text="Live",
|
||||||
|
cursor="hand2",
|
||||||
|
command=lambda: webcam_preview(root),
|
||||||
|
)
|
||||||
|
live_button.pack(side="left", padx=10, expand=True)
|
||||||
|
|
||||||
# --- 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.4, rely=0.86, relwidth=0.2, relheight=0.05)
|
camera_label.place(relx=0.4, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||||
available_cameras = get_available_cameras()
|
available_cameras = get_available_cameras(10)
|
||||||
# Convert camera indices to strings for CTkOptionMenu
|
# Convert camera indices to strings for CTkOptionMenu
|
||||||
available_camera_indices, available_camera_strings = available_cameras
|
available_camera_strings = [str(cam) for cam in available_cameras]
|
||||||
camera_variable = ctk.StringVar(
|
camera_variable = ctk.StringVar(
|
||||||
value=available_camera_strings[0]
|
value=available_camera_strings[0]
|
||||||
if available_camera_strings
|
if available_camera_strings
|
||||||
|
@ -419,20 +426,14 @@ def create_root(
|
||||||
root, variable=camera_variable, values=available_camera_strings
|
root, variable=camera_variable, values=available_camera_strings
|
||||||
)
|
)
|
||||||
camera_optionmenu.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05)
|
camera_optionmenu.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||||
# --- End Camera Selection ---
|
live_button = ctk.CTkButton(
|
||||||
|
root,
|
||||||
live_button = ModernButton(
|
|
||||||
button_frame,
|
|
||||||
text="Live",
|
text="Live",
|
||||||
cursor="hand2",
|
cursor="hand2",
|
||||||
command=lambda: webcam_preview(
|
command=lambda: webcam_preview(int(camera_variable.get())),
|
||||||
root,
|
|
||||||
available_camera_indices[
|
|
||||||
available_camera_strings.index(camera_variable.get())
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
live_button.pack(side="left", padx=10, expand=True)
|
live_button.place(relx=0.15, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||||
|
# --- End Camera Selection ---
|
||||||
|
|
||||||
stop_button = ModernButton(
|
stop_button = ModernButton(
|
||||||
button_frame,
|
button_frame,
|
||||||
|
@ -1011,24 +1012,21 @@ def webcam_preview(root: ctk.CTk, camera_index: int):
|
||||||
if modules.globals.source_path is None:
|
if modules.globals.source_path is None:
|
||||||
# No image selected
|
# No image selected
|
||||||
return
|
return
|
||||||
create_webcam_preview(camera_index)
|
create_webcam_preview()
|
||||||
else:
|
else:
|
||||||
modules.globals.souce_target_map = []
|
modules.globals.souce_target_map = []
|
||||||
create_source_target_popup_for_webcam(root, modules.globals.souce_target_map)
|
create_source_target_popup_for_webcam(root, modules.globals.souce_target_map)
|
||||||
|
|
||||||
|
|
||||||
def get_available_cameras():
|
def get_available_cameras(max_cameras=10):
|
||||||
"""Returns a list of available camera names and indices."""
|
"""Returns a list of available camera indices."""
|
||||||
camera_indices = []
|
available_cameras = []
|
||||||
camera_names = []
|
for i in range(max_cameras):
|
||||||
|
cap = cv2.VideoCapture(i)
|
||||||
for camera in enumerate_cameras():
|
|
||||||
cap = cv2.VideoCapture(camera.index)
|
|
||||||
if cap.isOpened():
|
if cap.isOpened():
|
||||||
camera_indices.append(camera.index)
|
available_cameras.append(i)
|
||||||
camera_names.append(camera.name)
|
|
||||||
cap.release()
|
cap.release()
|
||||||
return (camera_indices, camera_names)
|
return available_cameras
|
||||||
|
|
||||||
|
|
||||||
# Add this function to update the opacity value
|
# Add this function to update the opacity value
|
||||||
|
@ -1037,7 +1035,7 @@ def update_opacity(value):
|
||||||
|
|
||||||
|
|
||||||
# Modify the create_webcam_preview function to include the slider
|
# Modify the create_webcam_preview function to include the slider
|
||||||
def create_webcam_preview(camera_index):
|
def create_webcam_preview():
|
||||||
global preview_label, PREVIEW
|
global preview_label, PREVIEW
|
||||||
|
|
||||||
camera = cv2.VideoCapture(camera_index)
|
camera = cv2.VideoCapture(camera_index)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
numpy>=1.23.5,<2
|
numpy>=1.23.5,<2
|
||||||
opencv-python==4.8.1.78
|
opencv-python==4.8.1.78
|
||||||
cv2_enumerate_cameras==1.1.15
|
|
||||||
onnx==1.16.0
|
onnx==1.16.0
|
||||||
insightface==0.7.3
|
insightface==0.7.3
|
||||||
psutil==5.9.8
|
psutil==5.9.8
|
||||||
|
|
Loading…
Reference in New Issue