-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_eyedataset.py
50 lines (46 loc) · 1.46 KB
/
make_eyedataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from frame_utils import get_corrd, save, sep, binarize
import os
import cv2
from tqdm import tqdm
import numpy as np
import pandas as pd
CAM_HEIGHT = 1440
def check(file_path:str):
if os.path.exists(file_path):
return True
else:
print('FileNotFoundError')
return False
def get_eye_coord(video_path:str):
#動画の読み込み
mov_file = os.path.normpath(video_path)
cap = cv2.VideoCapture(mov_file)
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
#中心座標を格納するリスト
frame_ids = []
eye_x = []
eye_y = []
image = []
#メインループスタート
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
for frame_id in tqdm(range(0,total_frames)):
#フレームを取得
ret, frame = cap.read()
if ret:
#get binarized iamge
real,eye = sep.sep_y(frame,corrd = CAM_HEIGHT)
bin_image = binarize.binarize_image(frame)
#get center of biggest object
x,y = get_corrd.cog(bin_image.astype(np.uint8))
eye_x.append(x)
eye_y.append(y)
frame_ids.append(frame_id)
image_path = save.image(real,'frame'+str(frame_id))
image.append(image_path)
else:
print(f'error occurd at frame{frame_id}')
break
cap.release()
df = pd.DataFrame({'frame_ids':frame_ids,'x':eye_x,'y':eye_y,'image':image})
save.csv(df,'eye_dataset')
return df