AI讓兒童繪畫動(dòng)起來(lái)-程序員帶娃必備
項(xiàng)目效果演示
項(xiàng)目描述
項(xiàng)目地址
http: //www.fairanimateddrawings.com
github:https://github.com/facebookresearch/AnimatedDrawings
安裝環(huán)境
該項(xiàng)目已在 macOS Ventura 13.2.1 和 Ubuntu 18.04 上進(jìn)行了測(cè)試。如果您在其他操作系統(tǒng)上安裝,則可能會(huì)遇到問(wèn)題。
我們強(qiáng)烈建議在安裝 Animated Drawings 之前激活 Python 虛擬環(huán)境。Conda 的 Miniconda 是一個(gè)不錯(cuò)的選擇。
安裝步驟
# create and activate the virtual environment
conda create --name animated_drawings python=3.8.13
conda activate animated_drawings
# clone AnimatedDrawings and use pip to install
git clone https://github.com/facebookresearch/AnimatedDrawings.git
cd AnimatedDrawings
pip install -e .
現(xiàn)在一切都已設(shè)置完畢,讓我們?yōu)橐恍├L圖制作動(dòng)畫吧!首先,請(qǐng)按照下列步驟操作:
打開(kāi)終端并激活animated_drawings conda環(huán)境:
~ % conda activate animated_drawings
確保您位于 AnimatedDrawings 的根目錄中:
(animated_drawings) ~ % cd {location of AnimatedDrawings on your computer}
啟動(dòng)Python解釋器:
(animated_drawings) AnimatedDrawings % python
將以下兩行復(fù)制并粘貼到解釋器中:
from animated_drawings import render
render.start('./examples/config/mvc/interactive_window_example.yaml')
如果一切都安裝正確,屏幕上應(yīng)該會(huì)出現(xiàn)一個(gè)交互式窗口。(使用空格鍵暫停/取消暫停場(chǎng)景,使用箭頭鍵及時(shí)前后移動(dòng),使用 q 關(guān)閉屏幕。)
這里的幕后發(fā)生了很多事情。角色、動(dòng)作、場(chǎng)景等都由配置文件控制,例如
interactive_window_example.yaml. 下面,我們展示如何通過(guò)改變配置文件來(lái)實(shí)現(xiàn)不同的效果。您可以在此處了解有關(guān)配置文件的更多信息。
導(dǎo)出 MP4 視頻
假設(shè)您想將動(dòng)畫保存為視頻文件,而不是直接在窗口中查看。通過(guò)將這些行復(fù)制到 Python 解釋器中來(lái)指定不同的示例配置:
from animated_drawings import render
render.start('./examples/config/mvc/export_mp4_example.yaml')
動(dòng)畫不是保存在交互式窗口中,而是保存到文件 video.mp4 中,該文件位于與腳本相同的目錄中。
導(dǎo)出透明.gif
也許您想要透明的 .gif 而不是 .mp4?在 Python 解釋器中復(fù)制這些行:
from animated_drawings import render
render.start('./examples/config/mvc/export_gif_example.yaml')
無(wú)頭渲染
如果您想無(wú)頭生成視頻(例如在通過(guò) ssh 訪問(wèn)的遠(yuǎn)程服務(wù)器上),則需要USE_MESA: True在view配置文件的 部分中指定。
view:
USE_MESA: True
將多個(gè)角色添加到場(chǎng)景中
通過(guò)在配置場(chǎng)景的“ANIMATED_CHARACTERS”列表中指定多個(gè)條目,可以將多個(gè)角色添加到視頻中。要親自查看,請(qǐng)從 AnimatedDrawings 根目錄中的 Python 解釋器運(yùn)行以下命令:
from animated_drawings import render
render.start('./examples/config/mvc/multiple_characters_example.yaml')
添加背景圖片
假設(shè)您想向動(dòng)畫添加背景。您可以通過(guò)在配置中指定圖像路徑來(lái)完成此操作。從 AnimatedDrawings 根目錄中的 Python 解釋器運(yùn)行以下命令:
from animated_drawings import render
render.start('./examples/config/mvc/background_example.yaml')
感興趣的小伙伴們,抓緊行動(dòng)起來(lái)吧。