Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help=
        'Path to image folder. The video will be created from these images.')
    parser.add_argument('--fps',
                        type=int,
                        default=60,
                        help='FPS (Frames per second) setting for the video.')
    parser.add_argument('--processed',
                        action='store_true',
                        help='Transform the image back to the model space.')
    args = parser.parse_args()

    video_file = args.image_folder + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))
    clip = ImageSequenceClip(args.image_folder, fps=args.fps)

    if args.processed:

        def tmp(im):
            processed = utils.process_image(im)
            processed = cv2.cvtColor(processed, color_space['src'])
            return np.hstack((im, processed))

        clip = clip.fl_image(tmp)

    clip.write_videofile(video_file)
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    # convert file folder into list firltered for image file types
    image_list = sorted([os.path.join(args.image_folder, image_file)
                         for image_file in os.listdir(args.image_folder)])

    image_list = [image_file for image_file in image_list if os.path.splitext(
        image_file)[1][1:].lower() in IMAGE_EXT]

    # two methods of naming output video to handle varying environemnts
    video_file_1 = args.image_folder + '.mp4'
    video_file_2 = args.image_folder + 'output_video.mp4'

    print("Creating video {}, FPS={}".format(args.image_folder, args.fps))
    clip = ImageSequenceClip(image_list, fps=args.fps)

    try:
        clip.write_videofile(video_file_1)
    except:
        clip.write_videofile(video_file_2)
