Spaces:
Runtime error
Runtime error
Samuel Schmidt
commited on
Commit
·
cffc8b0
1
Parent(s):
153b1b2
Removed cv2 from lbp
Browse files- src/LBP.py +23 -53
src/LBP.py
CHANGED
@@ -1,55 +1,25 @@
|
|
1 |
-
import cv2
|
2 |
from skimage import feature
|
3 |
-
import matplotlib.pyplot as plt
|
4 |
import numpy as np
|
5 |
-
|
6 |
-
|
7 |
-
class
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
minNeighbors=5,
|
29 |
-
minSize=(24, 24))
|
30 |
-
return rects
|
31 |
-
|
32 |
-
def preprocess_img(self, image):
|
33 |
-
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
34 |
-
rects = self.face_detection(img)
|
35 |
-
feature_vector = np.zeros((self.numPoints + 2) * 3)
|
36 |
-
|
37 |
-
for (x, y, w, h) in rects:
|
38 |
-
face = img[y:y + h, x:x + w]
|
39 |
-
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
|
40 |
-
|
41 |
-
lbp = self.describe(face)
|
42 |
-
feature_vector[(self.numPoints + 2) * 0: (self.numPoints + 2) * 1] += lbp
|
43 |
-
|
44 |
-
# Process green channel
|
45 |
-
lbp = self.describe(face[:, :, 1])
|
46 |
-
feature_vector[(self.numPoints + 2) * 1: (self.numPoints + 2) * 2] += lbp
|
47 |
-
|
48 |
-
# Process blue channel
|
49 |
-
lbp = self.describe(face[:, :, 2])
|
50 |
-
feature_vector[(self.numPoints + 2) * 2: (self.numPoints + 2) * 3] += lbp
|
51 |
-
|
52 |
-
feature_vector /= len(rects)
|
53 |
-
|
54 |
-
return feature_vector
|
55 |
-
|
|
|
|
|
1 |
from skimage import feature
|
|
|
2 |
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
class LocalBinaryPatterns:
|
6 |
+
def __init__(self, numPoints, radius):
|
7 |
+
# store the number of points and radius
|
8 |
+
self.numPoints = numPoints
|
9 |
+
self.radius = radius
|
10 |
+
|
11 |
+
def describe(self, image, eps=1e-7):
|
12 |
+
# compute the Local Binary Pattern representation
|
13 |
+
# of the image, and then use the LBP representation
|
14 |
+
# to build the histogram of patterns
|
15 |
+
gray_img = imgage.convert('L')
|
16 |
+
lbp = feature.local_binary_pattern(image, self.numPoints,
|
17 |
+
self.radius, method="uniform")
|
18 |
+
(hist, _) = np.histogram(lbp.ravel(),
|
19 |
+
bins=np.arange(0, self.numPoints + 3),
|
20 |
+
range=(0, self.numPoints + 2))
|
21 |
+
# normalize the histogram
|
22 |
+
hist = hist.astype("float")
|
23 |
+
hist /= (hist.sum() + eps)
|
24 |
+
# return the histogram of Local Binary Patterns
|
25 |
+
return hist
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|