-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example.py
34 lines (25 loc) · 1022 Bytes
/
Example.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
import cv2
import moviepy.editor as mpy
from Dehaze_module import remove_haze
cap = cv2.VideoCapture("file.mp4")
frame_fps = int(cap.get(cv2.CAP_PROP_FPS))
# specify a writer to write a processed video to a disk frame by frame
video_row=[]
while True:
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
break
# some video processing here
new = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
gray, haze_map = remove_haze(new, showHazeTransmissionMap=False)
# write a processed frame to the list
video_row.append(gray)
## Close video file
cap.release()
# create moviepy object from list with numpy frames and save it to a disk
clip = mpy.ImageSequenceClip(video_row, fps=25)
clip.write_videofile("new.mp4")
# when video is fully saved to disk, open it as BytesIO and play with st.video()
# result_video = open(temp_file_result, "rb")
result_video = open(new.mp4, "rb")