Skip to content

Commit cc11fa7

Browse files
committed
.
1 parent 391c109 commit cc11fa7

23 files changed

+476
-377
lines changed

Latex/estabilizacion.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ def checkedTrace(img0, img1, p0, back_threshold = 1.0):
2323
return p1, status
2424

2525
if __name__ == '__main__':
26-
frames = []
2726
import sys
2827
try:
2928
name = sys.argv[1]
3029
nout = sys.argv[2]
3130
except:
3231
print("Error, introduce los nombre de los ficheros de entrada y salida")
3332
sys.exit()
34-
33+
frames = []
3534
cap = cv2.VideoCapture(name)
3635
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
3736
size = (int(cap.get( cv.CV_CAP_PROP_FRAME_WIDTH)),int(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)))
@@ -62,14 +61,13 @@ def checkedTrace(img0, img1, p0, back_threshold = 1.0):
6261
except:
6362
pass
6463

65-
old_frame = cv2.warpPerspective(frame, H, (w, h), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
66-
frames.append(old_frame)
67-
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
68-
p0 = cv2.goodFeaturesToTrack(old_gray, mask = None, **feature_params)
69-
cv2.cornerSubPix(old_gray, p0, (5, 5), (-1, -1), term)
70-
count += 1
64+
old_frame = cv2.warpPerspective(frame, H, (w, h), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
65+
frames.append(old_frame)
66+
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
67+
p0 = cv2.goodFeaturesToTrack(old_gray, mask = None, **feature_params)
68+
cv2.cornerSubPix(old_gray, p0, (5, 5), (-1, -1), term)
69+
count += 1
7170
writer = cv2.VideoWriter(nout, cv.CV_FOURCC('M','J','P','G'), fps, size)
7271
for frm in frames:
7372
writer.write(frm)
74-
cv2.destroyAllWindows()
7573
cap.release()

Latex/estabilizacion_acelerometro.py

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,57 +76,52 @@ def recalculate_pos(x, z, d, f):
7676
except:
7777
print("Error, introduce nombre del archivo de entrada")
7878
sys.exit()
79+
frames = []
80+
nout = "out-" + name
7981
cap = cv2.VideoCapture(name)
8082
x, y, z = calculate_movement(accname)
8183

8284

83-
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)/2
84-
85+
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
86+
fps=16
87+
size = (int(cap.get( cv.CV_CAP_PROP_FRAME_WIDTH)),int(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)))
8588
t = 0.0
8689
f = 0.004
87-
dist = 1.2
90+
dist = 1.4
8891

8992
ret, old_frame = cap.read()
9093
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
9194

95+
frames.append(old_frame)
9296

93-
cv2.imshow('original',old_frame)
94-
cv2.imshow('stabilized',old_frame)
95-
96-
while(1):
97+
while(ret):
9798
ret,frame = cap.read()
98-
if not ret:
99-
break
100-
cv2.imshow('original',frame)
101-
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
102-
t = cap.get(cv2.cv.CV_CAP_PROP_POS_MSEC)/1000
103-
104-
h, w = old_frame.shape[:2]
105-
106-
#calculamos la traslacion
107-
dx = np.interp(t,[d[0] for d in x], [d[1] for d in x])
108-
dy = np.interp(t,[d[0] for d in y], [d[1] for d in y])
109-
dz = np.interp(t,[d[0] for d in z], [d[1] for d in z])
99+
if ret:
100+
cv2.imshow('original',frame)
101+
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
102+
t = cap.get(cv2.cv.CV_CAP_PROP_POS_MSEC)/1000
103+
h, w = old_frame.shape[:2]
110104

111-
dx = recalculate_pos(dx, dz, dist, f)
112-
dy = recalculate_pos(dy, dz, dist, f)
105+
#calculamos la traslacion
106+
dx = np.interp(t,[d[0] for d in x], [d[1] for d in x])
107+
dy = np.interp(t,[d[0] for d in y], [d[1] for d in y])
108+
dz = np.interp(t,[d[0] for d in z], [d[1] for d in z])
113109

