── data
└── face_classfication
├── dst:加工した画像の出力用フォルダ
├── img:画像用のフォルダ
└── video:動画用のフォルダ
マウントは以下のコードを実行後、Google Driveへのアクセス権限を許可します。
from google.colab import drive
drive.mount('/content/drive')
入出力用のフォルダを作成
import os
# 動画名を指定する
video_name = "動画名"
# imgフォルダをマウント(なければ作成)
src_img_dir = "/content/drive/MyDrive/data/face_classfication/img"
if not os.path.exists(src_img_dir):
os.makedirs(src_img_dir)
# 画像を入れるフォルダをマウント(なければ作成)
src_img_fold = "/content/drive/MyDrive/data/face_classfication/img/"+video_name
if not os.path.exists(src_img_fold):
os.makedirs(src_img_fold)
from PIL import Image
from PIL import ImageDraw
# dstフォルダをマウント(なければ作成)
dst_img_dir = "/content/drive/MyDrive/data/face_classfication/dst"
if not os.path.exists(dst_img_dir):
os.makedirs(dst_img_dir)
# 加工した画像を入れるフォルダをマウント(なければ作成)
dst_img_fold = "/content/drive/MyDrive/data/face_classfication/dst/"+video_name
if not os.path.exists(dst_img_fold):
os.makedirs(dst_img_fold)
# PILを使って左上にフレーム番号を追加(使わないためコメントアウト)
for i, file in enumerate(src_files):
im = Image.open(file)
draw = ImageDraw.Draw(im)
draw.text((10,10), "{0:04d}".format(i), fill="#ff0")
dst_file = "{dir}/{index:04d}.jpg".format(dir=dst_img_fold,index=i)
im.save(dst_file