日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python實現(xiàn)視頻分幀效果

系統(tǒng) 1788 0

本文實例為大家分享了python實現(xiàn)視頻分幀的具體代碼,供大家參考,具體內(nèi)容如下

            
import cv2 
vidcap = cv2.VideoCapture('005.avi') 
success,image = vidcap.read() 
count = 0 
success = True 
while success: 
 success,image = vidcap.read() 
 cv2.imwrite("frame%d.jpg" % count, image)  # save frame as JPEG file 
 if cv2.waitKey(10) == 27:      
  break 
 count += 1 


          

python tools:將視頻的每一幀提取并保存

            
# coding=utf-8 
 
import os 
import cv2 
 
videos_src_path = "/home/wgp/視頻/" 
video_formats = [".MP4", ".MOV"] 
frames_save_path = "/home/wgp/視頻/" 
width = 320 
height = 240 
time_interval = 50 
 
 
def video2frame(video_src_path, formats, frame_save_path, frame_width, frame_height, interval): 
 """ 
 將視頻按固定間隔讀取寫入圖片 
 :param video_src_path: 視頻存放路徑 
 :param formats: 包含的所有視頻格式 
 :param frame_save_path: 保存路徑 
 :param frame_width: 保存幀寬 
 :param frame_height: 保存幀高 
 :param interval: 保存幀間隔 
 :return: 幀圖片 
 """ 
 videos = os.listdir(video_src_path) 
 
 def filter_format(x, all_formats): 
  if x[-4:] in all_formats: 
   return True 
  else: 
   return False 
 
 videos = filter(lambda x: filter_format(x, formats), videos) 
 
 for each_video in videos: 
  print "正在讀取視頻:", each_video 
 
  each_video_name = each_video[:-4] 
  os.mkdir(frame_save_path + each_video_name) 
  each_video_save_full_path = os.path.join(frame_save_path, each_video_name) + "/" 
 
  each_video_full_path = os.path.join(video_src_path, each_video) 
 
  cap = cv2.VideoCapture(each_video_full_path) 
  frame_index = 0 
  frame_count = 0 
  if cap.isOpened(): 
   success = True 
  else: 
   success = False 
   print("讀取失敗!") 
 
  while(success): 
   success, frame = cap.read() 
   print "---> 正在讀取第%d幀:" % frame_index, success 
 
   if frame_index % interval == 0: 
    resize_frame = cv2.resize(frame, (frame_width, frame_height), interpolation=cv2.INTER_AREA) 
    # cv2.imwrite(each_video_save_full_path + each_video_name + "_%d.jpg" % frame_index, resize_frame) 
    cv2.imwrite(each_video_save_full_path + "%d.jpg" % frame_count, resize_frame) 
    frame_count += 1 
 
   frame_index += 1 
 
 cap.release() 
 
 
if __name__ == '__main__': 
 video2frame(videos_src_path, video_formats, frames_save_path, width, height, time_interval) 
          

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东辽县| 万盛区| 高平市| 马公市| 武定县| 漳州市| 西乌| 天津市| 叶城县| 江达县| 柘城县| 响水县| 定兴县| 高雄县| 师宗县| 永丰县| 涞源县| 安达市| 屏东县| 宣化县| 青冈县| 祁东县| 宁河县| 枣阳市| 格尔木市| 黔东| 乐陵市| 宕昌县| 绥中县| 广水市| 荥经县| 正宁县| 彭水| 凤台县| 安丘市| 蓝山县| 北海市| 阳春市| 六安市| 夹江县| 太康县|