Update ui.py
Added: - try-finally Block: This makes sure the camera.release() is called no matter how the while loops end. - Resource Cleanup: The finally block takes care of cleaning up resources to keep the application stable.
This commit is contained in:
@@ -795,6 +795,7 @@ def create_webcam_preview(camera_index: int):
|
|||||||
frame_count = 0
|
frame_count = 0
|
||||||
fps = 0
|
fps = 0
|
||||||
|
|
||||||
|
try:
|
||||||
while camera:
|
while camera:
|
||||||
ret, frame = camera.read()
|
ret, frame = camera.read()
|
||||||
if not ret:
|
if not ret:
|
||||||
@@ -860,11 +861,12 @@ def create_webcam_preview(camera_index: int):
|
|||||||
|
|
||||||
if PREVIEW.state() == "withdrawn":
|
if PREVIEW.state() == "withdrawn":
|
||||||
break
|
break
|
||||||
|
finally:
|
||||||
camera.release()
|
camera.release()
|
||||||
PREVIEW.withdraw()
|
PREVIEW.withdraw()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user