-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
89 lines (69 loc) · 2.67 KB
/
main.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
# Author: Selahaddin HONI | 001honi@github
# March, 2021
# ============================================================================================
from video import Video
from block_matching import BlockMatching
from tqdm import tqdm
import numpy as np
import cv2
import tqdm
import time
# Block Matching Parameters
# ============================================================================================
dfd=1 ; blockSize=(16,16) ; searchMethod=0 ; searchRange=15 ; predict_from_prev = False ; N=5
bm = BlockMatching(dfd=dfd,
blockSize=blockSize,
searchMethod=searchMethod,
searchRange=searchRange,
motionIntensity=False)
# Title and Parameters Info
dfd = "MSE" if dfd else "MAD"
method = "Exhaustive" if not searchMethod else "ThreeStep"
text = ["Block Matching Algorithm","DFD: {} | {} | {} Search Range: {}".format(
dfd,blockSize,method,searchRange)]
print(text)
# Import Video Sequence
# ============================================================================================
gray = True
predict = "prev" if predict_from_prev else "orig"
path_inp = "videos/foreman-orig.avi"
path_out = "videos/{}-Size{}-{}-{}-{}.mp4".format(dfd,blockSize[0],method,searchRange,predict)
video = Video(path_inp)
video.read_frames(gray=gray)
(H,W) = video.shape
# Demo
# ============================================================================================
a = 72 ; t = 78
start_time = time.time()
anchor = video.frames_inp[a]
target = video.frames_inp[t]
bm.step(anchor,target)
anchorP = bm.anchorP
motionField = bm.motionField
out = video.visualize(anchor,target,motionField,anchorP,text,a,t)
elapsed_time = time.time() - start_time
print(f"Elapsed time: {elapsed_time:.3f} secs")
cv2.imshow("Demo",out)
cv2.waitKey(0)
cv2.imwrite("demo.png",out)
# Video Process
# ============================================================================================
# start_time = time.time()
# prev_prediction = None
# for f in tqdm.tqdm(range(video.total_frame-1)):
# if predict_from_prev:
# anchor = video.frames_inp[f] if f%N == 0 else prev_prediction
# else:
# anchor = video.frames_inp[f]
# target = video.frames_inp[f+1]
# bm.step(anchor,target)
# anchorP = bm.anchorP
# motionField = bm.motionField
# out = video.visualize(anchor,target,motionField,anchorP,text,f,f+1)
# video.frames_out.append(out)
# if predict_from_prev:
# prev_prediction = anchorP
# elapsed_time = time.time() - start_time
# print(f"Elapsed time: {elapsed_time:.3f} secs")
# video.write(path_out,fps=30)
# print(path_out)