由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址
Opencv & gif
reference: https://blog.csdn.net/qq_41500251/article/details/82820806
import time, cv2from PIL import Imageimport numpy as npdef GIF(file):List = []im = Image.open(file)im.seek(1)#skip to the second frametry:while 1:List += [cv2.cvtColor(np.asarray(im.convert()),cv2.COLOR_RGB2BGR)]im.seek(im.tell()+1)except EOFError:#the sequence endspassNum = 0while Num < len(List)*2:Num +=1ID = Num%(len(List))cv2.imshow("OpenCV",List[ID])print(ID)cv2.waitKey(1)time.sleep(0.1)cv2.destroyAllWindows()
for Videos:
from cv2 import cv2import imageioimport numpy# Collection of the imgsframes_list = []# Tossed frames per FPS. When FPS = 1, all frame are saved.FPS = 1cap=cv2.VideoCapture("test_1.mp4")while (True):ret,frame=cap.read()#img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)img = cv2.resize(frame, (460,360))frames_list.append(img)frames = []Num =0for img in frames_list:Num +=1if Num %3 == 0:frames.append(img)gif=imageio.mimsave('test_3.gif',frames,'GIF',duration=1/8)
Enjoy~
由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址
GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗
