-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lbp.py
77 lines (57 loc) · 2.12 KB
/
test_lbp.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
#!/usr/bin/env python3
#
# Test C bindings for LBP texture extraction.
#
import argparse
import numpy as np
import os
import sys
import time
from common import *
def PrintElapsedTime(mesg, elapsed):
suffix = "s"
if elapsed < 0.001:
elapsed *= 1000
suffix = "ms"
print("{}{}{}".format(mesg, elapsed, suffix))
def OpenGrayImage(path):
image = cv2.imread(path)
image = cv2.resize(image, (SIZE, SIZE))
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
if __name__ == "__main__":
prs = argparse.ArgumentParser()
prs.add_argument("-i", "--input", type=str, required=True, help="Image/directory path")
prs.add_argument("-l", "--limit", type=int, help="Limit the number of images to test")
args = prs.parse_args()
lib = InitLBPLib()
if lib is not None:
if os.path.isfile(args.input):
image = OpenGrayImage(args.input)
start = time.time()
A = ExtractLBP_slow(image, SIZE, SIZE)
end = time.time()
PrintElapsedTime("Python LBP extraction: ", end - start)
start = time.time()
B = ExtractLBP(lib, image, SIZE, SIZE)
end = time.time()
PrintElapsedTime("C LBP extraction: ", end - start)
# print(A)
# print('\n');
# print(B)
else:
elapsed = [0, 0]
filenames = os.listdir(args.input)
maxImages = args.limit
if maxImages is None or maxImages > len(filenames):
maxImages = len(filenames)
for i in range(0, maxImages):
imagePath = os.path.join(args.input, filenames[i])
image = OpenGrayImage(imagePath)
start = time.time()
A = ExtractLBP_slow(image, SIZE, SIZE)
elapsed[0] += time.time() - start
start = time.time()
B = ExtractLBP(lib, image, SIZE, SIZE)
elapsed[1] += time.time() - start
PrintElapsedTime("Python LBP extration (total): ", elapsed[0])
PrintElapsedTime("C LBP extration (total): ", elapsed[1])