-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathtest_hook.py
79 lines (67 loc) · 2.08 KB
/
test_hook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from stagesepx.cutter import VideoCutter
from stagesepx.classifier import SVMClassifier
from stagesepx.reporter import Reporter
from stagesepx.hook import (
ExampleHook,
IgnoreHook,
CropHook,
FrameSaveHook,
RefineHook,
InterestPointHook,
TemplateCompareHook,
InvalidFrameDetectHook,
_AreaBaseHook,
)
import os
PROJECT_PATH = os.path.dirname(os.path.dirname(__file__))
VIDEO_PATH = os.path.join(PROJECT_PATH, "demo.mp4")
IMAGE_NAME = "demo.jpg"
IMAGE_PATH = os.path.join(PROJECT_PATH, IMAGE_NAME)
assert os.path.isfile(IMAGE_PATH)
def test_others():
assert _AreaBaseHook.convert(200, 200, 100, 100) == (100, 100)
try:
InvalidFrameDetectHook()
except DeprecationWarning:
pass
def test_hook():
# init hook
hook = ExampleHook()
hook1 = ExampleHook()
hook2 = IgnoreHook(size=(0.5, 0.5))
frame_home = os.path.join(PROJECT_PATH, "frame_save_dir")
hook3 = FrameSaveHook(frame_home)
hook4 = CropHook(size=(0.5, 0.5), offset=(0.0, 0.5))
hook5 = RefineHook()
hook6 = InterestPointHook()
hook7 = TemplateCompareHook({"amazon": IMAGE_PATH})
# --- cutter ---
cutter = VideoCutter(compress_rate=0.9)
# add hook
cutter.add_hook(hook)
cutter.add_hook(hook1)
cutter.add_hook(hook2)
cutter.add_hook(hook3)
cutter.add_hook(hook4)
cutter.add_hook(hook5)
cutter.add_hook(hook6)
cutter.add_hook(hook7)
res = cutter.cut(VIDEO_PATH)
stable, unstable = res.get_range()
assert len(stable) == 2, "count of stable range is not correct"
data_home = res.pick_and_save(stable, 5)
assert os.path.isdir(data_home), "result dir not existed"
# --- classify ---
cl = SVMClassifier()
cl.load(data_home)
cl.train()
classify_result = cl.classify(VIDEO_PATH, stable)
# --- draw ---
r = Reporter()
report_path = os.path.join(data_home, "report.html")
r.draw(classify_result, report_path=report_path, cut_result=res)
assert os.path.isfile(report_path)
# hook check
assert os.path.isdir(frame_home)
assert hook6.result
assert hook7.result