@ -795,74 +795,76 @@ def create_webcam_preview(camera_index: int):
frame_count = 0
frame_count = 0
fps = 0
fps = 0
while camera :
try :
ret , frame = camera . read ( )
while camera :
if not ret :
ret , frame = camera . read ( )
break
if not ret :
break
temp_frame = frame . copy ( )
temp_frame = frame . copy ( )
if modules . globals . live_mirror :
temp_frame = cv2 . flip ( temp_frame , 1 )
if modules . globals . live_mirror :
temp_frame = cv2 . flip ( temp_frame , 1 )
if modules . globals . live_resizable :
temp_frame = fit_image_to_size (
if modules . globals . live_resizable :
temp_frame , PREVIEW . winfo_width ( ) , PREVIEW . winfo_height ( )
temp_frame = fit_image_to_size (
)
temp_frame , PREVIEW . winfo_width ( ) , PREVIEW . winfo_height ( )
)
if not modules . globals . map_faces :
if source_image is None and modules . globals . source_path :
if not modules . globals . map_faces :
source_image = get_one_face ( cv2 . imread ( modules . globals . source_path ) )
if source_image is None and modules . globals . source_path :
source_image = get_one_face ( cv2 . imread ( modules . globals . source_path ) )
for frame_processor in frame_processors :
if frame_processor . NAME == " DLC.FACE-ENHANCER " :
for frame_processor in frame_processors :
if modules . globals . fp_ui [ " face_enhancer " ] :
if frame_processor . NAME == " DLC.FACE-ENHANCER " :
temp_frame = frame_processor . process_frame ( None , temp_frame )
if modules . globals . fp_ui [ " face_enhancer " ] :
else :
temp_frame = frame_processor . process_frame ( None , temp_frame )
temp_frame = frame_processor . process_frame ( source_image , temp_frame )
else :
else :
temp_frame = frame_processor . process_frame ( source_image , temp_frame )
modules . globals . target_path = None
else :
modules . globals . target_path = None
for frame_processor in frame_processors :
if frame_processor . NAME == " DLC.FACE-ENHANCER " :
for frame_processor in frame_processors :
if modules . globals . fp_ui [ " face_enhancer " ] :
if frame_processor . NAME == " DLC.FACE-ENHANCER " :
if modules . globals . fp_ui [ " face_enhancer " ] :
temp_frame = frame_processor . process_frame_v2 ( temp_frame )
else :
temp_frame = frame_processor . process_frame_v2 ( temp_frame )
temp_frame = frame_processor . process_frame_v2 ( temp_frame )
else :
temp_frame = frame_processor . process_frame_v2 ( temp_frame )
# Calculate and display FPS
current_time = time . time ( )
frame_count + = 1
if current_time - prev_time > = fps_update_interval :
fps = frame_count / ( current_time - prev_time )
frame_count = 0
prev_time = current_time
if modules . globals . show_fps :
cv2 . putText (
temp_frame ,
f " FPS: { fps : .1f } " ,
( 10 , 30 ) ,
cv2 . FONT_HERSHEY_SIMPLEX ,
1 ,
( 0 , 255 , 0 ) ,
2 ,
)
image = cv2 . cvtColor ( temp_frame , cv2 . COLOR_BGR2RGB )
# Calculate and display FPS
image = Image . fromarray ( image )
current_time = time . time ( )
image = ImageOps . contain (
frame_count + = 1
image , ( temp_frame . shape [ 1 ] , temp_frame . shape [ 0 ] ) , Image . LANCZOS
if current_time - prev_time > = fps_update_interval :
)
fps = frame_count / ( current_time - prev_time )
image = ctk . CTkImage ( image , size = image . size )
frame_count = 0
preview_label . configure ( image = image )
prev_time = current_time
ROOT . update ( )
if modules . globals . show_fps :
if PREVIEW . state ( ) == " withdrawn " :
cv2 . putText (
break
temp_frame ,
f " FPS: { fps : .1f } " ,
( 10 , 30 ) ,
cv2 . FONT_HERSHEY_SIMPLEX ,
1 ,
( 0 , 255 , 0 ) ,
2 ,
)
image = cv2 . cvtColor ( temp_frame , cv2 . COLOR_BGR2RGB )
image = Image . fromarray ( image )
image = ImageOps . contain (
image , ( temp_frame . shape [ 1 ] , temp_frame . shape [ 0 ] ) , Image . LANCZOS
)
image = ctk . CTkImage ( image , size = image . size )
preview_label . configure ( image = image )
ROOT . update ( )
if PREVIEW . state ( ) == " withdrawn " :
break
finally :
camera . release ( )
PREVIEW . withdraw ( )
camera . release ( )
PREVIEW . withdraw ( )
def create_source_target_popup_for_webcam (
def create_source_target_popup_for_webcam (