-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
HornSchunck.py
executable file
·56 lines (41 loc) · 1.6 KB
/
HornSchunck.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
#!/usr/bin/env python
"""
python HornSchunck.py data/box box.*
python HornSchunck.py data/office office.*
python HornSchunck.py data/rubic rubic.*
python HornSchunck.py data/sphere sphere.*
"""
# from scipy.ndimage.filters import gaussian_filter
import imageio
from pathlib import Path
from matplotlib.pyplot import show
from argparse import ArgumentParser
from pyoptflow import HornSchunck, getimgfiles
from pyoptflow.plots import compareGraphs
FILTER = 7
def main():
p = ArgumentParser(description="Pure Python Horn Schunck Optical Flow")
p.add_argument("stem", help="path/stem of files to analyze")
p.add_argument("pat", help="glob pattern of files", default="*.bmp")
p.add_argument("-p", "--plot", help="show plots", action="store_true")
p.add_argument(
"-a", "--alpha", help="regularization parameter", type=float, default=0.001
)
p.add_argument("-N", help="number of iterations", type=int, default=8)
p = p.parse_args()
U, V = horn_schunck(p.stem, p.pat, alpha=p.alpha, Niter=p.N, verbose=p.plot)
show()
def horn_schunck(stem: Path, pat: str, alpha: float, Niter: int, verbose: bool):
flist = getimgfiles(stem, pat)
for i in range(len(flist) - 1):
fn1 = flist[i]
im1 = imageio.imread(fn1, as_gray=True)
# Iold = gaussian_filter(Iold,FILTER)
fn2 = flist[i + 1]
im2 = imageio.imread(fn2, as_gray=True)
# Inew = gaussian_filter(Inew,FILTER)
U, V = HornSchunck(im1, im2, alpha=1.0, Niter=100)
compareGraphs(U, V, im2, fn=fn2.name)
return U, V
if __name__ == "__main__":
main()