forked from benetech/VideoDeduplication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_matching.py
40 lines (29 loc) · 1.36 KB
/
template_matching.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
import os
os.environ['WINNOW_CONFIG'] = os.path.abspath('../config.yaml')
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial.distance import cdist
from glob import glob
from winnow.feature_extraction.extraction_routine import load_featurizer
from winnow.feature_extraction.utils import load_image,load_video,download_file
from winnow.search_engine.template_matching import SearchEngine,download_sample_templates
from winnow.annotation.tools import Annotator
import requests
import shutil
import yaml
with open("config.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
TEMPLATES_SOURCE = cfg['templates_source_path']
SEARCH_SPACE = os.path.join(cfg['destination_folder'],cfg['root_folder_intermediate'],'frame_level')
TEMPLATE_TEST_OUTPUT = os.path.join(cfg['destination_folder'],'template_test.csv')
DISTANCE = 0.07
print('Loading model...')
model = load_featurizer()
print('Initiating search engine using templates from:{} and loooking at videos located in:{}'.format(TEMPLATES_SOURCE,
SEARCH_SPACE))
se = SearchEngine(TEMPLATES_SOURCE,
SEARCH_SPACE,
model)
print('Running all potential queries and returning results that yield a distance lower than {}'.format(DISTANCE))
se.create_annotation_report(threshold=DISTANCE,fp = TEMPLATE_TEST_OUTPUT)
print('Report saved to {}'.format(TEMPLATE_TEST_OUTPUT))