python實(shí)現(xiàn)將視頻按幀讀取到自定義目錄
如題,首先讀取視頻路徑,其次根據(jù)視頻名稱創(chuàng)建對(duì)應(yīng)的文件夾,再逐幀將視頻幀讀入。
import cv2
import argparse
import sys
import os
parser = argparse.ArgumentParser(description='tranfer the vedio to img.')
parser.add_argument('-m', '--mode', choices=['folder', 'url'], default='folder')
parser.add_argument('-p', '--path', help='Specify a path [e.g. testModel]', default='E:\DATA\pose_h3.6m\S5\Videos')
parser.add_argument('-pimg', '--imgpath', help='Specify a path [e.g. testModel]', default='F:\pythonprogram\multi_task\img\S5')
args = parser.parse_args(sys.argv[1:])
if args.mode == 'folder':
#get video
withPath = lambda f: '{}/{}'.format(args.path,f)
video = dict((f,cv2.imread(withPath(f))) for f in os.listdir(args.path) if os.path.isfile(withPath(f)))
for key,val in video.items():
fram_video = '{}/{}'.format(args.path,key)
act_cam=key[:-4]
vc=cv2.VideoCapture('{}\{}'.format(args.path,key))
c = 1
# camera
# print('{}\{}\{}.jpg'.format(args.imgpath, act_cam,str(c)))
path = '{}\{}'.format(args.imgpath, act_cam)
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
while rval:
rval, frame = vc.read()
cv2.imwrite('{}\\{}\\{}.jpg'.format(args.imgpath, act_cam,str(c)),frame)
# cv2.imwrite('C:\\Users\\65183\\Desktop\\test\\fuck\\'+str(c)+'.jpg', frame)
c = c + 1
cv2.waitKey(1)
vc.release()
以上這篇python實(shí)現(xiàn)將視頻按幀讀取到自定義目錄就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python之random.sample()和numpy.random.choice()的優(yōu)缺點(diǎn)說(shuō)明
這篇文章主要介紹了Python之random.sample()和numpy.random.choice()的優(yōu)缺點(diǎn)說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Python unittest單元測(cè)試openpyxl實(shí)現(xiàn)過(guò)程解析
這篇文章主要介紹了Python unittest單元測(cè)試openpyxl實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
Python數(shù)據(jù)可視化之Pyecharts使用詳解
Pyecharts是一個(gè)由百度開(kāi)源的、用于生成Echarts圖表的類庫(kù),可以用來(lái)進(jìn)行數(shù)據(jù)可視化分析。本文將詳細(xì)講解一下Pyecharts的使用,需要的可以參考一下2022-04-04
Python數(shù)據(jù)抓取爬蟲(chóng)代理防封IP方法
在本篇內(nèi)容里小編給大家分享了關(guān)于Python數(shù)據(jù)抓取爬蟲(chóng)代理防封IP方法講解,需要的朋友們可以跟著學(xué)習(xí)下。2018-12-12
python?label與one-hot之間的互相轉(zhuǎn)換方式
這篇文章主要介紹了python?label與one-hot之間的互相轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
python進(jìn)階學(xué)習(xí)實(shí)時(shí)目標(biāo)跟蹤示例詳解
這篇文章主要為大家介紹了python進(jìn)階學(xué)習(xí)實(shí)時(shí)目標(biāo)跟蹤示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Python獲取CPU、內(nèi)存使用率以及網(wǎng)絡(luò)使用狀態(tài)代碼
這篇文章主要介紹了Python獲取CPU使用率、內(nèi)存使用率、網(wǎng)絡(luò)使用狀態(tài)的相關(guān)代碼,對(duì)此有需要的朋友一起測(cè)試下。2018-02-02
Python遞歸實(shí)現(xiàn)猴子吃桃問(wèn)題及解析
這篇文章主要介紹了Python遞歸實(shí)現(xiàn)猴子吃桃問(wèn)題及解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07

