HAR笔记--kinetics-400数据集下载和简单处理代码

1--完整项目地址

liujf69/Data-Processing/Kinetics_400

2--参考

Kinetics-400数据集简介及下载

3--简单处理代码

import os
import csv
import cv2

def find_video_name(root_video_path, label, youtube_id):
    video_path = os.path.join(root_video_path, label)
    video_names = os.listdir(video_path)
    for idx, video_name in enumerate(video_names):
        if(video_name[:11] == youtube_id):
            return video_name

def split_frame(raw_csv: str, root_video_path: str, root_output_path: str, debug: bool = True):
    csv_reader = csv.reader(open(raw_csv))
    for idx, row in enumerate(csv_reader): 
        if (idx == 0):
            continue # ['label', 'youtube_id', 'time_start', 'time_end', 'split', 'is_cc'] 
        label, youtube_id, time_start, time_end, split, is_cc = row
        video_name = find_video_name(root_video_path, label, youtube_id)
        print("Process ", idx, " ", video_name)
        
        video_path = os.path.join(root_video_path, label, video_name)
        save_path = os.path.join(root_output_path, label, video_name.split(".")[0])
        if not os.path.exists(save_path):
            os.makedirs(save_path)
        cap = cv2.VideoCapture(video_path)
        frame_idx = 0
        ret = True
        while ret:
            ret, rgb_img = cap.read()  # read each frame
            if (not ret):
                break
            cv2.imwrite(save_path + '/' + str(frame_idx) + '.jpg', rgb_img)
            frame_idx = frame_idx + 1
        
        if debug: # just process one video
            break

if __name__ == "__main__":
    raw_csv = "./label/train_256.csv"
    root_video_path = "./raw-part/compress/train_256"
    root_output_path = "./test"
    split_frame(raw_csv = raw_csv, root_video_path = root_video_path, root_output_path = root_output_path, debug = True)

    print("All Done!")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值