-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvrd.py
85 lines (62 loc) · 2.78 KB
/
vrd.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
80
81
82
83
from lib import VRDConfig, VRDUtil, ThGenerator, ThMatcher, CCGenerator, ORBGenerator, MultiLevelMatcher
import json, sys, os, argparse
# python -u vrd.py --input assets/video-reference-library/Zakatinspired.mp4 --working-dir VRD
parser = argparse.ArgumentParser()
parser.add_argument("--command", help="The command you would like to run. Options are: thGen, thMatch, ccGen, ccMatch, orbGen, ssmGen, ssmMatch, genAllRefVideos")
parser.add_argument("--input", help="Path to the input video file, which is required for most commands.")
parser.add_argument("--working-dir", help="Path to VRD working/root directory. Defaults to current directory.")
args = parser.parse_args()
cmd = args.command
queryVideo = args.input
path, fileName = os.path.split(queryVideo)
config = VRDConfig.VRDConfig()
if args.working_dir == None:
config.workingDir = "."
else:
config.workingDir = args.working_dir
if cmd == None:
MultiLevelMatcher.MultiLevelMatcher(config).run(queryVideo)
if cmd == "fpAll":
qFrames, ccFrames = ThGenerator.ThGenerator(config).run(queryVideo)
ThMatcher.ThMatcher(config).run(qFrames)
#CCGenerator.CCGenerator.run(ccFrames)
#CCMatcher.CCMatcher().run()
if cmd == "ccGen":
CCGenerator.CCGenerator(config).run(queryVideo)
if cmd == "ccMatch":
ccMatcher = CCMatcher.CCMatcher(config)
if cmd == "thGen":
ThGenerator.ThGenerator(config).run(queryVideo)
if cmd == "thMatch":
vu = VRDUtil.VRDUtil(config)
thMatcher = ThMatcher.ThMatcher(config)
videos = vu.getReferenceVideosList()
processedVideos = 0
qvPath, qvFilename = os.path.split(queryVideo)
qVideo = vu.readFramesFromDrive("assets/fingerprints/"+qvFilename+"/Th")
for video in videos:
rvPath, rvFilename = os.path.split(video)
rVideo = vu.readFramesFromDrive("assets/fingerprints/"+rvFilename+"/Th")
significantFrameMatches = thMatcher.thMatchVideos(qVideo, rVideo)
if len(significantFrameMatches) > 0:
out = {
"qVideo": queryVideo,
"rVideo": video,
"matches": significantFrameMatches
}
jsonMatches = json.dumps(out)
print("output:"+jsonMatches+"\n")
processedVideos += 1
print("Processed videos:"+str(processedVideos))
if cmd == "genAllRefVideos":
refLibPath = "assets/video-reference-library"
files = [f for f in listdir(refLibPath) if isfile(join(refLibPath, f))]
thGen = ThGenerator(config)
for file in files:
#Check if already exists
if os.path.exists("assets/fingerprints/"+file):
print("Skippping existing: "+file)
else:
size = os.path.getsize(refLibPath+"/"+file)
print("Processing: "+file+" ("+str(round(size/1024/1024))+"MB)")
thGen.run(refLibPath+"/"+file)