Exemplo n.º 3
0
def CreateGif(filename, array, fps=5, scale=1., fmt='gif'):
    ''' Create and save a gif or video from array of images.
        Parameters:
            * filename (string): name of the saved video
            * array (list or string): array of images name already in order, if string it supposed to be the first part of the images name (before iteration integer)
            * fps = 5 (integer): frame per seconds (limit human eye ~ 15)
            * scale = 1. (float): ratio factor to scale image hight and width
            * fmt (string): file extention of the gif/video (e.g: 'gif', 'mp4' or 'avi')
        Return:
            * moviepy clip object
    '''
    if (isinstance(array, str)):
        arrsize = len(gb.glob(array + '*.png'))
        array = [array + str(i) + '.png' for i in range(arrsize)]
    else:
        pass
    from moviepy.editor import ImageSequenceClip
    filename += '.' + fmt
    clip = ImageSequenceClip(list(array), fps=fps).resize(scale)
    if (fmt == 'gif'):
        clip.write_gif(filename, fps=fps)
    elif (fmt == 'mp4'):
        clip.write_videofile(filename, fps=fps, codec='mpeg4')
    elif (fmt == 'avi'):
        clip.write_videofile(filename, fps=fps, codec='png')
    else:
        print('Error! Wrong File extension.')
        sys.exit()
    command = os.popen('du -sh %s' % filename)
    print(command.read())
    return clip
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(description='创建驾驶视频.')
    parser.add_argument('image_folder',
                        type=str,
                        default='',
                        help='图像文件夹的路径。将从这些图像创建视频.')
    parser.add_argument('--fps',
                        type=int,
                        default=60,
                        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    # 将文件文件夹转换为图像文件类型的列表
    image_list = sorted([
        os.path.join(args.image_folder, image_file)
        for image_file in os.listdir(args.image_folder)
    ])

    image_list = [
        image_file for image_file in image_list
        if os.path.splitext(image_file)[1][1:].lower() in IMAGE_EXT
    ]

    #  两种处理不同环境的输出视频命名方法
    video_file_1 = args.image_folder + '.mp4'
    video_file_2 = args.image_folder + 'output_video.mp4'

    print("创建视频文件 {}, FPS={}".format(args.image_folder, args.fps))
    clip = ImageSequenceClip(image_list, fps=args.fps)

    try:
        clip.write_videofile(video_file_1)
    except:
        clip.write_videofile(video_file_2)
Exemplo n.º 5
0
def movie(filename: str, array: np.ndarray, fps: int = 10, scale: float = 1.0):
    """
    Create a mp4 movie file from a 3D numpy array

    >>> import numpy as np
    >>> X = np.random.randn(100, 64, 64)
    >>> movie('test.mp4', X)

    :param filename: The filename of the gif to write to
    :param array: A numpy array that contains a sequence of images
    :param fps: frames per second (default: 10)
    :param scale: how much to rescale each image by (default: 1.0)

    Inspired in https://gist.github.com/nirum/d4224ad3cd0d71bfef6eba8f3d6ffd59

    """

    # ensure that the file has the .gif extension
    basename, _ = os.path.splitext(filename)
    filename = basename + '.mp4'

    # copy into the color dimension if the images are black and white
    if array.ndim == 3:
        array = array[..., np.newaxis] * np.ones(3)

    # make the moviepy clip
    clip = ImageSequenceClip(list(array), fps=fps).resize(scale)
    clip.write_videofile(filename, fps=fps)
    return clip
Exemplo n.º 6
0
    def run(self):
        # Set up video capture
        left_video = cv2.VideoCapture(0)  #eo_in_path)
        right_video = cv2.VideoCapture(1)  #self.right_video_in_path)
        print('[INFO]: {} and {} loaded'.format(
            self.left_video_in_path.split('/')[-1],
            self.right_video_in_path.split('/')[-1]))
        print('[INFO]: Video stitching starting....')

        # Get information about the videos
        n_frames = min(int(left_video.get(cv2.CAP_PROP_FRAME_COUNT)),
                       int(right_video.get(cv2.CAP_PROP_FRAME_COUNT)))
        fps = int(left_video.get(cv2.CAP_PROP_FPS))
        frames = []

        # for _ in tqdm.tqdm(np.arange(n_frames)):
        while True:
            # Grab the frames from their respective video streams
            ok, left = left_video.read()
            _, right = right_video.read()

            if ok:

                cv2.imshow("a", left)
                cv2.imshow("b", right)
                # Stitch the frames together to form the panorama
                stitched_frame = self.stitch([left, right])

                # No homography could not be computed
                if stitched_frame is None:
                    print("[INFO]: Homography could not be computed!")
                    break

                # Add frame to video
                # stitched_frame = imutils.resize(stitched_frame, width=self.video_out_width)
                # stitched_frame = cv2.resize(stitched_frame, (self.video_out_width,self.video_out_width))
                frames.append(stitched_frame)

                if self.display:
                    # Show the output images
                    cv2.imshow("Result", stitched_frame)

                # If the 'q' key was pressed, break from the loop
                if cv2.waitKey(1) & 0xFF == ord("q"):
                    break

        cv2.destroyAllWindows()
        print('[INFO]: Video stitching finished')

        # Save video
        print('[INFO]: Saving {} in {}'.format(
            self.video_out_path.split('/')[-1],
            os.path.dirname(self.video_out_path)))
        clip = ImageSequenceClip(frames, fps=fps)
        clip.write_videofile(self.video_out_path,
                             codec='mpeg4',
                             audio=False,
                             progress_bar=True,
                             verbose=False)
        print('[INFO]: {} saved'.format(self.video_out_path.split('/')[-1]))
Exemplo n.º 7
0
def make_gif_of_traj(filename, output_filename, raw=True, fps=5):
    file = dd.io.load(filename)
    traj_len = len(file)
    print(f'trajectory length is {traj_len}')
    traj_images = []
    a = attrdict.AttrDict({'mean': 0, 'scale': 1})
    for i in range(1, traj_len):
        data = file[i]
        act = obs_to_action(data, file[i - 1], a)
        sorted_act = sorted(act, key=np.abs)
        if np.abs(sorted_act[0]) == 0 and sorted_act[1] == 0:
            print('alert alert')
        print(act)
        fig, axs = plot_images(data, raw=raw)
        fig.canvas.draw()
        image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8')
        image = image.reshape(fig.canvas.get_width_height()[::-1] + (3, ))
        traj_images.append(image)
    clip = ImageSequenceClip(traj_images, fps=fps)
    print(f'Writing out to {output_filename}.mp4')
    clip.write_videofile(f'{output_filename}.mp4', fps=fps)
    print(f'Writing out to {output_filename}.gif')
    clip.write_gif(f'{output_filename}.gif',
                   fps=fps,
                   program='imageio',
                   opt='wu')
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    #convert file folder into list firltered for image file types
    image_list = sorted([os.path.join(args.image_folder, image_file)
                        for image_file in os.listdir(args.image_folder)])
    
    image_list = [image_file for image_file in image_list if os.path.splitext(image_file)[1][1:].lower() in IMAGE_EXT]

    #two methods of naming output video to handle varying environemnts
    video_file_1 = args.image_folder + '.mp4'
    video_file_2 = args.image_folder + 'output_video.mp4'

    print("Creating video {}, FPS={}".format(args.image_folder, args.fps))
    clip = ImageSequenceClip(image_list, fps=args.fps)
    
    try:
        clip.write_videofile(video_file_1)
    except:
        clip.write_videofile(video_file_2)
Exemplo n.º 9
0
 def export_action(self):
     #get the folder containing the images using a file dialog
     dlg = QFileDialog()
     dlg.setFileMode(QFileDialog.Directory)
     folderLocs = QStringList(
     )  #create a QstringList to hold the location data
     if dlg.exec_():
         folderLocs = dlg.selectedFiles()
         for folderLoc in folderLocs:
             #Export the recorder images as video using ffmpeg
             print("Grabbing images from: ", str(folderLoc))
             folderName = str(
                 folderLoc
             )[-8:]  #get the folder name (the last 8 characters) from the directory name
             try:
                 clip = ImageSequenceClip(str(folderLoc),
                                          fps=int(self.writeFPS))
                 print("Writing file...")
                 if self.writeMethod == 0:
                     clip.write_videofile(self.localDir + "/exported/" +
                                          folderName + "_" +
                                          str(self.writeName) + ".avi",
                                          codec=str(self.writeCodec))
                 elif self.writeMethod == 1:
                     clip.write_gif(self.localDir + "/exported/" +
                                    folderName + "_" + str(self.writeName) +
                                    ".gif",
                                    program=str(self.writeProgram))
             except Exception as e:
                 print("Writing exception check settings.\nException:" +
                       str(e))
                 errorBox("Writing exception check settings.\nException:" +
                          str(e))
Exemplo n.º 10
0
def main():
    resultFrames = []
    clipFileName = input('Введите имя видеофайла для обработки: ')

    if not os.path.isfile(clipFileName):
        print('Указанный файл не найден')
        return

    clip = VideoFileClip(clipFileName)

    depth = 5
    margin = 100
    fillerWidth = 320
    windowSplit = 2
    winCount = 18
    searchPortion = 1.

    pipAlpha = .7
    pipScaleRatio = .35

    pipParams = {'alpha': pipAlpha, 'scaleRatio': pipScaleRatio}

    ld = Detector(imgMarginWidth=fillerWidth, historyDepth=depth,
                  margin=margin, windowSplit=windowSplit, winCount=winCount,
                  searchPortion=searchPortion, veHiDepth=45,
                  pointSize=64, groupThrd=10, groupDiff=.1, confidenceThrd=.5)

    for frame in tqdm(clip.iter_frames()):
        dst = ld.getEmbedDetections(src=frame, pipParams=pipParams)
        resultFrames.append(dst)

    resultClip = ImageSequenceClip(resultFrames, fps=25, with_mask=False)
    resultFileName = clipFileName.split('.')[0]
    resultFileName = '{}_out_{}.mp4'.format(resultFileName, aux.timeStamp())
    resultClip.write_videofile(resultFileName, progress_bar=True)
Exemplo n.º 11
0
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help=
        'Path to image folder. The video will be created from these images.')
    parser.add_argument('--fps',
                        type=int,
                        default=60,
                        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    setNum = args.image_folder.split('dataset')[1]
    setNum = setNum.split('/')[0]

    print(setNum)

    imageArray = []
    with open('dataset%s/data.csv' % setNum, 'rt') as file:
        reader = csv.reader(
            file)  #Create a reader to read the csv file line by line
        for line in reader:  #For each line in the csv fileine == 1): #If it's not the first line
            if (line[0] != 'center'):
                imagePath = "dataset{}/png/".format(setNum) + line[0].split(
                    'IMG\\')[1]  #Get the local path to the image
                image = pyplot.imread(imagePath)  #Read the image
                imageArray.append(image)

    video_file = args.image_folder + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))
    clip = ImageSequenceClip(imageArray, fps=args.fps)
    clip.write_videofile(video_file)
