第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

plt如何將單個視頻文件顯示為html?

plt如何將單個視頻文件顯示為html?

翻翻過去那場雪 2023-08-15 16:30:17
我無法僅顯示 html 格式的一張圖像。此代碼片段并排顯示兩個媒體,一個是照片,另一個是駕駛視頻,我只想查看駕駛視頻import imageioimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animationfrom skimage.transform import resizefrom IPython.display import HTMLimport warningswarnings.filterwarnings("ignore")source_image = imageio.imread('/content/gdrive/My Drive/first-order-motion-model/stat.png')driving_video = imageio.mimread('/content/gdrive/My Drive/first-order-motion-model/obama.mp4')#Resize image and video to 256x256source_image = resize(source_image, (256, 256))[..., :3]driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video]def display(source, driving, generated=None):? ? fig = plt.figure(figsize=(8 + 4 * (generated is not None), 6))? ? ims = []? ? for i in range(len(driving)):? ? ? ? cols = [source]? ? ? ? cols.append(driving[i])? ? ? ? if generated is not None:? ? ? ? ? ? cols.append(generated[i])? ? ? ? im = plt.imshow(np.concatenate(cols, axis=1), animated=True)? ? ? ? plt.axis('off')? ? ? ? ims.append([im])? ? ani = animation.ArtistAnimation(fig, ims, interval=50, repeat_delay=1000)? ? plt.close()? ? return aniHTML(display(source_image, driving_video).to_html5_video())如果可能的話,我很樂意接受對我嘗試了幾個小時但失敗的另一件事的幫助:我想將 25 張圖像放入一個文件夾中,并使用相同的駕駛視頻對所有圖像進行深度偽造,然后在一個視頻中將它們顯示在 5x5 網(wǎng)格中。
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻1784條經(jīng)驗 獲得超2個贊

要顯示單個視頻,您必須從列表中刪除圖像 -cols = []而不是cols = [source]


我無法測試它,但它的工作原理是這樣的

  • 使用視頻文件名創(chuàng)建 5x5 列表

  • 讀取每個視頻并轉(zhuǎn)換為幀列表

  • 使用索引來連接行中的幀并將行連接到單個圖像。

通過這種方式,它會創(chuàng)建顯示為動畫的圖像列表。

all_filenames = [

    # row 1

    [

        '/content/gdrive/My Drive/first-order-motion-model/video1.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/video2.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/video3.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/video4.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/video5.mp4',

    ],

    # row 2

    [

        '/content/gdrive/My Drive/first-order-motion-model/other1.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/other2.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/other3.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/other4.mp4',

        '/content/gdrive/My Drive/first-order-motion-model/other5.mp4',

    ],

    # row 3

    # etc.

]


# --- load all videos and convert every video to list of frames ---


all_videos = []


for row in all_filenames:

    row_videos = []

    for filename in row:

        # read video

        video = imageio.mimread(filename)

        # convert to list of frames

        frames = [resize(frame, (256, 256))[..., :3] for frame in video]

        # keep it in row

        row_videos.append(frames)

    # keep row in `all_videos`

    all_videos.append(row_videos)

    

# --- concatenate list 5x5 to images ---


def display(all_videos):

    fig = plt.figure(figsize=(4*5, 4*5))


    all_images = []

    

    for i in range(len(all_videos[0][0])):  # use len of first video in first row  but it would rather use `min()` for all videos

        col_images = [] 

        for row in all_videos:

            row_images = []

            for video in row:

                row_images.append(video[i])

            # concatenate every row

            row_img = np.concatenate(row_images, axis=1)

            col_images.append(row_img)

        # concatenate rows to single images

        col_img = np.concatenate(col_images, axis=0)

        img = plt.imshow(col_img, animated=True)

        plt.axis('off')

        all_images.append([img])


    ani = animation.ArtistAnimation(fig, all_images, interval=50, repeat_delay=1000)

    plt.close()

    return ani


HTML(display(all_videos).to_html5_video())


查看完整回答
反對 回復(fù) 2023-08-15
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號