-
Notifications
You must be signed in to change notification settings - Fork 243
Speeding up video frames loading #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from scipy import ndimage | ||
| from scipy.misc import imresize | ||
| import skvideo.io | ||
| import cv2 | ||
| import dlib | ||
| from lipnet.lipreading.aligns import Align | ||
|
|
||
|
|
@@ -191,11 +192,30 @@ def get_frames_mouth(self, detector, predictor, frames): | |
| mouth_frames.append(mouth_crop_image) | ||
| return mouth_frames | ||
|
|
||
| def get_video_frames(self, path): | ||
| def get_video_frames_skvideo(self, path): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change the current method of video loading as it has been proven to be reliable and doesn't require an additional installation of OpenCV, which is sometimes problematic (not to mention that the program itself sometimes doesn't work as expected). Instead, provide an additional argument for the user in the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| videogen = skvideo.io.vreader(path) | ||
| #print("aaaa") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please delete this line
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| frames = np.array([frame for frame in videogen]) | ||
| return frames | ||
|
|
||
|
|
||
| def get_video_frames(self, path): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename the method to signify the use of opencv
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| reader = cv2.VideoCapture(path) | ||
|
|
||
| frames = [] | ||
| while True: | ||
| ret, frame = reader.read() | ||
|
|
||
| if not ret: | ||
| break | ||
| else: | ||
| frames.append(frame[...,::-1]) | ||
|
|
||
| return np.array(frames) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| def set_data(self, frames): | ||
| data_frames = [] | ||
| for frame in frames: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle cv2 import failure (when users don't have OpenCV) as we want to give options to users to opt-out from using the feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to import cv2 later in the code