Exemplo n.º 12
0
def process_video(video_file, clf, scaler, params):
    '''
    create bounding box for each frame in a video file
    '''
    video_clip = VideoFileClip(video_file)

    qsize = 6
    heatmap_threshold = 3
    old_frames = Queue()
    new_frames = Queue()
    image_sequence = []

    for i, f, in enumerate(video_clip.iter_frames()):
        print ('processing frame ', i)
        fig = plot_bounding_box(f, clf, scaler, params)
        if old_frames.qsize() < qsize:
            old_frames.put(fig)
        else:
            average_frame, old_frames = get_frame_aggregate(old_frames)
            _ = old_frames.get()
            old_frames.put(fig)

            heatmap = ro.apply_threshold(average_frame, heatmap_threshold)
            labels = label(heatmap)
            print(labels[1], 'cars found')
            draw_img = ro.draw_labeled_bboxes(np.copy(f), labels)
            image_sequence.append(draw_img)

            #plt.figure()
            #plt.imshow(draw_img)
            #plt.show()
    clip = ImageSequenceClip(image_sequence, fps=video_clip.fps)
    clip.write_videofile("drive_n_%d_t_%d.mp4" %(qsize, heatmap_threshold), audio=False)
def main():

    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help=
        'Path to image folder. The video will be created from these images.')
    parser.add_argument('--fps',
                        type=int,
                        default=60,
                        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    video_file = args.image_folder + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))

    clip = ImageSequenceClip(args.image_folder, fps=args.fps)

    # Show preprocessing effects
    video_processor = model.VideoProcessor()
    clip = clip.fl_image(video_processor.process_frame)

    clip.write_videofile(video_file)
Exemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()
	
    setNum = args.image_folder.split('dataset')[1]
    setNum = setNum.split('/')[0]
	
    print (setNum)
	
    imageArray = []
    with open('dataset%s/data.csv' % setNum,'rt') as file:
        reader = csv.reader(file) #Create a reader to read the csv file line by line
        for line in reader: #For each line in the csv fileine == 1): #If it's not the first line
            if(line[0] != 'center'):
                imagePath = "dataset{}/png/".format(setNum) + line[0].split('IMG\\')[1] #Get the local path to the image
                image = pyplot.imread(imagePath) #Read the image
                imageArray.append(image)
	
    video_file = args.image_folder + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))
    clip = ImageSequenceClip(imageArray, fps=args.fps)
    clip.write_videofile(video_file)
