@@ -73,6 +73,7 @@ class VideoCaptureWorker(QThread):
7373
7474 frame_ready = pyqtSignal (object )
7575 capture_requested = pyqtSignal ()
76+ camera_error = pyqtSignal (str ) # Signal for camera initialization errors
7677
7778 def __init__ (self , canvas_width , canvas_height , video_device_idx = 0 ):
7879 super ().__init__ ()
@@ -136,7 +137,9 @@ def _capture_frame(self):
136137 self .video_device .setCamera (self .video_device_idx )
137138 self .camera_initialised = True
138139 except Exception as e :
139- logging .error (f"Failed to set camera index { self .video_device_idx } : { e } " )
140+ error_msg = f"Failed to initialize camera { self .video_device_idx } : { e } "
141+ logging .error (error_msg )
142+ self .camera_error .emit (error_msg )
140143 return
141144
142145 # Capture frame - avoid color conversion if not necessary
@@ -478,6 +481,7 @@ def __init_video(self):
478481 self .window_default_width , self .window_default_height , 0
479482 )
480483 self .video_worker .frame_ready .connect (self ._on_frame_ready )
484+ self .video_worker .camera_error .connect (self ._on_camera_initialization_error )
481485 self .video_worker .start ()
482486
483487 # Wire focus signals from the view back to the main window handlers.
@@ -863,6 +867,19 @@ def _on_camera_enumeration_error(self, error_msg):
863867 self .video_devices = []
864868 self .video_device_var = "Error"
865869
870+ def _on_camera_initialization_error (self , error_msg ):
871+ """
872+ Callback when camera initialization/verification fails.
873+ Shows error to user and allows them to select a different camera.
874+ """
875+ logging .error (f"Camera initialization error: { error_msg } " )
876+ QMessageBox .critical (
877+ self ,
878+ "Camera Error" ,
879+ f"{ error_msg } \n \n Please select a different camera from the Video menu." ,
880+ )
881+ self .video_device_var = "Error"
882+
866883 def _populate_video_device_menu (self ):
867884 """
868885 Populate the video device dropdown menu with available video devices.
0 commit comments