Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import pytest
import pyvista
from pyvista import examples
from pyvista.plotting import system_supports_plotting
NO_PLOTTING = not system_supports_plotting()
ffmpeg_failed = False
try:
try:
import imageio_ffmpeg
imageio_ffmpeg.get_ffmpeg_exe()
except ImportError:
imageio.plugins.ffmpeg.download()
except:
ffmpeg_failed = True
if __name__ != '__main__':
OFF_SCREEN = 'pytest' in sys.modules
else:
OFF_SCREEN = False
pyvista.OFF_SCREEN = OFF_SCREEN
sphere = pyvista.Sphere()
sphere_b = pyvista.Sphere(1.0)
sphere_c = pyvista.Sphere(2.0)
bb = self._bb[: self._n]
self._bb = self._bb[self._n :]
return bb
def close(self):
with self._lock:
self._f.close()
# Test our class
N = 100
file = FakeGenerator(N)
file.write_and_rewind(b"v" * N)
assert file.__next__() == b"v" * N
file = FakeGenerator(N)
T = imageio.plugins.ffmpeg.FrameCatcher(file) # the file looks like a generator
# Init None
time.sleep(0.1)
assert T._frame is None # get_frame() would stall
# Read frame
file.write_and_rewind(b"x" * (N - 20))
time.sleep(0.2) # Let it read a part
assert T._frame is None # get_frame() would stall
file.write_and_rewind(b"x" * 20)
time.sleep(0.2) # Let it read the rest
frame, is_new = T.get_frame()
assert frame == b"x" * N
assert is_new, "is_new should be True the first time a frame is retrieved"
# Read frame that has not been updated
####################################################
# Dependencies
####################################################
import os.path
import sys
subfolder = os.getcwd().split('Analysis-tools')[0]
sys.path.append(subfolder)
# add parent directory: (where nnet & config are!)
sys.path.append(subfolder + "/pose-tensorflow/")
sys.path.append(subfolder + "/Generating_a_Training_Set")
# Dependencies for video:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import imageio
imageio.plugins.ffmpeg.download()
from skimage.util import img_as_ubyte
from moviepy.editor import VideoFileClip
import subprocess
import pandas as pd
import numpy as np
from tqdm import tqdm
import os
import glob
import auxiliaryfunctions
####################################################
# Loading descriptors of model
####################################################
from myconfig_analysis import videofolder, cropping, Task, date, \
#!/usr/bin/env python
from __future__ import unicode_literals
import argparse
import os
import re
from itertools import starmap
import multiprocessing
import pysrt
import imageio
import youtube_dl
import chardet
import nltk
imageio.plugins.ffmpeg.download()
nltk.download('punkt')
from moviepy.editor import VideoFileClip, concatenate_videoclips
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
from sumy.summarizers.lsa import LsaSummarizer
imageio.plugins.ffmpeg.download()
def summarize(srt_file, n_sentences, language="english"):
""" Generate segmented summary
verbose : bool, optional
Show a progress bar while iterating the video. Defaults to False.
ffmpeg : str, optional
Path to ffmpeg command line tool. Defaults to the one downloaded
by imageio.
"""
self.filename = filename
if ffmpeg is None:
import imageio
try:
ffmpeg = imageio.plugins.ffmpeg.get_exe()
except imageio.plugins.ffmpeg.NeedDownloadError as e:
imageio.plugins.ffmpeg.download()
ffmpeg = imageio.plugins.ffmpeg.get_exe()
self.ffmpeg = ffmpeg
self.verbose = verbose
infos = self._parse_infos(print_infos=False, check_duration=True)
self._fps = infos['video_fps']
self._size = infos['video_size']
self._width, self._height = self._size
self._duration = infos['video_duration']
# self.ffmpeg_duration = infos['duration']
self._nframes = infos['video_nframes']
self.start = 0. if start is None else start
self.end = self._duration if end is None else end
self.step = 1./self._fps if step is None else step
sys.path.append(subfolder + "pose-tensorflow")
sys.path.append(subfolder + "Generating_a_Training_Set")
from myconfig_analysis import videofolder, cropping, Task, date, \
trainingsFraction, resnet, snapshotindex, shuffle,x1, x2, y1, y2, videotype, storedata_as_csv
# Deep-cut dependencies
from config import load_config
from nnet import predict
from dataset.pose_dataset import data_to_input
# Dependencies for video:
import pickle
# import matplotlib.pyplot as plt
import imageio
imageio.plugins.ffmpeg.download()
from skimage.util import img_as_ubyte
from moviepy.editor import VideoFileClip
import skimage
import skimage.color
import time
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
def getpose(image, cfg, outputs, outall=False):
''' Adapted from DeeperCut, see pose-tensorflow folder'''
image_batch = data_to_input(skimage.color.gray2rgb(image))
outputs_np = sess.run(outputs, feed_dict={inputs: image_batch})
scmap, locref = predict.extract_cnn_output(outputs_np, cfg)
step : float, optional
Iterate frames every `step` seconds.
Defaults to iterating every frame.
verbose : bool, optional
Show a progress bar while iterating the video. Defaults to False.
ffmpeg : str, optional
Path to ffmpeg command line tool. Defaults to the one downloaded
by imageio.
"""
self.filename = filename
if ffmpeg is None:
import imageio
try:
ffmpeg = imageio.plugins.ffmpeg.get_exe()
except imageio.plugins.ffmpeg.NeedDownloadError as e:
imageio.plugins.ffmpeg.download()
ffmpeg = imageio.plugins.ffmpeg.get_exe()
self.ffmpeg = ffmpeg
self.verbose = verbose
infos = self._parse_infos(print_infos=False, check_duration=True)
self._fps = infos['video_fps']
self._size = infos['video_size']
self._width, self._height = self._size
self._duration = infos['video_duration']
# self.ffmpeg_duration = infos['duration']
self._nframes = infos['video_nframes']
self.start = 0. if start is None else start
def convert_png2mp4(imgdir, filename, fps, delete_imgdir=False):
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
try:
writer = imageio.get_writer(filename, fps=fps)
except Exception:
imageio.plugins.ffmpeg.download()
writer = imageio.get_writer(filename, fps=fps)
imgs = sorted(glob("{}/*.png".format(imgdir)))
# print(imgs)
for img in imgs:
im = imageio.imread(img)
writer.append_data(im)
writer.close()
if delete_imgdir: shutil.rmtree(imgdir)
import imageio
imageio.plugins.ffmpeg.download()
import torchvision.transforms.functional as functional
import torchvision.transforms as transforms
import torch
from .statefultransforms import StatefulRandomCrop, StatefulRandomHorizontalFlip
def load_video(filename):
"""Loads the specified video using ffmpeg.
Args:
filename (str): The path to the file to load.
Should be a format that ffmpeg can handle.
Returns:
List[FloatTensor]: the frames of the video as a list of 3D tensors
(channels, width, height)"""
"""
Some codes are taken from https://github.com/Newmu/dcgan_code
"""
import math
import pprint
import scipy.misc
import numpy as np
import os
import imageio
import tensorflow as tf
import tensorflow.contrib.slim as slim
pp = pprint.PrettyPrinter()
imageio.plugins.ffmpeg.download()
get_stddev = lambda x, k_h, k_w: 1 / math.sqrt(k_w * k_h * x.get_shape()[-1])
def show_all_variables():
model_vars = tf.trainable_variables()
slim.model_analyzer.analyze_vars(model_vars, print_info=True)
def save_images(images, size, image_path):
if not os.path.exists(os.path.dirname(image_path)):
os.makedirs(os.path.dirname(image_path))
return imsave(inverse_transform(images), size, image_path)
def merge(images, size):
h, w = images.shape[1], images.shape[2]