def get_mask_func(self, widget, padding_left=0, padding_right=0, padding_top=0, padding_bottom=0): ''' Get mask function to render background, you can use this function to return \"render function\" to draw your ui to keep same style. @param widget: DialogBox widget. @param padding_left: Padding at left side. @param padding_right: Padding at right side. @param padding_top: Padding at top side. @param padding_bottom: Padding at bottom side. ''' if self.mask_type == DIALOG_MASK_SINGLE_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_single_page) elif self.mask_type == DIALOG_MASK_GLASS_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_glass_page) elif self.mask_type == DIALOG_MASK_MULTIPLE_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_multiple_page) elif self.mask_type == DIALOG_MASK_TAB_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_tab_page) else: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, draw_blank_mask)
def generate_features(audio=True, frames=True): out_path = Path(OUT_PATH + 'unmasked/') out_path.mkdir(parents=True, exist_ok=True) out_path = Path(OUT_PATH + 'masked/') out_path.mkdir(parents=True, exist_ok=True) # generate audio features if (audio): extract_features('data/audio_speech/', AUDIO_PATH) # generate frames if (frames): extract_frames('data/video_speech/', VIDEO_PATH) # generate landmarks for each frame for file in glob.iglob(FRAMES_PATH + '*.jpg'): filename = Path(file).name[:-4] # find correct landmarks original = cv2.imread(file) rect = detect_face(original) shape = generate_landmarks(original, rect) # save with open(OUT_PATH + 'unmasked/' + filename + '.csv', 'w', newline='') as output_file: writer = csv.writer(output_file, delimiter=',') for i in range(len(shape)): writer.writerow(shape[i]) # find masked landmarks draw_mask(file, 'temp.jpg') masked = cv2.imread('temp.jpg') shape = generate_landmarks(masked, rect) # save with open(OUT_PATH + 'masked/' + filename + '.csv', 'w', newline='') as output_file: writer = csv.writer(output_file, delimiter=',') for i in range(len(shape)): writer.writerow(shape[i])
def get_mask_func(self, widget, padding_left=0, padding_right=0, padding_top=0, padding_bottom=0): '''Get mask function.''' if self.mask_type == DIALOG_MASK_SINGLE_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_single_page) elif self.mask_type == DIALOG_MASK_GLASS_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_glass_page) elif self.mask_type == DIALOG_MASK_MULTIPLE_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_multiple_page) elif self.mask_type == DIALOG_MASK_TAB_PAGE: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, self.draw_mask_tab_page) else: return lambda cr, x, y, w, h: draw_mask( widget, x + padding_left, y + padding_top, w - padding_left - padding_right, h - padding_top - padding_bottom, draw_blank_mask)
from mask import draw_mask # obtain arguments if len(sys.argv) < 5: print "!!! Missing arguments, please provide input, data and output filenames." sys.exit(2) image_file = sys.argv[1] mask_data_file = sys.argv[2] roi_data_file = sys.argv[3] output_file = sys.argv[4] # get image image = repo.get_image(image_file) assert image.dtype == "uint8" # retrieve data contours = repo.get_data(mask_data_file)["contours"] roi_data = repo.get_data(roi_data_file) roi_upper = roi_data['teeth_upper'] roi_lower = roi_data['teeth_lower'] rois = np.concatenate([roi_upper,roi_lower]) # create image for index, contour in enumerate(contours): image = draw_mask(image, rois[index], contour, None) repo.put_image(output_file, image)