-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotionIdeaFeliz.py
More file actions
143 lines (115 loc) · 3.45 KB
/
MotionIdeaFeliz.py
File metadata and controls
143 lines (115 loc) · 3.45 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import argparse
import imutils
import cv2
import os, sys
import numpy as np
from matplotlib import pyplot as plt
#C:\Python27\python.exe C:\Users\gecete\PycharmProjects\diarization\MotionIdeaFeliz.py -i C:\Users\gecete\Documents\iris\zapas -o zapabuean.png
script_dir = sys.path[0]
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True,
help="path to input video or image files")
ap.add_argument("-o", "--output", required=True,
help="path to output 'long exposure'")
args = vars(ap.parse_args())
(rAvg, gAvg, bAvg) = (None, None, None)
total = 0
def load_images_from_folder(folder):
images = []
for filename in os.listdir(folder):
print(filename)
img1 = cv2.imread(os.path.join(folder, filename))
img = img1 # cv2.resize(img1, (0,0), fx=0.5, fy=0.5)
if img is not None:
images.append(img)
return images
if ("." in args["input"]):
vid_path = os.path.join(script_dir, args["input"])
stream = cv2.VideoCapture(vid_path)
inicio = 657 * 60
fin = inicio + 1
frame_no = inicio
total = inicio
stream.set(cv2.CAP_PROP_POS_FRAMES, frame_no - 1)
(grabbed, frame) = stream.read()
(Bi, Gi, Ri) = cv2.split(frame.astype("float"))
while True:
(grabbed, frame) = stream.read()
if not grabbed:
print("Fin")
break
if total%10 == 0:
# frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)
(B, G, R) = cv2.split(frame.astype("float"))
if rAvg is None:
rAvg = Ri
bAvg = Bi
gAvg = Gi
else:
length = stream.get(cv2.CAP_PROP_FRAME_COUNT)
print(total - fin)
sys.stdout.write('\r' + str(total * 100 / length) + "% Loading ")
(m, n) = rAvg.shape
for i in xrange(m):
for j in xrange(n):
if rAvg[i][j] > Ri[i][j]:
rAvg[i][j] = R[i][j]
if bAvg[i][j] > Bi[i][j]:
bAvg[i][j] = B[i][j]
if gAvg[i][j] > Gi[i][j]:
gAvg[i][j] = G[i][j]
total += 1
if total == fin:
break
else: # imagenes
stream = load_images_from_folder(args["input"]);
print("Total fotos: " + str(len(stream)))
imgq = cv2.imread('www.jpg')
hsv = cv2.cvtColor(imgq, cv2.COLOR_BGR2HSV)
(Bi, Gi, Ri) = cv2.split(hsv.astype("float"))
y, x, _ = plt.hist(np.ndarray.flatten(Bi), bins=180, density=True)
matriz = [y, x]
elem = np.argsort(y)
print(elem[-1], elem[-2])
y[::-1].sort()
print(y[0], y[1])
total=0
np.shape(Bi)
rAvgG = np.zeros(np.shape(Bi))
bAvgG = np.zeros(np.shape(Bi))
gAvgG = np.zeros(np.shape(Bi))
for imagen in stream:
# imagen = cv2.resize(imagen, (0,0), fx=0.5, fy=0.5)
hsv = cv2.cvtColor(imagen, cv2.COLOR_BGR2HSV)
(B, G, R) = cv2.split(hsv.astype("float"))
height, width, channels = hsv.shape;
s = (height, width);
print(total)
if rAvg is None:
rAvg = R
bAvg = B
gAvg = G
else:
(m, n) = rAvg.shape
for i in xrange(m):
for j in xrange(n):
if np.abs(bAvg[i][j]-elem[-1])>3:
Ri[i][j] = rAvg[i][j]
Bi[i][j] = bAvg[i][j]
Gi[i][j] = gAvg[i][j]
total += 1
avg = cv2.merge([Bi, Gi, Ri]).astype("uint8")
y, x, _ = plt.hist(np.ndarray.flatten(Bi), bins=180, density=True)
elem = np.argmax(y)
elem2 = np.argmax([y[1:np.size(y)-1]])
print(elem, elem2)
y[::-1].sort()
elem = np.argmax(y)
elem2 = np.argmax([y[1:np.size(y)-1]])
print(y[0],y[1])
print(elem,elem2)
plt.show()
avg = cv2.cvtColor(avg, cv2.COLOR_HSV2BGR)
cv2.imwrite(args["output"], avg)
if ("." in args["input"]):
stream.release()