Exemplo n.º 15
0
def main():
    car_detector = CarDetector(5)
    car_detector.trian_classifier('vehicles', 'non-vehicles')
    # image_files = glob.glob(r'./test_images/test*.jpg')
    # subplot_text = '23'
    # i=0
    # for image_file in image_files:
    #     i+=1
    #     img = cv2.imread(image_file)
    #     draw_image= car_detector.find_cars(img)
    #     plt.subplot(subplot_text+str(i))
    #     draw_image=cv2.cvtColor(draw_image,cv2.COLOR_BGR2RGB)
    #     plt.imshow(draw_image)
    #     plt.title('Example '+str(i))
    # plt.show()

    input_clip_file = 'project_video.mp4'
    input_clip = VideoFileClip(input_clip_file)
    output_clip_file = 'output_project_video.mp4'
    output_frame_list = []
    for frame in input_clip.iter_frames():
        #The algorithms were developed for BGR not RGB
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        output_frame = car_detector.find_cars(frame)
        output_frame = cv2.cvtColor(output_frame, cv2.COLOR_BGR2RGB)
        output_frame_list.append(output_frame)

    output_clip = ImageSequenceClip(output_frame_list, input_clip.fps)
    output_clip.write_videofile(output_clip_file)
Exemplo n.º 16
0
def gif(filename, array, fps=10, scale=1.0):
    """Creates a gif given a stack of images using moviepy
    Notes
    -----
    works with current Github version of moviepy (not the pip version)
    https://github.com/Zulko/moviepy/commit/d4c9c37bc88261d8ed8b5d9b7c317d13b2cdf62e
    Usage
    -----
    >>> X = randn(100, 64, 64)
    >>> gif('test.gif', X)
    Parameters
    ----------
    filename : string
        The filename of the gif to write to
    array : array_like
        A numpy array that contains a sequence of images
    fps : int
        frames per second (default: 10)
    scale : float
        how much to rescale each image by (default: 1.0)
    """

    # ensure that the file has the .gif extension
    fname, _ = os.path.splitext(filename)
    filename = fname + '.gif'

    # copy into the color dimension if the images are black and white
    if array.ndim == 3:
        array = array[..., np.newaxis] * np.ones(3)

    # make the moviepy clip
    clip = ImageSequenceClip(list(array), fps=fps).resize(scale)
    clip.write_gif(filename, fps=fps)
    clip.write_videofile(fname + ".mp4", fps=fps)
    return clip
Exemplo n.º 17
0
 def write_frames(self, frames: List[np.ndarray], filepath: str, audio: CompositeAudioClip) -> str:
     """Writes the frames to a given .mp4 filepath (h264 codec)"""
     vclip = ImageSequenceClip(frames, fps=self.fps)
     audio.set_duration(vclip.duration)
     vclip.audio = audio
     vclip.write_videofile(filepath, codec='libx264', fps=self.fps)
     return filepath
def img_to_video(img_folder, target_file, fps=10):
    clip = ImageSequenceClip(img_folder, fps=fps)
    clip.write_videofile(target_file, codec='libx264', threads=4)
    [
        os.remove(os.path.join(img_folder, i)) for i in os.listdir(img_folder)
        if i[-4:] != '.mp4'
    ]
Exemplo n.º 19
0
def make_video(path_images_record, path_video_save, fps):
    """
    Create an .mp4 video from a set of images
    
    Inputs
    ----------
    path_images_record: str
        Path to where the images from the recorded run are saved
    path_video_save: str
        Path to where the output video will be saved
    fps: int
        Framed per second in the output video
       
    Outputs
    -------
        Saves an .mp4 video at 'path_video_save'

    """

    image_list = sorted([path_join(path_images_record, image_file)
                        for image_file in listdir(path_images_record)])
    
    image_list = [image_file for image_file in image_list if splitext(image_file)[1][1:].lower() in IMAGE_EXT]

    clip = ImageSequenceClip(image_list, fps = fps)

    clip.write_videofile(path_video_save)
Exemplo n.º 20
0
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--side',
        type=str,
        default='center',
        help='center, left, right.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    train_samples = loadData([args.image_folder], side=args.side)
    #print(train_samples)
    video_file = './data/' + args.image_folder + '.' + args.side + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))
    clip = ImageSequenceClip(train_samples, fps=args.fps)
    clip.write_videofile(video_file)
