【AI】視頻動漫化


一、功能

將一個現實中的人物視頻,讓視頻變成動漫的風格

二、實現原理

基於github上的圖片動漫化ai項目,其不支持圖片,所以我通過將視頻拆分為大量的圖片,然后將圖片全部轉換為動漫圖片,最后將所有的圖片進行合並,即可間接將視頻進行動漫化

三、操作方法

1、你需要學會怎么將視頻拆分為圖片,以及怎么將圖片合並為視頻,可參考我的文章:視頻拆分為圖片、圖片合並為視頻(帶聲音)
2、你需要有我的python腳本,本文會給出

點擊查看代碼
import os

import requests,json,base64,urllib3,time,re,os
source_path=r"C:\Users\painter\Desktop\視頻拆分圖片-圖片合並成視頻\output\\"    #這里是待動漫化處理的圖片路徑
filenames=os.listdir(source_path)

for filename in filenames:   #獲取每一張圖片的文件名
    try:
        ext = filename.split('.')[1]
        with open(source_path+filename,"rb") as f:
            tupian=f.read()
        # print(tupian)
        tupian="data:image/{};base64,".format(ext)+base64.b64encode(tupian).decode()
        # print(tupian)
        proxy={"http://":"127.0.0.1:8080","https://":"127.0.0.1:8080"}
        headers={
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36',
        'Sec-Ch-Ua-Platform': "Windows",
        'Content-Type': 'application/json',
        'Origin': 'https://hf.space',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Referer': 'https://hf.space/gradioiframe/akhaliq/AnimeGANv2/+'}
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        r = requests.post(url='https://hf.space/gradioiframe/akhaliq/AnimeGANv2/api/queue/push/',headers=headers,json={"data": [tupian,"version 2 (\ud83d\udd3a robustness,\ud83d\udd3b stylizatior)"],"action":"predict"},verify=False)
        hash=r.json()["hash"]
        hash={"hash":hash}
        time.sleep(7)
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        req=requests.post(url="https://hf.space/gradioiframe/akhaliq/AnimeGANv2/api/queue/status/",headers=headers,json=hash,verify=False)
        # print(req.json())
        # urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        # req1=requests.post(url="https://hf.space/gradioiframe/akhaliq/AnimeGANv2/api/queue/status/",headers=headers,json=hash,verify=False)
        img=req.json()["data"]["data"][0].replace("data:image/png;base64,","")
        img=base64.b64decode(img)
        # base64.b64encode(tupian).decode()
        # print(img)

        #寫入處理好的動漫圖片,將其寫入到原來的原圖片路徑,為了節省空間,對原圖片進行覆蓋處理
        with open(source_path+filename,"wb") as f:
            f.write(img)
        print("已完成:{}".format(filename))
        # print(result)
    except:
        pass

四、效果視頻


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM