Skip to content

Commit

Permalink
feat(#47): finish one-step API
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Sep 1, 2019
1 parent 24745ed commit 7bacd03
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
37 changes: 30 additions & 7 deletions stagesepx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,45 @@
from stagesepx.cutter import VideoCutter
from stagesepx.classifier import SVMClassifier
from stagesepx.reporter import Reporter
from stagesepx import toolbox


class TerminalCli(object):
""" this is a client for stagesepx, for easier usage. """
"""
this is a client for stagesepx, for easier usage.
for flexible usage, you 'd better use the script way.
"""

@toolbox.arg_printer
def one_step(self,
video_path: str,
output_path: str = None,
frame_count: int = 5,
compress_rate: float = 0.2,
limit: int = None):
"""
one step => cut, classifier, draw
:param video_path: your video path
:param output_path: output path (dir)
:param frame_count: default to 5, and finally you will get 5 frames for each range
:param compress_rate: before_pic * compress_rate = after_pic. default to 0.2
:param limit: ignore some ranges which are too short, 5 means ignore stable ranges which length < 5
:return:
"""

def one_step(self, video_path: str, output_path: str = None):
# --- cutter ---
cutter = VideoCutter()
res = cutter.cut(video_path)
stable, unstable = res.get_range()
res = cutter.cut(video_path, compress_rate=compress_rate)
stable, unstable = res.get_range(limit=limit)

data_home = res.pick_and_save(stable, 5, to_dir=output_path)
data_home = res.pick_and_save(
stable,
frame_count,
to_dir=output_path)

# --- classify ---

cl = SVMClassifier()
cl = SVMClassifier(compress_rate=compress_rate)
cl.load(data_home)
cl.train()
classify_result = cl.classify(video_path, stable)
Expand Down
11 changes: 11 additions & 0 deletions stagesepx/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import typing
import math
import numpy as np
from loguru import logger
from functools import wraps
from base64 import b64encode
from skimage.filters import threshold_otsu
from skimage.measure import compare_ssim as origin_compare_ssim
Expand Down Expand Up @@ -229,6 +231,15 @@ def np2b64str(frame: np.ndarray) -> str:
return b64encode(buffer).decode()


def arg_printer(func: typing.Callable):
@wraps(func)
def _wrapper(*args, **kwargs):
logger.debug(f'function {func.__name__} args: {args}, kwargs: {kwargs}')
return func(*args, **kwargs)

return _wrapper


if __name__ == '__main__':
t = cv2.imread('../1.png', cv2.IMREAD_GRAYSCALE)
t = sharpen_frame(t)
Expand Down

0 comments on commit 7bacd03

Please sign in to comment.