Exemplo n.º 21
0
def run():
    num_classes = 2
    image_shape = (160, 576)
    data_dir = './data'
    runs_dir = './runs'
    tests.test_for_kitti_dataset(data_dir)

    # Download pretrained vgg model
    helper.maybe_download_pretrained_vgg(data_dir)

    # OPTIONAL: Train and Inference on the cityscapes dataset instead of the Kitti dataset.
    # You'll need a GPU with at least 10 teraFLOPS to train on.
    #  https://www.cityscapes-dataset.com/

    with tf.Session() as sess:
        # Path to vgg model
        vgg_path = os.path.join(data_dir, 'vgg')
        # Create function to get batches
        get_batches_fn = helper.gen_batch_function(os.path.join(data_dir, 'data_road/training'), image_shape)

        # OPTIONAL: Augment Images for better results
        #  https://datascience.stackexchange.com/questions/5224/how-to-prepare-augment-images-for-neural-network

        # TODO: Build NN using load_vgg, layers, and optimize function
        input_image, keep_prob, layer3_out, layer4_out, layer7_out = load_vgg(sess, vgg_path)
        layer_output = layers(layer3_out, layer4_out, layer7_out, num_classes)

        correct_label = tf.placeholder(tf.float32, [None, None, None, num_classes])
        learning_rate = tf.placeholder(tf.float32)
        logits, train_op, total_loss = optimize(layer_output, correct_label, learning_rate, num_classes)

        # TODO: Train NN using the train_nn function
        epochs = 175
        batch_size = 16 # Tuning Params
        learning_curve, mean_iou_curve = train_nn(sess, epochs, batch_size, get_batches_fn, train_op, total_loss, input_image, logits, correct_label, num_classes, keep_prob, learning_rate)

        plt.plot(learning_curve)
        plt.title('training curves')
        plt.ylabel('loss')
        plt.xlabel('epochs')
        plt.savefig('./learning_curve.png')

        plt.plot([i*MEAN_IOU_INTERVAL for i in range(len(mean_iou_curve))], mean_iou_curve)
        plt.title('mean iou curves')
        plt.ylabel('iou')
        plt.xlabel('epochs')
        plt.savefig('./mean_iou_curve.png')
        #plt.show()

        # TODO: Save inference data using helper.save_inference_samples
        #  helper.save_inference_samples(runs_dir, data_dir, sess, image_shape, logits, keep_prob, input_image)
        output_dir = helper.save_inference_samples(runs_dir, data_dir, sess, image_shape, logits, keep_prob, input_image)

        # OPTIONAL: Apply the trained model to a video
        video_file = 'output.mp4'
        fps = 2
        print("Creating video {}, FPS={}".format(video_file, fps))
        clip = ImageSequenceClip(output_dir, fps=fps)
        clip.write_videofile(video_file)
Exemplo n.º 22
0
def makemovie(dirname, outfile):
    images = []
    filecnt = len(os.listdir(dirname)) - 1
    for cnt in range(1, filecnt):
        images.append(dirname + str(cnt) + '.jpg')

    clip = ImageSequenceClip(images, fps=30)
    clip.write_videofile(outfile)
Exemplo n.º 23
0
def save_with_mp4(output_dir, name):
    glob_name = os.path.join(output_dir, name, '*.jpg')
    images = glob(glob_name)
    if len(images) == 0:
        print('Image not found in {}'.format(glob_name), file=sys.stderr)
        return
    clip = ImageSequenceClip(images, fps=60)
    clip.write_videofile(os.path.join(output_dir, '{}.mp4'.format(name)))
Exemplo n.º 24
0
 def stopPlay(self):
     self.timer.stop()
     fileName = QtWidgets.QFileDialog.getSaveFileName(
         caption='Save Recording', filter='*.mp4')
     print('Saving to ' + str(fileName[0]))
     if fileName[0] != '':
         clip = ImageSequenceClip(self.images, fps=30)
         clip.write_videofile(fileName[0], fps=30)
Exemplo n.º 25
0
def makeVidFromImgSequence(memes, j):
    ids = []
    for i in range(0, len(memes)):
        ids.append("processed\\" + memes[i]["imgID"])

    #Save Video
    clip = ImageSequenceClip(ids, fps=0.2)
    clip.write_videofile("processVids/output" + str(j) + ".mp4")
Exemplo n.º 26
0
def main(ip_dir, video, fps):
    # generate the video, from the images in sequence
    vimages = [
        str(filename)
        for filename in sorted(glob.glob(os.path.join(ip_dir + '/*.jpg')))
    ]
    clip = ImageSequenceClip(vimages, fps)
    clip.write_videofile(ip_dir + '/' + video + '.mp4', fps)
Exemplo n.º 27
0
def main():
    """
    Runs when invoking directly from command line
    :return: 
    """
    resultFrames = []

    clipFileName = input('Enter video file name: ')

    if not os.path.isfile(clipFileName):
        print('No such file. Exiting.')
        return

    clip = VideoFileClip(clipFileName)

    # depth = aux.promptForInt(message='Enter history depth in frames: ')
    # detectionPointSize = aux.promptForInt(message='Enter Search Margin: ')
    # fillerWidth = aux.promptForInt(message='Enter filler width: ')
    # windowSplit = aux.promptForInt(message='Enter Window Split: ')
    # winCount = aux.promptForInt(message='Enter Window Count for Box Search: ')
    # searchPortion = aux.promptForFloat(message='Enter the Search portion (0.0 - 1.0): ')
    # pipAlpha = aux.promptForFloat(message='Enter Picture-in-picture alpha: (0.0 - 1.0): ')
    # pipScaleRatio = aux.promptForFloat(message='Enter Picture-in-picture scale (0.0 - 1.0): ')

    depth = 5
    margin = 100
    fillerWidth = 320
    windowSplit = 2
    winCount = 18
    searchPortion = 1.

    pipAlpha = .7
    pipScaleRatio = .35

    pipParams = {'alpha': pipAlpha, 'scaleRatio': pipScaleRatio}

    print('Total frames: {}'.format(clip.duration * clip.fps))

    ld = Detector(imgMarginWidth=fillerWidth,
                  historyDepth=depth,
                  margin=margin,
                  windowSplit=windowSplit,
                  winCount=winCount,
                  searchPortion=searchPortion,
                  veHiDepth=45,
                  pointSize=64,
                  groupThrd=10,
                  groupDiff=.1,
                  confidenceThrd=.5)

    for frame in tqdm(clip.iter_frames()):
        dst = ld.embedDetections(src=frame, pipParams=pipParams)
        resultFrames.append(dst)

    resultClip = ImageSequenceClip(resultFrames, fps=25, with_mask=False)
    resultFileName = clipFileName.split('.')[0]
    resultFileName = '{}_out_{}.mp4'.format(resultFileName, aux.timeStamp())
    resultClip.write_videofile(resultFileName)
