def batch_export(file_batch, lineart_file_batch, output_dir, lineart_dir): export_list = [] crop_list = [] line_list = [] if len(file_batch) != 0: for img, _, aspect in file_batch: crop_image = crop.crop_square_image(img, aspect) crop_list.append(crop_image) crop_chunk = [ crop_list[i:i + batch_input_size] for i in range(0, len(crop_list), batch_input_size) ] sketch_list = [] for chunk in crop_chunk: sketch_list.extend(sketchify.batch_keras_enhanced(chunk)) for (_, file_id, _), img, sketch in zip(file_batch, crop_list, sketch_list): square_sketch, cropped, extend = crop.make_square(sketch) square_image, _, _ = crop.make_square(img, cropped, extend) export_list.append((square_image, str(file_id))) export_list.append((square_sketch, str(file_id) + '_sk')) for img, file_id, aspect in lineart_file_batch: crop_image = crop.crop_square_image(img, aspect) square_image = make_lineart_square(crop_image) line_list.append((square_image, str(file_id))) for img, id in export_list: cv2.imwrite(str(output_dir / f'{id}.png'), img) for img, id in line_list: cv2.imwrite(str(lineart_dir / f'{id}_sk.png'), img) file_batch.clear() lineart_file_batch.clear()
def make_square_and_sketch(img): sketch = sketchify.get_sketch(img) square_img, cropped, extend = crop.make_square(img) square_sketch, _, _ = crop.make_square(sketch, cropped, extend) return (square_img, square_sketch)
def make_lineart_square(img): img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) square_img, _, _ = crop.make_square(img) return square_img