114-
dx = dx*(7659.0)
115-
dy = dy*(7659.0)
110+
dx = recalculate_pos(dx, dz, dist, f)
111+
dy = recalculate_pos(dy, dz, dist, f)
116112

117-
M = np.array([[1, 0, dx],[0, 1, dy]])
113+
dx = dx*(7659.0)
114+
dy = dy*(7659.0)
118115

116+
M = np.array([[1, 0, dx],[0, 1, dy]])
119117

120-
overlay = cv2.warpAffine(frame, M, (w,h), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
121-
122-
123-
old_frame = overlay.copy()
124-
cv2.imshow('stabilized',overlay)
125-
k = cv2.waitKey(30) & 0xff
126-
if k == 27:
127-
break
118+
old_frame = cv2.warpAffine(frame, M, (w,h), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
119+
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
128120

129-
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
121+
frames.append(old_frame)
130122

123+
writer = cv2.VideoWriter(nout, cv.CV_FOURCC('M','J','P','G'), fps, size)
124+
for frm in frames:
125+
writer.write(frm)
131126
cv2.destroyAllWindows()
132127
cap.release()

Latex/ilum_sensor.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_array(filename):
1010
array = []
1111
first = True
1212
old_date = 0.0
13-
for line t = t + 1/fps in acc_file:
13+
for line in acc_file:
1414
if first:
1515
aux_date = line.split(":")
1616
t0 = ((int(aux_date[0])*60 + int(aux_date[1]))*60 + float(aux_date[2]))
@@ -81,31 +81,42 @@ def draw_hist(im, name):
8181
except:
8282
print("Error, introduce nombre del archivo de entrada")
8383
sys.exit()
84+
frames = []
85+
nout = "out-" + name
8486
cap = cv2.VideoCapture(name)
8587
array = get_array(illuname)
8688
i = 0
87-
while(1):
89+
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
90+
fps = 16
91+
size = (int(cap.get( cv.CV_CAP_PROP_FRAME_WIDTH)),int(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)))
92+
ret = True
93+
while(ret):
8894
ret,frame = cap.read()
8995
t = cap.get(cv2.cv.CV_CAP_PROP_POS_MSEC)/1000
90-
if not ret:
91-
break
92-
i = 0
93-
while i < len(array)-1:
94-
if (array[i][1]<=t) and (t<array[i+1][1]):
95-
break
96-
i = i+1
97-
lux = array[i][0]
98-
if lux > 400:
99-
lux = 400
100-
k = pow((lux/400),1./4)
101-
x = -2*k+1
102-
y = pow(10,x)
96+
t = t*1.197
97+
if ret:
98+
i = 0
99+
while i < len(array)-1:
100+
if (array[i][1]<=t) and (t<array[i+1][1]):
101+
break
102+
i = i+1
103+
lux = array[i][0]
104+
if lux > 400:
105+
lux = 400
106+
k = pow((lux/400),1./4)
107+
x = -2*k+1
108+
y = pow(10,x)
103109

104110

105-
gr = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
106-
out = autolevels(gr, y)
107-
cv2.imshow('Sensor-in',gr)
108-
cv2.imshow("Sensor-out", out)
111+
gr = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
112+
out = autolevels(gr, y)
113+
out = cv2.cvtColor(out, cv2.COLOR_GRAY2BGR)
114+
frames.append(out)
115+
109116

110-
c = cv2.waitKey(33)
111-
if (c==27): break
117+
118+
writer = cv2.VideoWriter(nout, cv.CV_FOURCC('M','J','P','G'), fps, size)
119+
for frm in frames:
120+
writer.write(frm)
121+
cv2.destroyAllWindows()
122+
cap.release()

Latex/logo.gif

580 KB
Loading

Latex/logo.jpg

495 KB
Loading

Latex/luz.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import cv2
2+
import cv2.cv as cv
3+
import numpy as np
4+
5+
6+
def correct_gamma(img, dst, correction):
7+
8+
temp = img.copy()/255.0
9+
temp = np.array(temp, dtype=np.float32)
10+
temp = cv2.pow(temp, correction)*255.0
11+
return temp
12+
13+
def doCeq(im,a,t):
14+
aint = np.abs(im)
15+
m = np.power(aint, a)
16+
m = np.mean(m)
17+
m = np.power(m,1.0/a)
18+
19+
im = im/m
20+
aint = np.abs(im)
21+
22+
#m = np.array([[pow(min(t,x),a) for x in y] for y in aint])
23+
m = np.minimum(aint, t)
24+
m = np.power(m, a)
25+
26+
m = np.mean(m)
27+
m = np.power(m,1.0/a)
28+
im = im/m
29+
30+
im = t*np.tanh(im/t)
31+
im = cv2.convertScaleAbs(im, alpha=127, beta=0)
32+
return im
33+
34+
def process_image(img):
35+
36+
gr = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
37+
gr = np.array(gr, dtype=np.uint8)
38+
gf = correct_gamma(gr, gr, 0.2)
39+
b1 = cv2.GaussianBlur(gf,(0,0), 1,1)
40+
b2 = cv2.GaussianBlur(gf,(0,0), 2,2)
41+
b2 = cv2.subtract(b1, b2)
42+
gr = cv2.convertScaleAbs(b2, alpha=127, beta=127)
43+
gr = doCeq(gr, 0.1, 10)
44+
#gr = cv2.normalize(gr,alpha = 0,beta = 255,norm_type = cv2.NORM_MINMAX)
45+
return gr
46+
47+
if __name__ == '__main__':
48+
import sys
49+
try:
50+
name = sys.argv[1]
51+
nout = sys.argv[2]
52+
except:
53+
print("Error, introduce los nombre de los ficheros de entrada y salida")
54+
sys.exit()
55+
56+
frames = []
57+
cap = cv2.VideoCapture(name)
58+
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
59+
fps = 16
60+
size = (int(cap.get( cv.CV_CAP_PROP_FRAME_WIDTH)),int(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)))
61+
nframes = int(cap.get(cv.CV_CAP_PROP_FRAME_COUNT))
62+
count = 1
63+
ret = True
64+
65+
while(ret):
66+
ret,frame = cap.read()
67+
if ret:
68+
out = process_image(frame)
69+
out = cv2.cvtColor(out, cv2.COLOR_GRAY2BGR)
70+
frames.append(out)
71+
porcentaje = 100*count/nframes
72+
print porcentaje, "% completed......................."
73+
count += 1
74+
writer = cv2.VideoWriter(nout, cv.CV_FOURCC('M','J','P','G'), fps, size)
75+
for frm in frames:
76+
writer.write(frm)
77+
cap.release()
78+

