Compare commits

..

1 Commits

Author SHA1 Message Date
Kshamendra 77909a07fa
Merge 874ccbbbe0 into bdd7c593e1 2024-10-02 20:52:42 +05:30
2 changed files with 24 additions and 27 deletions

View File

@ -3,7 +3,6 @@ import webbrowser
import customtkinter as ctk
from typing import Callable, Tuple
import cv2
from cv2_enumerate_cameras import enumerate_cameras
from PIL import Image, ImageOps
import tkinterdnd2 as tkdnd
import time
@ -404,12 +403,20 @@ def create_root(
)
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_label = ctk.CTkLabel(root, text="Select Camera:")
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
available_camera_indices, available_camera_strings = available_cameras
available_camera_strings = [str(cam) for cam in available_cameras]
camera_variable = ctk.StringVar(
value=available_camera_strings[0]
if available_camera_strings
@ -419,20 +426,14 @@ def create_root(
root, variable=camera_variable, values=available_camera_strings
)
camera_optionmenu.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05)
# --- End Camera Selection ---
live_button = ModernButton(
button_frame,
live_button = ctk.CTkButton(
root,
text="Live",
cursor="hand2",
command=lambda: webcam_preview(
root,
available_camera_indices[
available_camera_strings.index(camera_variable.get())
],
),
command=lambda: webcam_preview(int(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(
button_frame,
@ -1011,24 +1012,21 @@ def webcam_preview(root: ctk.CTk, camera_index: int):
if modules.globals.source_path is None:
# No image selected
return
create_webcam_preview(camera_index)
create_webcam_preview()
else:
modules.globals.souce_target_map = []
create_source_target_popup_for_webcam(root, modules.globals.souce_target_map)
def get_available_cameras():
"""Returns a list of available camera names and indices."""
camera_indices = []
camera_names = []
for camera in enumerate_cameras():
cap = cv2.VideoCapture(camera.index)
def get_available_cameras(max_cameras=10):
"""Returns a list of available camera indices."""
available_cameras = []
for i in range(max_cameras):
cap = cv2.VideoCapture(i)
if cap.isOpened():
camera_indices.append(camera.index)
camera_names.append(camera.name)
available_cameras.append(i)
cap.release()
return (camera_indices, camera_names)
return available_cameras
# 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
def create_webcam_preview(camera_index):
def create_webcam_preview():
global preview_label, PREVIEW
camera = cv2.VideoCapture(camera_index)

View File

@ -2,7 +2,6 @@
numpy>=1.23.5,<2
opencv-python==4.8.1.78
cv2_enumerate_cameras==1.1.15
onnx==1.16.0
insightface==0.7.3
psutil==5.9.8