Skip to content

Commit 589b6f3

Browse files
committed
add CMakeLists.txt for building SeetaFace Alignment on linux and update README.
1 parent 8b17fc2 commit 589b6f3

File tree

8 files changed

+76
-16
lines changed

8 files changed

+76
-16
lines changed

FaceAlignment/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 2.8.4)
2+
3+
project(seeta_fa_lib)
4+
5+
# Build options
6+
option(BUILD_EXAMPLES "Set to ON to build examples" ON)
7+
8+
# Use C++11
9+
#set(CMAKE_CXX_STANDARD 11)
10+
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
12+
message(STATUS "C++11 support has been enabled by default.")
13+
14+
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
16+
17+
include_directories(include)
18+
19+
set(src_files
20+
src/cfan.cpp
21+
src/face_alignment.cpp
22+
src/sift.cpp
23+
)
24+
25+
add_library(seeta_fa_lib SHARED ${src_files})
26+
set(fa_required_libs seeta_fa_lib)
27+
28+
if (BUILD_EXAMPLES)
29+
message(STATUS "Build with examples.")
30+
find_package(OpenCV)
31+
if (NOT OpenCV_FOUND)
32+
message(WARNING "OpenCV not found. Test will not be built.")
33+
else()
34+
include_directories(${OpenCV_INCLUDE_DIRS} build)
35+
link_directories(build)
36+
list(APPEND fa_required_libs ${OpenCV_LIBS} seeta_facedet_lib)
37+
add_executable(fa_test src/test/face_alignment_test.cpp)
38+
target_link_libraries(fa_test ${fa_required_libs})
39+
endif()
40+
endif()

FaceAlignment/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ As for speed, it takes about 5 milliseconds per face to predict the 5 facial poi
3333
5. Define `SEETA_EXPORTS` macro: (Project) Properities -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.
3434
6. Build.
3535

36+
### Build in Linux
37+
38+
```
39+
mkdir build
40+
```
41+
copy the "face detection lib" and "face_detection.h" to the directory "build" for building the test example.
42+
43+
```
44+
cd build
45+
cmake ..
46+
make
47+
```
48+
49+
If everything goes fine, move on to test the program. Note: you should copy the face detetion model [seeta_fd_frontal_v1.0.bin](../FaceDetection/model/seeta_fd_frontal_v1.0.bin) to the directory "build" before testing.
50+
51+
```
52+
./fa_test
53+
```
54+
3655
### How to run SeetaFace Alignment
3756

3857
This version is developed to detect five facial landmarks, i.e., two eyes' centers, nose tip and two mouth corners.

FaceAlignment/data/image_0001.png

500 KB
Loading

FaceAlignment/include/cfan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131

3232
#pragma once
33-
#include "math.h"
33+
#include <cmath>
3434
#include "sift.h"
3535
#include "common.h"
3636

FaceAlignment/include/face_alignment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#ifndef SEETA_FACE_ALIGNMENT_H_
3333
#define SEETA_FACE_ALIGNMENT_H_
3434

35+
#include <cstdlib>
3536
#include "common.h"
3637
class CCFAN;
3738

FaceAlignment/src/cfan.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232

3333
#include "cfan.h"
34-
35-
using namespace std;
34+
#include <string.h>
3635

3736
/** A constructor.
3837
* Initialize basic parameters.
@@ -168,10 +167,10 @@ void CCFAN::FacialPointLocate(const unsigned char *gray_im, int im_width, int im
168167
float extend_revised_y = 0.05;
169168

170169
/*Compute the extended region of the detected face*/
171-
int extend_lx = max(floor(left_x - extend_factor*bbox_w), 0);
172-
int extend_rx = min(floor(right_x + extend_factor*bbox_w), im_width - 1);
173-
int extend_ly = max(floor(left_y - (extend_factor - extend_revised_y)*bbox_h), 0);
174-
int extend_ry = min(floor(right_y + (extend_factor + extend_revised_y)*bbox_h), im_height - 1);
170+
int extend_lx = std::max(floor(left_x - extend_factor*bbox_w), double(0));
171+
int extend_rx = std::min(floor(right_x + extend_factor*bbox_w), double(im_width - 1));
172+
int extend_ly = std::max(floor(left_y - (extend_factor - extend_revised_y)*bbox_h), double(0));
173+
int extend_ry = std::min(floor(right_y + (extend_factor + extend_revised_y)*bbox_h), double(im_height - 1));
175174

