-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeapImageProcessing.py
61 lines (42 loc) · 1.84 KB
/
LeapImageProcessing.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
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 8 12:59:32 2018
@author: ich
"""
import os
import shutil
import numpy as np
root = os.getcwd()
orig_data_path = root + "/RecordedData"
proc_data_path = root + "/ProcessedData"
gestures = os.listdir(orig_data_path)
for i in range(len(gestures)):
orig_gest_path = os.path.join(orig_data_path, gestures[i])
proc_gest_path = os.path.join(proc_data_path, gestures[i])
if not os.path.exists(proc_gest_path):
os.mkdir(proc_gest_path)
users = os.listdir(orig_gest_path)
repetition = 0
for j in range(len(users)):
orig_user_path = os.path.join(orig_gest_path, users[j])
# read pressed.txt
pressed_file = open(os.path.join(orig_user_path,"pressed.txt"), "r")
pressed = pressed_file.readlines()
pressed_file.close()
# find changes from 0 to 1
changes = np.where(np.roll(pressed,1)!=pressed)[0]
index = np.arange(0, len(changes), 2)
# copy frames with pressed 1 on each change to a different directory
for l in index:
if l<len(changes):
init = changes[l]
end = changes[l+1]
images = np.arange(init, end)
proc_rep_path = os.path.join(proc_gest_path, "rep_"+str(repetition).zfill(3))
if not os.path.exists(proc_rep_path):
os.mkdir(proc_rep_path)
for k in range(len(images)):
img_orig = os.path.join(orig_user_path, "image_"+str(images[k]).zfill(5)+".png")
img_proc = os.path.join(proc_rep_path, "image_"+str(k).zfill(3)+".png")
shutil.copy(img_orig, img_proc)
repetition = repetition + 1