Python中讀取指定文件夾多個圖片使用視頻播放及視頻圖片格式轉換

一、視頻轉圖片python

#!/usr/bin/env python  
import cv2  
vc=cv2.VideoCapture("Your_Vid's_Name.mp4")  
c=1  
if vc.isOpened():  
    rval,frame=vc.read()  
else:  
    rval=False  
while rval:  
    rval,frame=vc.read()  
    cv2.imwrite('The_Path_to_Save_Your_Pics'+str(c)+'.jpg',frame)  
    c=c+1  
    cv2.waitKey(1)  
vc.release()

 

二、圖片轉視頻文件app

#!/usr/bin/env python  
import cv2  
from cv2 import VideoWriter,VideoWriter_fourcc,imread,resize  
import os  
img_root="The_Address_of_Your_Pics'_folder"  
#Edit each frame's appearing time!  
fps=5  
fourcc=VideoWriter_fourcc(*"MJPG")  
videoWriter=cv2.VideoWriter("The_Way_You_Want_to_Save_Your_Vid.avi",fourcc,fps,(1200,1200))  
  
im_names=os.listdir(img_root)  
for im_name in range(len(im_names)):  
    frame=cv2.imread(img_root+str(im_name)+'.jpg')  
    print im_name  
    videoWriter.write(frame)  
      
videoWriter.release()

 

三、Python中讀取指定文件夾多個圖片使用視頻播放ide

def readImageShowVideo(imagepath):
    img_path = gb.glob(os.path.join(imagepath, '*.jpg'))
    print(img_path)
    # img_path = "PETS2006/ROI.bmp"
    for path in img_path:
        img = cv2.imread(path)
        cv2.imshow('frame', img)
        cv2.waitKey(30)

 

分享無價,轉載請註明出處!.net

http://www.javashuo.com/article/p-tzyhbysc-me.htmlcode

相關文章
相關標籤/搜索