Latex/memoria.aux

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,63 @@
2020
\citation{oreilly}
2121
\@writefile{toc}{\contentsline {section}{\numberline {1.2}Ejemplos}{5}}
2222
\citation{canny86}
23-
\@writefile{toc}{\contentsline {chapter}{\numberline {2}Otras librer\IeC {\'\i }as usadas}{17}}
23+
\@writefile{toc}{\contentsline {chapter}{\numberline {2}Otras librer\IeC {\'\i }as usadas}{15}}
2424
\@writefile{lof}{\addvspace {10\p@ }}
2525
\@writefile{lot}{\addvspace {10\p@ }}
26-
\newlabel{cap.otras}{{2}{17}}
27-
\@writefile{toc}{\contentsline {section}{\numberline {2.1}Android}{17}}
28-
\@writefile{toc}{\contentsline {section}{\numberline {2.2}Numpy}{19}}
29-
\newlabel{sec.numpy}{{2.2}{19}}
26+
\newlabel{cap.otras}{{2}{15}}
27+
\@writefile{toc}{\contentsline {section}{\numberline {2.1}Android}{15}}
28+
\@writefile{toc}{\contentsline {section}{\numberline {2.2}Numpy}{17}}
29+
\newlabel{sec.numpy}{{2.2}{17}}
3030
\citation{shiandtomasi}
3131
\citation{LucasKanade}
3232
\citation{harris88}
33-
\@writefile{toc}{\contentsline {chapter}{\numberline {3}Estabilizaci\IeC {\'o}n de imagen}{21}}
33+
\@writefile{toc}{\contentsline {chapter}{\numberline {3}Estabilizaci\IeC {\'o}n de imagen}{19}}
3434
\@writefile{lof}{\addvspace {10\p@ }}
3535
\@writefile{lot}{\addvspace {10\p@ }}
36-
\newlabel{cap.estab}{{3}{21}}
37-
\@writefile{toc}{\contentsline {section}{\numberline {3.1}Algoritmo b\IeC {\'a}sico}{21}}
38-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.1}Algoritmo para encontrar puntos caracter\IeC {\'\i }sticos}{21}}
36+
\newlabel{cap.estab}{{3}{19}}
37+
\@writefile{toc}{\contentsline {section}{\numberline {3.1}Algoritmo b\IeC {\'a}sico}{19}}
38+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.1}Algoritmo para encontrar puntos caracter\IeC {\'\i }sticos}{19}}
3939
\citation{shiandtomasi}
4040
\citation{harris88}
4141
\citation{LucasKanade}
42-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.2}Algoritmo de Lucas-Kanade}{24}}
43-
\newlabel{optflow}{{3.5}{24}}
44-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.3}C\IeC {\'a}lculo de la homograf\IeC {\'\i }a}{28}}
45-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.4}C\IeC {\'o}digo}{29}}
46-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.5}Comentarios y variaciones del algoritmo}{31}}
42+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.2}Algoritmo de Lucas-Kanade}{22}}
43+
\newlabel{optflow}{{3.5}{22}}
44+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.3}C\IeC {\'a}lculo de la homograf\IeC {\'\i }a}{26}}
45+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.4}C\IeC {\'o}digo}{27}}
46+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1.5}Comentarios y variaciones del algoritmo}{29}}
4747
\citation{kug75}
48-
\@writefile{toc}{\contentsline {section}{\numberline {3.2}Algoritmo basado en la correlaci\IeC {\'o}n de fase}{32}}
49-
\@writefile{toc}{\contentsline {section}{\numberline {3.3}Uso del aceler\IeC {\'o}metro para estabilizar}{33}}
50-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.1}Programa para Android}{33}}
51-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.2}Programa de procesado de los datos}{34}}
48+
\@writefile{toc}{\contentsline {section}{\numberline {3.2}Algoritmo basado en la correlaci\IeC {\'o}n de fase}{30}}
49+
\@writefile{toc}{\contentsline {section}{\numberline {3.3}Uso del aceler\IeC {\'o}metro para estabilizar}{31}}
50+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.1}Programa para Android}{31}}
51+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.2}Programa de procesado de los datos}{32}}
5252
\citation{googlesensor}
53-
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.3}Resultados}{36}}
54-
\@writefile{toc}{\contentsline {chapter}{\numberline {4}Estabilizaci\IeC {\'o}n de la luz}{37}}
53+
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3.3}Resultados}{34}}
54+
\@writefile{toc}{\contentsline {chapter}{\numberline {4}Estabilizaci\IeC {\'o}n de la luz}{35}}
5555
\@writefile{lof}{\addvspace {10\p@ }}
5656
\@writefile{lot}{\addvspace {10\p@ }}
57-
\newlabel{cap.luz}{{4}{37}}
58-
\@writefile{toc}{\contentsline {section}{\numberline {4.1}Introducci\IeC {\'o}n}{37}}
57+
\newlabel{cap.luz}{{4}{35}}
58+
\@writefile{toc}{\contentsline {section}{\numberline {4.1}Introducci\IeC {\'o}n}{35}}
5959
\citation{illuFace}
60-
\@writefile{toc}{\contentsline {section}{\numberline {4.2}Un algoritmo de normalizaci\IeC {\'o}n de luz}{38}}
61-
\@writefile{toc}{\contentsline {section}{\numberline {4.3}Correcci\IeC {\'o}n de la iluminaci\IeC {\'o}n usando el sensor}{39}}
62-
\@writefile{toc}{\contentsline {chapter}{\numberline {A}C\IeC {\'o}digo del aceler\IeC {\'o}metro}{41}}
60+
\@writefile{toc}{\contentsline {section}{\numberline {4.2}Un algoritmo de normalizaci\IeC {\'o}n de luz}{36}}
61+
\@writefile{toc}{\contentsline {section}{\numberline {4.3}Correcci\IeC {\'o}n de la iluminaci\IeC {\'o}n usando el sensor}{37}}
62+
\@writefile{toc}{\contentsline {chapter}{\numberline {A}C\IeC {\'o}digo del aceler\IeC {\'o}metro}{39}}
6363
\@writefile{lof}{\addvspace {10\p@ }}
6464
\@writefile{lot}{\addvspace {10\p@ }}
65-
\@writefile{toc}{\contentsline {section}{\numberline {A.1}C\IeC {\'o}digo de Android}{41}}
66-
\newlabel{android_ap_acc}{{A.1}{41}}
67-
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.1}MainActivity}{41}}
68-
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.2}Clase vcorderView}{46}}
69-
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.3}Android manifest}{49}}
70-
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.4}Activity layout}{50}}
71-
\@writefile{toc}{\contentsline {section}{\numberline {A.2}C\IeC {\'o}digo de procesado de los datos}{51}}
72-
\newlabel{ap_acc}{{A.2}{51}}
73-
\@writefile{toc}{\contentsline {chapter}{\numberline {B}C\IeC {\'o}digo del sensor de luz}{55}}
65+
\@writefile{toc}{\contentsline {section}{\numberline {A.1}C\IeC {\'o}digo de Android}{39}}
66+
\newlabel{android_ap_acc}{{A.1}{39}}
67+
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.1}MainActivity}{39}}
68+
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.2}Clase vcorderView}{44}}
69+
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.3}Android manifest}{47}}
70+
\@writefile{toc}{\contentsline {subsection}{\numberline {A.1.4}Activity layout}{48}}
71+
\@writefile{toc}{\contentsline {section}{\numberline {A.2}C\IeC {\'o}digo de procesado de los datos}{49}}
72+
\newlabel{ap_acc}{{A.2}{49}}
73+
\@writefile{toc}{\contentsline {chapter}{\numberline {B}C\IeC {\'o}digo del sensor de luz}{53}}
7474
\@writefile{lof}{\addvspace {10\p@ }}
7575
\@writefile{lot}{\addvspace {10\p@ }}
76-
\@writefile{toc}{\contentsline {section}{\numberline {B.1}C\IeC {\'o}digo de Android}{55}}
77-
\newlabel{android_ap_illu}{{B.1}{55}}
78-
\@writefile{toc}{\contentsline {section}{\numberline {B.2}C\IeC {\'o}digo de procesado de los datos}{60}}
79-
\newlabel{ap_illu}{{B.2}{60}}
76+
\@writefile{toc}{\contentsline {section}{\numberline {B.1}C\IeC {\'o}digo de Android}{53}}
77+
\newlabel{android_ap_illu}{{B.1}{53}}
78+
\@writefile{toc}{\contentsline {section}{\numberline {B.2}C\IeC {\'o}digo de procesado de los datos}{58}}
79+
\newlabel{ap_illu}{{B.2}{58}}
8080
\bibstyle{plain}
8181
\bibdata{texto}
8282
\bibcite{androidref}{1}

0 commit comments

Comments
 (0)