Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 2018-Python-Practice-master/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
'''
1. import `Video` and `save_video` from the correct module of package "styler"
'''
from ... import Video
from ... import save_video
from styler.video import Video
from styler.utils import save_video


model_file = 'data/vg-30.pb'
Expand Down Expand Up @@ -41,7 +41,7 @@ def main():
'''
2. set the `path` to your input
'''
with Video(...) as v:
with Video("./input/jaguar.mp4") as v:
frames = v.read_frames(image_h=shape[1], image_w=shape[2])

logging.info("Processing image")
Expand All @@ -53,15 +53,15 @@ def main():
'''
processed = [
session.run(out, feed_dict={image: [frame]})
...
for frame in frames
]

'''
4. Pass the results as a argument into function
'''
save_video('result.mp4',
fps=30, h=shape[1], w=shape[2],
frames=...)
frames=processed)

logging.info("Processing took %f" % (
(datetime.now() - start_time).total_seconds()))
Expand Down
Binary file added 2018-Python-Practice-master/result.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 7 additions & 2 deletions 2018-Python-Practice-master/styler/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ def read_frames(self, image_h, image_w):
- Return your results
'''
frames = []
while(self.cap.isOpened):
ret, frame = self.cap.read()
if ret == False:
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(建議) Line32 也可以寫成 if not ret: ,因為通常較少用 == 來比較物件跟 True/False boolean

frames.append(cv2.resize(frame, (512, 512)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line34 這邊希望使用的是 utils.py 裡的 resize()哦。可以看下 utils.py 的版本有對這份應用做一些特殊處理(擷取中心位置之後才 resize)所以跟直接 cv2.resize 結果可能有些出入

# 5-1 /5-2 Read video and collect them

self.frames = ... # 5-3 let object have the result
return ... # return your results
self.frames = frames # 5-3 let object have the result
return frames # return your results

def __exit__(self, exc_type, exc_val, exc_tb):
self.cap.release()