176175
int face_w = extend_rx - extend_lx + 1;
177176
int face_h = extend_ry - extend_ly + 1;
@@ -206,7 +205,7 @@ void CCFAN::FacialPointLocate(const unsigned char *gray_im, int im_width, int im
206205
{
207206
for (int j = 0; j < pts_num_; j++)
208207
{
209-
if (_isnan(fea[j * 128 + i]))
208+
if (isnan(fea[j * 128 + i]))
210209
{
211210
re_fea[i*pts_num_ + j] = 0;
212211
}
@@ -282,7 +281,7 @@ void CCFAN::FacialPointLocate(const unsigned char *gray_im, int im_width, int im
282281
{
283282
for (int j = 0; j < pts_num_; j++)
284283
{
285-
if (_isnan(fea[j * 128 + i]))
284+
if (isnan(fea[j * 128 + i]))
286285
{
287286
re_fea[i*pts_num_ + j] = 0;
288287
}
@@ -394,10 +393,10 @@ void CCFAN::GetSubImg(const unsigned char *gray_im, int im_width, int im_height,
394393
memset(sub_img, 128, patch_size*patch_size);
395394
int center_x = floor(point_x + 0.5);
396395
int center_y = floor(point_y + 0.5);
397-
int patch_left = max((center_x + 1) - patch_size / 2, 0);
398-
int patch_right = min((center_x + 1) + patch_size / 2 - 1, im_width - 1);
399-
int patch_top = max((center_y + 1) - patch_size / 2, 0);
400-
int patch_bottom = min((center_y + 1) + patch_size / 2 - 1, im_height - 1);
396+
int patch_left = std::max((center_x + 1) - patch_size / 2, 0);
397+
int patch_right = std::min((center_x + 1) + patch_size / 2 - 1, im_width - 1);
398+
int patch_top = std::max((center_y + 1) - patch_size / 2, 0);
399+
int patch_bottom = std::min((center_y + 1) + patch_size / 2 - 1, im_height - 1);
401400

402401
int lx = abs(patch_left - ((center_x + 1) - patch_size / 2));
403402
int rx = patch_size - abs(patch_right - ((center_x + 1) + patch_size / 2 - 1)) - 1;

FaceAlignment/src/sift.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232

3333
#include "sift.h"
34+
#include <string.h>
3435

3536
#define pi 3.1415926
3637
double SIFT::delta_gauss_x[25] =

FaceAlignment/src/test/face_alignment_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ int main(int argc, char** argv)
5050
detector.SetWindowStep(4, 4);
5151

5252
// Initialize face alignment model
53-
seeta::FaceAlignment point_detector("seeta_fa_v1.1.bin");
53+
seeta::FaceAlignment point_detector("../model/seeta_fa_v1.1.bin");
5454

5555
//load image
5656
IplImage *img_grayscale = NULL;
57-
img_grayscale = cvLoadImage("image_0001.png", 0);
57+
img_grayscale = cvLoadImage("../data/image_0001.png", 0);
5858
if (img_grayscale == NULL)
5959
{
6060
return 0;
6161
}
6262

63-
IplImage *img_color = cvLoadImage("image_0001.png", 1);
63+
IplImage *img_color = cvLoadImage("../data/image_0001.png", 1);
6464
int pts_num = 5;
6565
int im_width = img_grayscale->width;
6666
int im_height = img_grayscale->height;

0 commit comments

Comments
 (0)