Skip to content

Commit

Permalink
update index
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxlu committed Dec 7, 2018
1 parent a16970e commit 5f806d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.idea/
XCloud/__pycache__/
cv/__pycache__/
cv/static/FaceUpload/
dm/__pycache__/
nlp/__pycache__/
4 changes: 2 additions & 2 deletions cv/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def Geo_from_cv(img):
result[k] = {"bbox": [d.left(), d.top(), d.right(), d.bottom()],
"landmarks": [[shape.part(i).x, shape.part(i).y] for i in range(68)]}

xs = np.array([_[0] for _ in result['landmarks']])
ys = np.array([_[1] for _ in result['landmarks']])
xs = np.array([_[0] for _ in result[0]['landmarks']])
ys = np.array([_[1] for _ in result[0]['landmarks']])

return list(xs - np.mean(xs)) + list(ys - np.mean(ys))
4 changes: 2 additions & 2 deletions cv/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h2>Services</h2>
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-cloud fa-stack-1x text-primary"></i>
<i class="fa fa-eye fa-stack-1x text-primary"></i>
</span>
<h4>
<strong>Computer Vision</strong>
Expand All @@ -98,7 +98,7 @@ <h4>
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-eye fa-stack-1x text-primary"></i>
<i class="fa fa-cloud fa-stack-1x text-primary"></i>
</span>
<h4>
<strong>Data Mining</strong>
Expand Down
30 changes: 20 additions & 10 deletions cv/train_and_test_fbp_with_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,34 @@ def prepare_data():
for i in range(len(files)):
img = cv2.imread(os.path.join(SCUT5500_DIR, files[i]))
mtcnn_result = detector.detect_faces(img)
bbox = mtcnn_result['box']

if bbox is not None:
face_region = img[bbox[0] - int(bbox[2] / 2): bbox[0] + int(bbox[2] / 2),
bbox[1] - int(bbox[3] / 2): bbox[1] + int(bbox[3] / 2)]
ratio = max(face_region[0], face_region[1]) / min(face_region[0], face_region[1])
if face_region[0] > face_region[1]:
face_region = cv2.resize(face_region, (int((face_region[0] / ratio) * 64 / face_region[1]), 64))

if len(mtcnn_result) > 0:
bbox = mtcnn_result[0]['box']
print(bbox)

margin_pixel = 10
face_region = img[bbox[0] - margin_pixel: bbox[0] + bbox[2] + margin_pixel,
bbox[1] - margin_pixel: bbox[1] + bbox[3] + margin_pixel]

# cv2.imshow('face', face_region)
# cv2.waitKey()
# cv2.destroyAllWindows()

ratio = max(face_region.shape[0], face_region.shape[1]) / min(face_region.shape[0], face_region.shape[1])
if face_region.shape[0] > face_region.shape[1]:
face_region = cv2.resize(face_region,
(int((face_region.shape[0] / ratio) * 64 / face_region.shape[1]), 64))
else:
face_region = cv2.resize(face_region, (64, int((face_region[1] / ratio) * 64 / face_region[0])))
face_region = cv2.resize(face_region,
(64, int((face_region.shape[1] / ratio) * 64 / face_region.shape[0])))
else:
face_region = cv2.resize(img, (64, 64))

lbp = LBP_from_cv(face_region)
hog = HOG_from_cv(face_region)
ldmk = Geo_from_cv(img)

feature = lbp + hog + ldmk
feature = lbp
features.append(feature)
lbs.append(scores[i])

Expand Down

0 comments on commit 5f806d4

Please sign in to comment.