Exemplo n.º 28
0
def get_output(video_path,
               out_filename,
               label,
               fps=30,
               font_size=20,
               font_color='white',
               resize_algorithm='bicubic',
               use_frames=False):
    """Get demo output using ``moviepy``.

    This function will generate video file or gif file from raw video or
    frames, by using ``moviepy``. For more information of some parameters,
    you can refer to: https://github.com/Zulko/moviepy.

    Args:
        video_path (str): The video file path or the rawframes directory path.
            If ``use_frames`` is set to True, it should be rawframes directory
            path. Otherwise, it should be video file path.
        out_filename (str): Output filename for the generated file.
        label (str): Predicted label of the generated file.
        fps (int): Number of picture frames to read per second. Default: 30.
        font_size (int): Font size of the label. Default: 20.
        font_color (str): Font color of the label. Default: 'white'.
        resize_algorithm (str): The algorithm used for resizing.
            Default: 'bicubic'. For more information,
            see https://ffmpeg.org/ffmpeg-scaler.html.
        use_frames: Determine Whether to use rawframes as input. Default:False.
    """

    try:
        from moviepy.editor import (ImageSequenceClip, TextClip, VideoFileClip,
                                    CompositeVideoClip)
    except ImportError:
        raise ImportError('Please install moviepy to enable output file.')

    if use_frames:
        frame_list = sorted(
            [osp.join(video_path, x) for x in os.listdir(video_path)])
        video_clips = ImageSequenceClip(frame_list, fps=fps)
    else:
        video_clips = VideoFileClip(
            video_path, resize_algorithm=resize_algorithm)

    duration_video_clip = video_clips.duration
    text_clips = TextClip(label, fontsize=font_size, color=font_color)
    text_clips = (
        text_clips.set_position(
            ('right', 'bottom'),
            relative=True).set_duration(duration_video_clip))

    video_clips = CompositeVideoClip([video_clips, text_clips])

    out_type = osp.splitext(out_filename)[1][1:]
    if out_type == 'gif':
        video_clips.write_gif(out_filename)
    else:
        video_clips.write_videofile(out_filename, remove_temp=True)
def make_video(video_images_files, name, fps=30):
    """Given list of image files, create video"""
    # create video
    print('\nCreating video...')
    clip = ImageSequenceClip(video_images_files, fps)

    # write video
    clip.write_videofile(name)
    return clip
Exemplo n.º 30
0
    def video(self):
        images = [
            self.path + "blended/" + f for f in listdir(self.path + "blended")
            if isfile(join(self.path + "blended", f))
        ]
        print images

        clip = ImageSequenceClip(images, fps=1)
        clip.write_videofile(self.path + "video/movie.mp4")
Exemplo n.º 31
0
def write_movie(params, logger, observations, step, score, best_agent=True):
    observations = [o.transpose(1, 2, 0) * 255.0 for o in observations]
    clip = ImageSequenceClip(observations, fps=int(30 / params.frame_skip))
    output_dir = logger.get_eval_output()
    clip.write_videofile('{}eval{:0004}_{:00005.0f}.mp4'.format(
        output_dir, step, score * 100))
    if params.use_visdom:
        logger.add_video('{}eval{:0004}_{:00005.0f}.mp4'.format(
            output_dir, step, score * 100),
                         best_agent=best_agent)
Exemplo n.º 32
0
def videoOutput(imgList, outLocation, numLoops):
    # writing video out
    frameList = []

    for i in range(numLoops):
        for img in imgList:
            frameList.append(img)

    vid_clip = ImageSequenceClip(frameList, fps=10)
    vid_clip.write_videofile(outLocation)
    return True
