def generate_mosaic(self, target, dims, blur, out, vtype, frate=16): """ Generates and writes video mosaic. """ writer = cv2.VideoWriter(out, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), frate, (dims[1], dims[0])) reader = cv2.VideoCapture(target) success, image = reader.read() count = 0 texturize = None while success: print('Reading target frame ' + str(count)) frame = resize_image(image, dims) print('Generating output frame ' + str(count)) if vtype == 'mosaic': out_frame = np.zeros(frame.shape) for row in range(self.tile_size, dims[0] + 1, self.tile_size): for col in range(self.tile_size, dims[1] + 1, self.tile_size): region = frame[row - self.tile_size:row, col - self.tile_size:col] best = self.tiles[self.good_match(region), ...] out_frame[row - self.tile_size:row, col - self.tile_size:col, :] = best elif vtype == 'texture': if texturize is None: texturize = Texture((dims[0], dims[1], 3), 25) texturize.set_candidates(self.tiles, 3, True) out_frame = texturize.gen_texture(None, frame, 3, .5) if blur: out_frame = cv2.GaussianBlur(out_frame, (21, 21), 0) writer.write(np.uint8(out_frame)) success, image = reader.read() count += 1 reader.release() writer.release()