本文整理汇总了Python中imageio.get_writer方法的典型用法代码示例。如果您正苦于以下问题:Python imageio.get_writer方法的具体用法?Python imageio.get_writer怎么用?Python imageio.get_writer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imageio
的用法示例。
在下文中一共展示了imageio.get_writer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: motion2video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def motion2video(motion, h, w, save_path, colors, transparency=False, motion_tgt=None, fps=25, save_frame=False):
nr_joints = motion.shape[0]
videowriter = imageio.get_writer(save_path, fps=fps)
vlen = motion.shape[-1]
if save_frame:
frames_dir = save_path[:-4] + '-frames'
ensure_dir(frames_dir)
for i in tqdm(range(vlen)):
[img, img_cropped] = joints2image(motion[:, :, i], colors, transparency, H=h, W=w, nr_joints=nr_joints)
if motion_tgt is not None:
[img_tgt, img_tgt_cropped] = joints2image(motion_tgt[:, :, i], colors, transparency, H=h, W=w, nr_joints=nr_joints)
img_ori = img.copy()
img = cv2.addWeighted(img_tgt, 0.3, img_ori, 0.7, 0)
img_cropped = cv2.addWeighted(img_tgt, 0.3, img_ori, 0.7, 0)
bb = bounding_box(img_cropped)
img_cropped = img_cropped[:, bb[2]:bb[3], :]
if save_frame:
save_image(img_cropped, os.path.join(frames_dir, "%04d.png" % i))
videowriter.append_data(img)
videowriter.close()
示例2: serialize_video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def serialize_video(imgs, temp_name_append):
mp4_name = './temp{}.mp4'.format(temp_name_append)
try:
assert imgs.dtype == np.uint8, "Must be uint8 array!"
assert not os.path.exists(mp4_name), "file {} exists!".format(mp4_name)
# this is a hack to ensure imageio succesfully saves as a mp4 (instead of getting encoding confused)
writer = imageio.get_writer(mp4_name)
[writer.append_data(i[:, :, ::-1]) for i in imgs]
writer.close()
f = open(mp4_name, 'rb')
buf = f.read()
f.close()
finally:
if os.path.exists(mp4_name):
os.remove(mp4_name)
return np.frombuffer(buf, dtype=np.uint8)
示例3: make_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def make_gif(self, frame_count_limit=IMAGE_LIMIT, gif_name="mygif.gif", frame_duration=0.4):
"""Make a GIF visualization of view graph."""
self.make_thumbnails(frame_count_limit=frame_count_limit)
file_names = sorted([file_name for file_name in os.listdir(self.thumbnail_path)
if file_name.endswith('thumbnail.png')])
images = []
for file_name in file_names:
images.append(Image.open(self.thumbnail_path + file_name))
destination_filename = self.graph_path + gif_name
iterator = 0
with io.get_writer(destination_filename, mode='I', duration=frame_duration) as writer:
for file_name in file_names:
image = io.imread(self.thumbnail_path + file_name)
writer.append_data(image)
iterator += 1
writer.close()
示例4: _start_new_episode
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def _start_new_episode(self):
if self.writer:
self.writer.close()
if self.attention_writer:
self.attention_writer.close()
if self.episode_id % self.episode_save_rate == 0:
self.writer = imageio.get_writer(
os.path.join(self.video_dir, 'video_episode_{}.mp4'.format(self.episode_id)),
fps=15,
)
if self.write_attention_video:
self.attention_writer = imageio.get_writer(
os.path.join(self.video_dir, 'video_episode_{}_attention.mp4'.format(self.episode_id)),
fps=15,
)
else:
self.writer = None
self.attention_writer = None
self.episode_id += 1
示例5: make_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def make_gif(self, frame_count_limit=IMAGE_LIMIT, gif_name="mygif.gif", frame_duration=0.4):
"""Make a GIF visualization of view graph."""
if not self.save:
return
self.make_thumbnails(frame_count_limit=frame_count_limit)
file_names = sorted([file_name for file_name in os.listdir(self.thumbnail_path)
if file_name.endswith('thumbnail.png')])
images = []
for file_name in file_names:
images.append(Image.open(self.thumbnail_path + file_name))
destination_filename = self.graph_path + gif_name
iterator = 0
with io.get_writer(destination_filename, mode='I', duration=frame_duration) as writer:
for file_name in file_names:
image = io.imread(self.thumbnail_path + file_name)
writer.append_data(image)
iterator += 1
writer.close()
示例6: open_movie
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def open_movie(self, filename, framerate=24):
"""Establish a connection to the ffmpeg writer.
Parameters
----------
filename : str
Filename of the movie to open. Filename should end in mp4,
but other filetypes may be supported. See "imagio.get_writer"
framerate : int, optional
Frames per second.
"""
if isinstance(pyvista.FIGURE_PATH, str) and not os.path.isabs(filename):
filename = os.path.join(pyvista.FIGURE_PATH, filename)
self.mwriter = imageio.get_writer(filename, fps=framerate)
示例7: make_gif_from_images
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def make_gif_from_images(img_paths, outgif_path):
import imageio
resize_ratio = 4
skip_ratio = 2
with imageio.get_writer(outgif_path, mode='I') as writer:
for img_id, img_path in enumerate(img_paths):
image = imageio.imread(img_path)
image_resize = image[::resize_ratio, ::resize_ratio, :]
# Do sth to make gif file smaller
# 1) change resolution
# 2) change framerate
if img_id % skip_ratio == 0:
writer.append_data(image_resize)
print("Gif made!")
return
示例8: save_video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def save_video(imgdir, filename, ext='png', fps=24, delete_imgdir=False):
filename = os.path.join(imgdir, '..', filename+'.mp4')
try:
writer = imageio.get_writer(filename, fps=fps)
except Exception:
imageio.plugins.ffmpeg.download()
writer = imageio.get_writer(filename, fps=fps)
imgs = glob("{}/*.{}".format(imgdir, ext))
imgs = sorted(imgs, key=lambda x: int(os.path.basename(x).split('.')[0]))
# print(imgs)
for img in imgs:
im = imageio.imread(img)
writer.append_data(im)
writer.close()
if delete_imgdir: shutil.rmtree(imgdir)
示例9: __init__
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def __init__(self, d, save_dir='report'):
image_dir = os.path.join(save_dir, 'images')
if not os.path.exists(image_dir):
os.makedirs(image_dir)
self.d = d
self.save_dir = save_dir
self.steps = []
self.result = None
self.__gif_path = os.path.join(save_dir, 'output.gif')
self.__gif = imageio.get_writer(self.__gif_path, format='GIF', fps=2)
self.__uia_last_position = None
self.__last_screenshot = None
self.__closed = False
self.start_record()
示例10: save_video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def save_video(frame_queue, filename, fps):
'''
Target function for video process. Opens up file with path and uses library imageio
Args:
frame_queue: a queue of frames to be store. If the frame is None, the capture is over
filename: filename to which the capture is to be stored
fps: framerate.
Note that Queue.get() is a blocking function and thus will hang until new frames are
added to frame_queue
'''
writer = imageio.get_writer(filename, fps=fps)
while True:
frame = frame_queue.get()
if frame is None:
break
writer.append_data(frame)
writer.close()
示例11: make_circuit_video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def make_circuit_video(infile_dir_images, outfile_movie, fps=3, format='png'):
"""
Create a movie that visualizes the CPP solution from a series of static images.
Args:
infile_dir_images (str): path to list of images named like `img[X].png`. These are produced from make_circuit_images
outfile_movie (str): filename of created movie/gif (output)
fps (int): frames per second for movie
format (str): image format (png, jpeg, etc) used to generate images in named like img[X].[format].
Returns:
No return value. Writes a movie/gif to disk
"""
# sorting filenames in order
filenames = glob.glob(os.path.join(infile_dir_images, 'img*.%s' % format))
filenames_sort_indices = np.argsort([int(os.path.basename(filename).split('.')[0][3:]) for filename in filenames])
filenames = [filenames[i] for i in filenames_sort_indices]
# make movie
with imageio.get_writer(outfile_movie, mode='I', fps=fps) as writer:
for filename in tqdm.tqdm(filenames):
image = imageio.imread(filename)
writer.append_data(image)
return 'Movie written to {}'.format(outfile_movie)
示例12: write
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def write(imgs, name, fps):
writer = get_writer(name, fps=fps, quality=6)
for t in range(len(imgs)):
writer.append_data(imgs[t])
writer.close()
示例13: _file_worker
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def _file_worker(file_queue):
logging.debug('started file saver with PID:', os.getpid())
data = file_queue.get(True)
prepend_path = './'
while data is not None:
dat_type = data[0]
if dat_type == 'path':
prepend_path = data[1]
if not os.path.exists(prepend_path):
os.makedirs(prepend_path)
elif dat_type == 'txt_file':
save_path = '{}/{}'.format(prepend_path, data[1])
_make_parent_if_needed(save_path)
with open(save_path, 'w') as f:
f.write(data[2])
f.write('\n')
elif dat_type == 'mov':
save_path = '{}/{}'.format(prepend_path, data[1])
_make_parent_if_needed(save_path)
fps, frames = 4, data[2]
if len(data) == 4:
fps = data[3]
writer = io.get_writer(save_path, fps=fps)
[writer.append_data(f.astype(np.uint8)) for f in frames]
writer.close()
elif dat_type == 'img':
save_path = '{}/{}'.format(prepend_path, data[1])
_make_parent_if_needed(save_path)
cv2.imwrite(save_path, data[2][:, :, ::-1])
data = file_queue.get(True)
return
示例14: zip2gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def zip2gif(self, file):
from zipfile import ZipFile
import imageio
with ZipFile(file) as zip:
zip_folder = file.replace('.zip', '')
zip.extractall(zip_folder)
with imageio.get_writer(file.replace('.zip', '.gif'), mode='I') as writer:
for f in os.listdir(zip_folder):
writer.append_data(imageio.imread(os.path.join(zip_folder, f)))
#TODO: GIF帧率未实现,目前使用默认帧率
os.remove(file)
shutil.rmtree(zip_folder, ignore_errors=True)
示例15: test_local_video
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import get_writer [as 别名]
def test_local_video():
main_folder_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
obj_detection_graph = os.path.join(main_folder_path, 'object_detection/weights/batched_zoo/faster_rcnn_nas_coco_2018_01_28/batched_graph/frozen_inference_graph.pb')
print("Loading object detection model at %s" % obj_detection_graph)
Obj_Detector = obj.Object_Detector(obj_detection_graph)
test_vid_path = "chase1Person1View3Point0.mp4"
print('Testing on %s' % test_vid_path)
reader = imageio.get_reader(test_vid_path, 'ffmpeg')
fps = reader.get_meta_data()['fps'] // 2
out_vid_path = "chase1Person1View3Point0_out.mp4"
writer = imageio.get_writer(out_vid_path, fps=fps)
print("Writing output video on %s" %out_vid_path)
frame_cnt = 0
for test_img in reader:
frame_cnt += 1
if frame_cnt % 2 == 0:
continue
print("frame_cnt: %i" %frame_cnt)
expanded_img = np.expand_dims(test_img, axis=0)
detection_list = Obj_Detector.detect_objects_in_np(expanded_img)
out_img = visualize_results(test_img, detection_list, display=False)
writer.append_data(out_img)
writer.close()