Skip to content
Open
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion lipnet/lipreading/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from scipy import ndimage
from scipy.misc import imresize
import skvideo.io
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.

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

Copy link
Copy Markdown
Author

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

import dlib
from lipnet.lipreading.aligns import Align

Expand Down Expand Up @@ -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):

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.

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 from_video method. Something like this: from_video(self, path, use_open_cv=False). Please keep Sk-video to be the default method.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done!

videogen = skvideo.io.vreader(path)
#print("aaaa")

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.

Please delete this line

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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):

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.

Rename the method to signify the use of opencv

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:
Expand Down