def _create_output_img(self, frame, y_offset_ratio=1): """Create projections rotated by 'angle' deg. CCW Args: frame -- processed frame y_offset_ratio -- mask y coord offset ratio Returns: output_img -- resulting img. """ # Create blank output_img output_img = np.zeros( (self.output_img_height, self.output_img_width, 3), np.uint8) # Calculate frame position in the output_img frame_x = self.output_img_centre_x - self.width // 2 frame_y = self.output_img_centre_y - self.height * y_offset_ratio # Apply triangle mask on projection projection = apply_mask(frame, self.mask) # Apply projection to Bottom Centre of output_img output_img[frame_y : frame_y + self.height, \ frame_x : frame_x + self.width] = projection # Add Top projection output_img = cv2.add(output_img, cv2.flip(output_img, -1)) # Add Left and Right projections output_img = cv2.add(output_img, cv2.flip(cv2.transpose(output_img), 1)) return output_img
def _apply_settings(self, frame): """Apply custom settings received from GUI (in self.pos). Args: frame -- original frame Returns: result -- modified frame according to users adjustments """ # Translate frame to (i_x, i_y) if (self.pos['i_x'] != 0) or (self.pos['i_y'] != 0): frame = translate(frame, int(self.pos['i_x']), \ int(self.pos['i_y'])) # Scale frame if self.pos['scale'] != 1: frame_scaled = scale(frame, self.pos['scale']) frame = fit_into(frame_scaled, self.height, self.width) # Adjust brightness/contrast result = frame.copy() result = brightness_contrast(result, self.pos['contrast'], \ self.pos['brightness']) # Apply face detection mask (if ON) if self.pos['tracking_on']: if self.face_ex == None: self.face_ex = FaceDetection(self.height, self.width) tr_mask = self.face_ex.track_faces(frame) result = apply_mask(result, tr_mask) # GrabCut face(fg) extraction if self.pos['gc_iters'] > 0: gc_mask = self.grab_cut.gc_mask( img=frame, \ iters=self.pos['gc_iters']) result = apply_mask(result, gc_mask) # Create triangle mask # Add decorator here self.mask = create_triangle_mask(height=self.height, \ width=self.width, \ side=self.pos['m_side'], \ centre=self.pos['m_cntr'], \ bottom=self.pos['m_btm']) self.cap.loop_video = self.pos['loop_video'] return result
def _apply_settings(self, frame): """Apply custom settings received from GUI (in self.pos). Args: frame -- original frame Returns: result -- modified frame according to users adjustments """ # Translate frame to (i_x, i_y) if (self.pos['i_x'] != 0)or(self.pos['i_y'] != 0): frame = translate(frame, int(self.pos['i_x']), \ int(self.pos['i_y'])) # Scale frame if self.pos['scale'] != 1: frame_scaled = scale(frame, self.pos['scale']) frame = fit_into(frame_scaled, self.height, self.width) # Adjust brightness/contrast result = frame.copy() result = brightness_contrast(result, self.pos['contrast'], \ self.pos['brightness']) # Apply face detection mask (if ON) if self.pos['tracking_on']: if self.face_ex == None: self.face_ex = FaceDetection(self.height, self.width) tr_mask = self.face_ex.track_faces(frame) result = apply_mask(result, tr_mask) # GrabCut face(fg) extraction if self.pos['gc_iters'] > 0: gc_mask = self.grab_cut.gc_mask( img=frame, \ iters=self.pos['gc_iters']) result = apply_mask(result, gc_mask) # Create triangle mask # Add decorator here self.mask = create_triangle_mask(height=self.height, \ width=self.width, \ side=self.pos['m_side'], \ centre=self.pos['m_cntr'], \ bottom=self.pos['m_btm']) self.cap.loop_video = self.pos['loop_video'] return result
def _create_output_img(self, frame, y_offset_ratio=1): """Create projections rotated by 'angle' deg. CCW Args: frame -- processed frame y_offset_ratio -- mask y coord offset ratio Returns: output_img -- resulting img. """ # Create blank output_img output_img = np.zeros((self.output_img_height, self.output_img_width, 3), np.uint8) # Calculate frame position in the output_img frame_x = self.output_img_centre_x - self.width // 2 frame_y = self.output_img_centre_y - self.height * y_offset_ratio # Apply triangle mask on projection projection = apply_mask(frame, self.mask) # Apply projection to Bottom Centre of output_img output_img[frame_y : frame_y + self.height, \ frame_x : frame_x + self.width] = projection # Add Top projection output_img = cv2.add(output_img, cv2.flip(output_img, -1)) # Add Left and Right projections output_img = cv2.add(output_img, cv2.flip(cv2.transpose(output_img), 1)) return output_img