Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Obj_Detector = obj.Object_Detector(obj_detection_graph)
Tracker = obj.Tracker()
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)
actors = [0,1,2]
writers = []
for ii in actors:
writer = imageio.get_writer("person_%i.mp4" % ii, fps=fps)
print("Video writer set for person_%i" % ii)
writers.append(writer)
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)
detection_info = [info[0] for info in detection_list]
Tracker.update_tracker(detection_info, test_img)
if frame_cnt > 30:
print("writing segments")
for actor_no, writer in zip(actors,writers):
#Written by Timothy Seabrook
#timothy.seabrook@cs.ox.ac.uk
import imageio
import glob
filenames = glob.glob('/Users/seabrook/Documents/FDL/Kernel/' + '*.png')
with imageio.get_writer('/Users/seabrook/Documents/FDL/Kernel/kernel.gif', mode='I', duration=0.04) as writer:
for i in range(len(filenames) // 4):
image = imageio.imread(filenames[i])
writer.append_data(image)
def motion2video(motion, h, w, save_path, name, colors, transparency=False, motion_tgt=None, fps=25):
videowriter = imageio.get_writer(os.path.join(save_path, name + '.mp4'), fps=fps)
vlen = motion.shape[-1]
frames_dir = os.path.join(save_path, 'frames-' + name)
ensure_dir(frames_dir)
for i in tqdm(range(vlen)):
[img, img_cropped] = joints2image(motion[:, :, i], colors, transparency, H=h, W=w)
if motion_tgt is not None:
[img_tgt, img_tgt_cropped] = joints2image(motion_tgt[:, :, i], colors, H=h, W=w)
img = cv2.addWeighted(img_tgt, 0.3, img, 0.7, 0)
save_image(img_cropped, os.path.join(frames_dir, "%04d.png" % i))
videowriter.append_data(img)
videowriter.close()
images : `list` of :map:`Image`
List of Menpo images to export as a video.
out_path : `Path`
Path to save the video to.
fps : `float`, optional
The number of frames per second. If ``duration`` is not given, the
duration for each frame is set to 1/fps.
loop : `int`, optional
The number of iterations. 0 means loop indefinitely
duration : `float` or list of `float`, optional
The duration (in seconds) of each frame. Either specify one value
that is used for all frames, or one value for each frame.
"""
import imageio
writer = imageio.get_writer(str(out_path), mode='I', fps=fps,
loop=loop, duration=duration)
for v in images:
v = v.pixels_with_channels_at_back(out_dtype=np.uint8)
writer.append_data(v)
writer.close()
Default is ``True``.
Examples
--------
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> plotter = MeshPlotter(mesh)
>>> plotter.draw_vertices()
"""
if reverse:
files.reverse()
if pingpong:
files += files[::-1]
with imageio.get_writer(gif_path,
mode='I',
fps=fps,
loop=loop,
subrectangles=subrectangles) as writer:
for filename in files:
image = imageio.imread(filename)
writer.append_data(image)
if delete_files:
for filename in files:
os.remove(filename)
def put_genpix_in_frame():
file = '/home/guser/catkin_ws/src/lsdc/tensorflow_data/sawyer/dna_correct_nummask/vid_rndaction_var10_66002_diffmotions_b0_l30.gif'
frames_dna = getFrames(file)
file = '/home/guser/catkin_ws/src/lsdc/tensorflow_data/sawyer/1stimg_bckgd_cdna/vid_rndaction_var10_64002_diffmotions_b0_l30.gif'
frames_cdna = getFrames(file)
t = 1
dest_path = '/home/guser/frederik/doc_video'
frame = Image.open(dest_path + '/frame_comp_oadna.png', mode='r')
writer = imageio.get_writer(dest_path + '/genpix_withframe.mp4', fps=3)
pic_path = dest_path + "/animated"
if not os.path.exists(pic_path):
os.mkdir(pic_path)
for i, img_dna, img_cdna in zip(list(range(len(frames_dna))), frames_dna, frames_cdna):
newimg = copy.deepcopy(np.asarray(frame)[:, :, :3])
img_dna, size_insert = resize(img_dna)
# Image.fromarray(img_dna)
startr = 230
startc = 650
newimg[startr:startr + size_insert[0], startc: startc + size_insert[1]] = img_dna
img_cdna, size_insert = resize(img_cdna)
def save_video_mp4(filename, frames):
writer = imageio.get_writer(filename + '.mp4', fps=10)
for i, frame in enumerate(frames):
print('frame',i)
writer.append_data(frame)
writer.close()
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)