def img_load(path, w, h, resize=True): img = cv2_imread(path) if len(img.shape) == 2: img = np.dstack((img, img, img)) if resize: img = cv2_resize(img, (w, h)).astype(np.uint8) img = cvtColor(img, COLOR_BGR2RGB) return img
def predict_eye_state(self, image): """Treatment of crop for model prediction""" image = cv2_resize(image, (20, 10)) image = image.astype(dtype=np.float32) image_batch = np.reshape(image, (1, 10, 20, 1)) image_batch = keras_preprocess_input(image_batch) pred = np.argmax(self.model.predict(image_batch)[0]) return pred
def face_detection_with_face_recognition(self, rgb_frame): """I dont understand you can see the github in ciration in (blink models)""" original_height, original_width = rgb_frame.shape[:2] resized_image = cv2_resize(rgb_frame, (0, 0), fx=self.scale, fy=self.scale) lab = cv2_cvtColor(resized_image, cv2_COLOR_BGR2LAB) l, _, _ = cv2_split(lab) resized_height, resized_width = l.shape[:2] height_ratio, width_ratio = original_height / resized_height, original_width / resized_width face_loc = face_locations(l, model='hog') return face_loc, height_ratio, width_ratio
def crop(image, params): height, width = image.shape[:2] dst_height = int(height * params['central_fraction']) dst_width = int(width * params['central_fraction']) if height < dst_height or width < dst_width: resized = np.array([width, height]) if width < dst_width: resized *= dst_width / width if height < dst_height: resized *= dst_height / height image = cv2_resize(image, tuple(np.ceil(resized).astype(int))) top_left_y = (height - dst_height) // 2 top_left_x = (width - dst_width) // 2 return image[top_left_y:top_left_y + dst_height, top_left_x:top_left_x + dst_width]
def resize(image, params): shape = params['height'], params['width'] return cv2_resize(image, shape)
def get_im_cv2_1024(path): img = cv2_imread(path) resized = cv2_resize(img, (1024, 1024), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_512(path): img = cv2_imread(path) resized = cv2_resize(img, (512, 512), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_256(path): img = cv2_imread(path) resized = cv2_resize(img, (256, 256), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_64(path): img = cv2_imread(path) resized = cv2_resize(img, (64, 64), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_32(path): img = cv2_imread(path) resized = cv2_resize( img, (32, 32), cv2_INTER_AREA) #use cv2_resize(img, (64, 64), cv2_INTER_AREA) return [path, resized]