Exemplo n.º 33
0
def plotme(Elats, Elons, plotEclipse, Clats, Clons, plotConflict):
    count = 0

    d = os.path.dirname("globeframes/")
    if not os.path.exists(d):
        os.mkdir(d)

    # Rotate the earth
    for l in range((DEGPERTURN * count - 180), 180, DEGPERTURN):
        fig = plt.figure(figsize=(10, 10))
        map = Basemap(projection="ortho", lat_0=23.4, lon_0=l, resolution="l")

        # Make the globe more realistic
        map.bluemarble(scale=0.2)

        if plotEclipse:
            # compute the native map projection coordinates for countries.
            x, y = map(Elons, Elats)

            # plot filled circles at the locations of the contry.
            map.plot(x, y, "yo", ms=15, picker=5, mew=2)

        if plotConflict:

            x, y = map(Clons, Clats)
            map.plot(x, y, "rx", ms=10, picker=5, mew=4)

            # plot solar eclipse positions
            map.plot(x, y, "rx", ms=6)

        plt.savefig("globeframes/frame{0}".format((str(count).rjust(3, "0"))), facecolor="k")
        count += 1
        plt.clf()
        plt.close(fig)
        print("Percent completed: {} %".format((count * DEGPERTURN / 360) * 100))

    frames = []

    # Put all the frame names in a list
    for i in range(count):
        frames.append("./globeframes/frame{0}.png".format((str(i).rjust(3, "0"))))

    # Create a video file from the frames
    clip = ImageSequenceClip(frames, fps=FPS)
    clip.write_videofile("SpinningGlobe.mp4", fps=FPS)
Exemplo n.º 34
0
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    video_file = args.image_folder + '.mp4'
    print("Creating video {}, FPS={}".format(video_file, args.fps))
    clip = ImageSequenceClip(args.image_folder, fps=args.fps)
    clip.write_videofile(video_file)
Exemplo n.º 35
0
    def run(self):
        """

        :return:
        """
        #   check if folder exists and if not create it
        folder = self._name
        if not os.path.exists(folder):
            os.makedirs(folder)

        #   absolute path to store animation images to use them to create video file
        animation_folder_abs_path = os.path.join(os.getcwd(), folder)

        #   looop through solution data and create figure with opengl function grabFrameBuffer() every i-th step
        for _step in xrange(0, len(self._parent.step), int(self._parent._delta_step)):
            filename = "step_%06d"%_step+".png"

            #   assign step and repaint GL widget
            self._parent._step = int(_step)
            self._parent._update_GL()

            #   get image of current opengl widget scene
            image = self._parent.OpenGLWidget.grabFrameBuffer()

            #   abs path to image object of current simulation time step
            file_abs_path = os.path.join(animation_folder_abs_path, filename)
            #   save image to file
            image.save(file_abs_path)


        #   create video object
        video = ImageSequenceClip(animation_folder_abs_path, fps=24)#24
        #   write data to video object
        __animation_filename = self._name+".avi"

        #   check filename
        __animation_filename = check_filename(__animation_filename)

        video.write_videofile(__animation_filename,codec='mpeg4')

        #   delete animation folder with animation figures
        shutil.rmtree(animation_folder_abs_path)
Exemplo n.º 36
0
def arr2aviMPY(fileName, M, fps):
    """Convert gray-scale Numpy 3D image array to AVI file (use moviepy).
    
    Parameters
    ----------
    fileName : str
        Path for output AVI file.
        
    M : np.ndarray(uint8)
        F x H x W 3D array, representing a sequence of F images, each H x W.
        
    fps : int
        frame rate for the output file.
        
    """
    import numpy as np
    from moviepy.editor import ImageSequenceClip
    
    D = [np.dstack([m] * 3) for m in M]
    clip = ImageSequenceClip(D, fps=fps)    
    clip.write_videofile(fileName, codec='mpeg4', ffmpeg_params=['-vb','1M'])
Exemplo n.º 37
0
	
	#Send a second message to stop the wheel turning
	twist.angular.z = 0
	pub.publish(twist)
		
	key = '' #Reset the key to empty
		
	degChosen.append(deg) #Add the chosen angle to the appropriate array
	
	print round((time.time() - startTime) * 1000) #Print the total time it took for that frame to be processed
	tempAngle += deg #Update the angle
	
	actualDeg.append(tempAngle)
	
turnOff()
expertInput.join() #Have the expert input thread, which should be done, join back to the main thread
	
with open("../datasets/dataset_dagger/data.csv", 'wb') as file: #Open the csv file
	writer = csv.writer(file, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) #Create a writer
	writer.writerow(['frame', 'machine angle', 'expert angle', 'chosen angle', 'angle']) #Write the first row that labels the columns
	for i in range (len(degChosen)): #For each frame
		writer.writerow([i, degMArray[i], degHArray[i], degChosen[i], actualDeg[i]]) #Write the angles to the csv file
		
#Remove the last frame in the case that there aren't enought angles recorded
if not len(frameArray) == len(actualDeg):
	frameArray.pop()

