/
vidTest.py
97 lines (72 loc) · 1.71 KB
/
vidTest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
##stackoverflow.com/questions/10672578/extract-video-frames-in-python
import cv2
from imgProc import imgProc as ipr
import matplotlib.pyplot as plt
from skimage import color, exposure, io
import numpy as np
vid = 'C:\\Users\\vsimonis\\Downloads\\led_tests\\led_move1.avi'
vc = cv2.VideoCapture(vid)
c = 1
i = 1
modulus = 50
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
'''
plt.figure()
io.imshow(frame)
plt.show()
'''
gframe = color.rgb2gray(frame)
'''
plt.figure()
io.imshow(gframe)
plt.show()
'''
#J = ipr.minmaxx(gframe)
I = ipr.threshHist(gframe)
plt.figure()
io.imshow(I)
plt.show()
#ipr.getCentroidFromRaw(frame)
'''
imgIn1 = gframe.ravel()
#imgOut = np.zeros( (np.shape(imgIn) ) ).ravel()
# Histogram analysis to find maximum peak and associated gl
pxCnt, gL = exposure.histogram( gframe )
indMaxBG = int(np.arange( len(imgIn1) )[pxCnt == max(pxCnt)]) #int()
BGlevel = gL[indMaxBG]
# Nearest min below this max is threshold
d1 = np.zeros( np.shape(pxCnt) )
for i in range( 2 , len(pxCnt) - 1):
# derivative approximation
d1[i] = pxCnt[ i + 1 ] - pxCnt[ i ]
i = 1
p = 0
while ( d1[ indMaxBG - i ] > 0): ### - i!!!
p = indMaxBG - i
print p
i = i + 1
t = gL[ p ]
imgIn1 = gframe.ravel()
imgOut = np.zeros( ( np.shape(gframe) ) ).ravel()
inds = np.arange( len(imgIn1) )[imgIn1 > t]
for ind in inds:
imgOut[ind] = 1
imgOut = np.reshape( imgOut, np.shape(gframe) )
return imgOut
#imgOut = ipr.applyThresh( gframe , t )
"""while rval:
rval, frame = vc.read()
if i % 10 == 0:
x, y = ipr.getCentroidFromRaw(frame)
print x, y
plt.figure()
plt.imshow(frame)
plt.show()
cv2.waitKey(1)
i += 1
vc.release()
"""
'''