forked from ineuron/mouseVideo-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoProcess.py
67 lines (59 loc) · 1.82 KB
/
videoProcess.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
62
63
64
65
66
67
import numpy as np
import matplotlib.pylab as plt
import os.path
import sys
import subprocess
import videoAnalysisLib as va
#fname = '/lmb/home/tbranco/115954a_hab2.avi'
#saveDir = '/lmb/home/tbranco/analysis/'
# Input arguments:
# filename saveDir startFrame nfile secPerCpu
# Note: filename has full path
fname = sys.argv[1]
saveDir = sys.argv[2]
#fname = subprocess.check_output('readlink '+fname, shell=True)
#fname = fname.rstrip('\n')
startFrame = int(sys.argv[3])
#tEnd = int(sys.argv[4])
nfile = sys.argv[4]
ncall = sys.argv[5]
if len(nfile)==1:
nfile='00'+nfile
elif len(nfile)==2:
nfile='0'+nfile
if len(ncall)==1:
ncall='00'+ncall
elif len(ncall)==2:
ncall='0'+ncall
secPerCpu = float(sys.argv[6])
nestThreshold = 10
aviProps = va.getAVIinfo(fname)
print fname, aviProps
fileName = va.getFileName(fname)
trackFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.txt'
aviFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.avi'
bgSubFname = saveDir + 'file' + str(nfile) + '_' + ncall
tStart = va.frame2time(startFrame, aviProps) + (int(ncall)-1)*secPerCpu
tEnd = tStart + secPerCpu
print tStart, tEnd
while True:
try:
print(saveDir+"bg.npy")
bg = np.load(saveDir + "bg.npy")
print("Background file loaded")
except IOError:
print("Cannot find background file ")
break
try:
pmts = np.load(saveDir + "pmts.npy")
print("Parameters file loaded")
except IOError:
print("Cannot find parameters file ")
break
print("Processing video...")
mousePositions, meanFrame = va.processFrames(fname, aviFname, aviProps, tStart, tEnd, bg, pmts, nestThreshold, saveAVI=True)
np.savetxt(trackFname, mousePositions)
np.save(bgSubFname, meanFrame)
#data, results = va.analyseData(trackFname, aviProps, bg, pmts, PLOT=False)
#print(".AVI output file saved")
break