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
20 changes: 12 additions & 8 deletions 2018-Python-Practice-master/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
import sys
from datetime import datetime

import cv2

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

這邊不需要 import cv2哦

import tensorflow as tf

'''
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 @@ -52,21 +52,25 @@ def main():
and make it be processed by Tensorflow.
'''
processed = [
session.run(out, feed_dict={image: [frame]})
...
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()))
logging.info("Done")


if __name__ == '__main__':
main()
Binary file added 2018-Python-Practice-master/result.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion 2018-Python-Practice-master/styler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def save_video(filepath, fps, w, h, frames):
'''
If you cannot write video file, you may change the used codec
'''
used_codec = codecs[2] # change the index from codecs
used_codec = codecs[3] # change the index from codecs
fourcc = cv2.VideoWriter_fourcc(*used_codec)
out = cv2.VideoWriter(filepath, fourcc, fps, (w, h))
for frame in frames:
Expand Down
29 changes: 25 additions & 4 deletions 2018-Python-Practice-master/styler/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,32 @@ def read_frames(self, image_h, image_w):
- Also assign frames to "self" object
- Return your results
'''
frames = []
# 5-1 /5-2 Read video and collect them

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


# Read until video is completed
while(self.cap.isOpened()):

@gabyvon725 gabyvon725 Mar 15, 2018

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

(建議) Line33 可以省略括號

ret, frame = self.cap.read()
if ret == True:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Line 35 可以寫成 if ret:,因為通常較少用 == 來比較物件跟 True/False boolean

frame_r=resize(frame,image_h,image_w)
cv2.imshow('Frame',frame)
self.frames.append(frame_r)
if cv2.waitKey(25) & 0xFF == ord('q'):
break

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Line 39 40 這邊可以不寫哦。 因為目的就是要讓它處理完,不存在中途需要quit的問題。

else :
break

# Press Q on keyboard to exit


# When everything done, release the video capture object

# Closes all the frames
cv2.destroyAllWindows()


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

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