#Create a video using the frames collected
clip = ImageSequenceClip(frameArray, fps=15) 
clip.write_videofile('../datasets/dataset_dagger/dagger.mp4') #
def split_video():

  movie_title = os.path.split(args.source_path)[-1]
  offset_csv = os.path.join(args.target_folder, 'offsets.csv')
  offsets = []
  video = VideoFileClip(args.source_path, audio=False)
  framerate = video.fps
  width = (np.size(video.get_frame(0), 1) - args.middle_gap_pixel_size) / 2
  left_video = moviepy.video.fx.all.crop(video, x1=0, width=width)
  right_video = moviepy.video.fx.all.crop(video, x1=width + args.middle_gap_pixel_size, width=width)
  right_frame_iterator = right_video.iter_frames()
  output_ind = args.output_starting_ind

  for ind, left_frame in enumerate(left_video.iter_frames()):
    left_frame = rgb2gray(left_frame)
    right_frame = rgb2gray(right_frame_iterator.next())
    if (ind % 20 == 0): # INITIALIZE
      left_frames = []
      right_frames = []
      offset_frames = []
      first_start = ind
      offset = randint(1,10)
      second_start = first_start + offset
      offset_left = randint(0, 1) == 1
    if (ind >= first_start and ind < first_start + 10): # ADD FRAMES
      right_frames.append(right_frame)
      left_frames.append(left_frame)
    if (ind >= second_start and ind < second_start + 10): # ADD OFFSET FRAMES
      if (offset_left):
        offset_frames.append(left_frame)
      else:
        offset_frames.append(right_frame)
    if (ind % 20 == 19): # SAVE SEGMENT FRAMES TO JPEG
      if args.output_images:
        assert len(left_frames) == 10, 'Only added ' + str(len(left_frames)) + ' left frames on segment ' + str(output_ind) + '. Should have 10.'
        assert len(right_frames) == 10, 'Only added ' + str(len(right_frames)) + ' right frames on segment ' + str(output_ind) + '. Should have 10.'
        assert len(offset_frames) == 10, 'Only added ' + str(len(offset_frames)) + ' offset frames on segment ' + str(output_ind) + '. Should have 10.'
        for frame_ind, left_frame in enumerate(left_frames):
          misc.toimage(left_frame, cmin=np.min(left_frame), cmax=np.max(left_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-left.jpeg').format(output_ind, frame_ind)))
        for frame_ind, right_frame in enumerate(right_frames):
          misc.toimage(right_frame, cmin=np.min(right_frame), cmax=np.max(right_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-right.jpeg').format(output_ind, frame_ind)))
      else:
        left_video_out = ImageSequenceClip(left_frames, fps=framerate)
        left_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-left.mp4' % output_ind), codec='libx264', audio=False)
        right_video_out = ImageSequenceClip(right_frames, fps=framerate)
        right_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-right.mp4' % output_ind), codec='libx264', audio=False)
      offsets.append({ 'id': '%06d' % output_ind, 'offset_frames': 0 })
      output_ind += 1
      if (offset_left):
        if args.output_images:
          for frame_ind, offset_frame in enumerate(offset_frames):
            misc.toimage(offset_frame, cmin=np.min(left_frame), cmax=np.max(left_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-left.jpeg').format(output_ind, frame_ind)))
          for frame_ind, right_frame in enumerate(right_frames):
            misc.toimage(right_frame, cmin=np.min(right_frame), cmax=np.max(right_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-right.jpeg').format(output_ind, frame_ind)))
        else:
          left_video_out = ImageSequenceClip(offset_frames, fps=framerate)
          left_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-left.mp4' % output_ind), codec='libx264', audio=False)
          right_video_out = ImageSequenceClip(right_frames, fps=framerate)
          right_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-right.mp4' % output_ind), codec='libx264', audio=False)
      else:
        if args.output_images:
          for frame_ind, left_frame in enumerate(left_frames):
            misc.toimage(left_frame, cmin=np.min(left_frame), cmax=np.max(left_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-left.jpeg').format(output_ind, frame_ind)))
          for frame_ind, offset_frame in enumerate(offset_frames):
            misc.toimage(offset_frame, cmin=np.min(right_frame), cmax=np.max(right_frame)).save(os.path.join(args.target_folder, ('seg-{:06d}-frame-{:02d}-right.jpeg').format(output_ind, frame_ind)))
        else:
          left_video_out = ImageSequenceClip(left_frames, fps=framerate)
          left_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-left.mp4' % output_ind), codec='libx264', audio=False)
          right_video_out = ImageSequenceClip(offset_frames, fps=framerate)
          right_video_out.write_videofile(os.path.join(args.target_folder, 'seg-{:06d}-right.mp4' % output_ind), codec='libx264', audio=False)
      offsets.append({ 'id': '{:06d}'.format(output_ind), 'offset_frames': offset })
      output_ind += 1
    if (ind % 1000 == 0):
      print('Finished processing {:d} datapoints.'.format(output_ind))
  os.remove(offset_csv)
  with open(offset_csv, 'w') as offset_csv_file:
    w = csv.DictWriter(offset_csv_file, fieldnames=['id', 'offset_frames'])
    w.writeheader()
    w.writerows(offsets)
  return True
Exemplo n.º 39
0
# pip3 install moviepy
from moviepy.editor import ImageSequenceClip

frames = []

for i in range(180):
    frames.append("./globeframes/frame{0}.png".format((str(i).rjust(3, "0"))))


clip = ImageSequenceClip(frames, fps=20)


clip.write_videofile("SpinningGlobe.mp4", fps=20)  # export as video
# clip.speedx(0.5).write_gif("SpinningGlobe.gif", fps=20) # export as GIF (slow)