-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
Copy pathdemo.py
38 lines (31 loc) · 1.21 KB
/
demo.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
from argparse import ArgumentParser
import cv2
from algorithms.dense_optical_flow import dense_optical_flow
from algorithms.lucas_kanade import lucas_kanade_method
def main():
parser = ArgumentParser()
parser.add_argument(
"--algorithm",
choices=["farneback", "lucaskanade", "lucaskanade_dense", "rlof"],
required=True,
help="Optical flow algorithm to use",
)
parser.add_argument(
"--video_path", default="videos/cat.mp4", help="Path to the video",
)
args = parser.parse_args()
video_path = args.video_path
if args.algorithm == "lucaskanade":
lucas_kanade_method(video_path)
elif args.algorithm == "lucaskanade_dense":
method = cv2.optflow.calcOpticalFlowSparseToDense
dense_optical_flow(method, video_path, to_gray=True)
elif args.algorithm == "farneback":
method = cv2.calcOpticalFlowFarneback
params = [0.5, 3, 15, 3, 5, 1.2, 0] # Farneback's algorithm parameters
dense_optical_flow(method, video_path, params, to_gray=True)
elif args.algorithm == "rlof":
method = cv2.optflow.calcOpticalFlowDenseRLOF
dense_optical_flow(method, video_path)
if __name__ == "__main__":
main()