-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_data.py
58 lines (45 loc) · 1.39 KB
/
read_data.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
51
52
53
54
55
56
57
58
# reads in data from video and annotations file
# eventually want to save images to training folder on github
import numpy as np
import cv2
import os
labels = {
'no label': 0,
'tongue': 1,
'paw': 2,
'groom': 3,
'air lick': 4,
'chin': 5,
'air groom': 6,
'no contact': 7,
'tongue out': 8,
'ambiguous': 9,
}
# class to read in video and annotations
class readVideoAnnotations():
def __init__(self, video_path, annotations_path):
self.vidPath = video_path
self.anPath = annotations_path
if not os.path.exists('./images'):
for key in labels:
os.makedirs('./images/%s' %(key))
def readAnnotations(self):
self.annotations = np.load(self.anPath)['lickStates']
print(set(self.annotations))
def readVideo(self):
self.vid = cv2.VideoCapture(self.vidPath)
print(self.vid.get(cv2.CAP_PROP_FRAME_COUNT))
success,image = self.vid.read()
count = 0
while success:
success,image = self.vid.read()
#print('Read a new frame: ', success)
count += 1
print(count)
if __name__ == '__main__':
folder = '//10.128.50.43/sd6.3/habituation/'
vidFile = '1047487717_521466_20200831/1047487717_521466_20200831.behavior.mp4'
annotationFile = '1047487717_521466_20200831/1047487717_521466_20200831.behavior_08312020_212513_sync.npz'
readData = readVideoAnnotations(folder + vidFile, folder + annotationFile)
readData.readAnnotations()
readData.readVideo()