@@ -19,9 +19,7 @@ class CameraStrategy(BaseEyeStrategy):
1919 The camera strategy for eye strategies.
2020 """
2121 def __init__ (self , camera_id : int = 0 ):
22- self ._camera = cv2 .VideoCapture (camera_id )
23- if not self ._camera .isOpened ():
24- raise RuntimeError ('Could not start camera.' )
22+ self ._camera_id = camera_id
2523
2624 def check_if_detected (self ) -> EyeStrategyResult :
2725 """This method checks if there are any protectors around."""
@@ -41,8 +39,15 @@ def check_if_detected(self) -> EyeStrategyResult:
4139 # Internal methods.
4240 def _get_frame (self ) -> numpy .ndarray :
4341 """This method returns the frame from the camera."""
42+ # Create a camera object.
43+ camera = cv2 .VideoCapture (self ._camera_id )
44+ # Set the camera resolution.
45+ camera .set (3 , 640 )
46+ camera .set (4 , 480 )
4447 # Read the frame from the camera.
45- _ , frame = self ._camera .read ()
48+ _ , frame = camera .read ()
49+ # Release the camera.
50+ camera .release ()
4651 return frame
4752
4853 def _detect_humans (self , frame : numpy .ndarray ) -> tuple [list [tuple [int , int , int , int ]], float ]:
@@ -54,7 +59,7 @@ def _detect_humans(self, frame: numpy.ndarray) -> tuple[list[tuple[int, int, int
5459 frame ,
5560 winStride = (4 , 4 ),
5661 padding = (4 , 4 ),
57- scale = 1.05
62+ scale = 1.00
5863 )
5964 logger .debug ("Number of detections: " + str (num_detections )
6065 + " Regions: " + str (regions ))
0 commit comments