Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(preprocessor): add frame selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmyshin committed Sep 25, 2019
1 parent b59e699 commit 80364c0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions gnes/preprocessor/video/shotdetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import numpy as np
import math
from typing import List

from gnes.preprocessor.base import BaseVideoPreprocessor
Expand Down Expand Up @@ -99,12 +100,13 @@ def apply(self, doc: 'gnes_pb2.Document') -> None:
shot_len = len(frames)
c.weight = shot_len / num_frames
if self.sframes > 0 and shot_len > self.sframes:
begin = 0
if self.sframes < 3:
begin = (shot_len - self.sframes) // 2
step = (shot_len) // self.sframes
frames = [frames[_] for _ in range(begin, shot_len, step)]

if shot_len >= 2 * self.sframes:
step = math.ceil(shot_len / self.sframes)
frames = frames[::step]
else:
idx = np.sort(np.random.choice(shot_len, self.sframes, replace=False))
frames = [frames[idx_] for idx_ in idx]

chunk_data = np.array(frames)
c.blob.CopyFrom(array2blob(chunk_data))
else:
Expand Down

0 comments on commit 80364c0

Please sign in to comment.