@@ -16,10 +16,6 @@ def __init__(self, model_path: str):
1616 self .isGrayscale = False
1717
1818 def init (self ):
19- if psutil .OSX or psutil .MACOS :
20- print ('Make sure that video devices access is granted for your application.' )
21- print ('If your video device is not responding, try running "tccutil reset Camera" to reset the camera access privileges' )
22-
2319 model_info = super (ImageImpulseRunner , self ).init ()
2420 width = model_info ['model_parameters' ]['image_input_width' ];
2521 height = model_info ['model_parameters' ]['image_input_height' ];
@@ -44,23 +40,36 @@ def __exit__(self, type, value, traceback):
4440 def classify (self , data ):
4541 return super (ImageImpulseRunner , self ).classify (data )
4642
43+ # This returns images in RGB format (not BGR)
4744 def get_frames (self , videoDeviceId = 0 ):
45+ if psutil .OSX or psutil .MACOS :
46+ print ('Make sure to grant the this script access to your webcam.' )
47+ print ('If your webcam is not responding, try running "tccutil reset Camera" to reset the camera access privileges.' )
48+
4849 self .videoCapture = cv2 .VideoCapture (videoDeviceId )
4950 while not self .closed :
5051 success , img = self .videoCapture .read ()
52+ img = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
5153 if success :
5254 yield img
5355
56+ # This returns images in RGB format (not BGR)
5457 def classifier (self , videoDeviceId = 0 ):
58+ if psutil .OSX or psutil .MACOS :
59+ print ('Make sure to grant the this script access to your webcam.' )
60+ print ('If your webcam is not responding, try running "tccutil reset Camera" to reset the camera access privileges.' )
61+
5562 self .videoCapture = cv2 .VideoCapture (videoDeviceId )
5663 while not self .closed :
5764 success , img = self .videoCapture .read ()
5865 if success :
66+ img = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
5967 features , cropped = self .get_features_from_image (img )
6068
6169 res = self .classify (features )
6270 yield res , cropped
6371
72+ # This expects images in RGB format (not BGR)
6473 def get_features_from_image (self , img , crop_direction_x = 'center' , crop_direction_y = 'center' ):
6574 features = []
6675
0 commit comments