Skip to content

Commit 49b1c99

Browse files
committed
removed data folder; added code for compiling without SSE
1 parent 71c4707 commit 49b1c99

14 files changed

+91
-14
lines changed

FaceDetection/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
cmake_minimum_required(VERSION 2.8.4)
1+
cmake_minimum_required(VERSION 3.1.0)
22

33
project(seeta_facedet_lib)
44

55
# Build options
66
option(BUILD_EXAMPLES "Set to ON to build examples" ON)
77
option(USE_OPENMP "Set to ON to build use openmp" ON)
8+
option(USE_SSE "Set to ON to build use SSE" ON)
89

910
# Use C++11
1011
set(CMAKE_CXX_STANDARD 11)
1112
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1213
message(STATUS "C++11 support has been enabled by default.")
1314

14-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
15+
# Use SSE
16+
if (USE_SSE)
17+
add_definitions(-DUSE_SSE)
18+
message(STATUS "Use SSE")
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
20+
endif()
1521

1622
# Use OpenMP
1723
if (USE_OPENMP)
1824
find_package(OpenMP QUIET)
19-
if (OpenMP_FOUND)
25+
if (OPENMP_FOUND)
2026
message(STATUS "Use OpenMP")
2127
add_definitions(-DUSE_OPENMP)
2228
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
@@ -41,9 +47,11 @@ set(src_files
4147
src/fust.cpp
4248
)
4349

50+
# Build shared library
4451
add_library(seeta_facedet_lib SHARED ${src_files})
4552
set(facedet_required_libs seeta_facedet_lib)
4653

54+
# Build examples
4755
if (BUILD_EXAMPLES)
4856
message(STATUS "Build with examples.")
4957
find_package(OpenCV)

FaceDetection/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ FacenessNet [2] | 80x80 | n/a | 20 FPS
5959
8. Build.
6060

6161
### How to Build in Linux
62-
- build
62+
- Build
6363
```shell
6464
mkdir build
6565
cd build
6666
cmake ..
6767
make -j${nproc}
6868
```
6969

70-
- run demo
70+
- Run demo
7171
```shell
72-
./build/facedet_test data/2007_007763.jpg model/seeta_fd_frontal_v1.0.bin
72+
./build/facedet_test image_file model/seeta_fd_frontal_v1.0.bin
7373
```
7474

7575
### How to run SeetaFace Detector

FaceDetection/data/2007_007763.jpg

-87.5 KB
Binary file not shown.

FaceDetection/data/2008_001009.jpg

-40.8 KB
Binary file not shown.

FaceDetection/data/2008_001322.jpg

-63.8 KB
Binary file not shown.

FaceDetection/data/2008_002079.jpg

-90.5 KB
Binary file not shown.

FaceDetection/data/2008_002470.jpg

-89.2 KB
Binary file not shown.

FaceDetection/data/2008_002506.jpg

-77.5 KB
Binary file not shown.

FaceDetection/data/2008_004176.jpg

-91.6 KB
Binary file not shown.

FaceDetection/data/2008_007676.jpg

-107 KB
Binary file not shown.

FaceDetection/data/2009_004587.jpg

-77.6 KB
Binary file not shown.

FaceDetection/include/util/math_func.h

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#ifndef SEETA_FD_UTIL_MATH_FUNC_H_
3333
#define SEETA_FD_UTIL_MATH_FUNC_H_
3434

35+
#ifdef USE_SSE
3536
#include <immintrin.h>
37+
#endif
3638

3739
#include <cstdint>
3840

@@ -49,31 +51,37 @@ class MathFunction {
4951

5052
static inline void VectorAdd(const int32_t* x, const int32_t* y, int32_t* z,
5153
int32_t len) {
54+
int32_t i;
55+
#ifdef USE_SSE
5256
__m128i x1;
5357
__m128i y1;
5458
const __m128i* x2 = reinterpret_cast<const __m128i*>(x);
5559
const __m128i* y2 = reinterpret_cast<const __m128i*>(y);
5660
__m128i* z2 = reinterpret_cast<__m128i*>(z);
5761

58-
int32_t i;
5962
for (i = 0; i < len - 4; i += 4) {
6063
x1 = _mm_loadu_si128(x2++);
6164
y1 = _mm_loadu_si128(y2++);
6265
_mm_storeu_si128(z2++, _mm_add_epi32(x1, y1));
6366
}
6467
for (; i < len; i++)
6568
*(z + i) = (*(x + i)) + (*(y + i));
69+
#else
70+
for (i = 0; i < len; i++)
71+
*(z + i) = (*(x + i)) + (*(y + i));
72+
#endif
6673
}
6774

6875
static inline void VectorSub(const int32_t* x, const int32_t* y, int32_t* z,
6976
int32_t len) {
77+
int32_t i;
78+
#ifdef USE_SSE
7079
__m128i x1;
7180
__m128i y1;
7281
const __m128i* x2 = reinterpret_cast<const __m128i*>(x);
7382
const __m128i* y2 = reinterpret_cast<const __m128i*>(y);
7483
__m128i* z2 = reinterpret_cast<__m128i*>(z);
7584

76-
int32_t i;
7785
for (i = 0; i < len - 4; i += 4) {
7886
x1 = _mm_loadu_si128(x2++);
7987
y1 = _mm_loadu_si128(y2++);
@@ -82,47 +90,62 @@ class MathFunction {
8290
}
8391
for (; i < len; i++)
8492
*(z + i) = (*(x + i)) - (*(y + i));
93+
#else
94+
for (i = 0; i < len; i++)
95+
*(z + i) = (*(x + i)) - (*(y + i));
96+
#endif
8597
}
8698

8799
static inline void VectorAbs(const int32_t* src, int32_t* dest, int32_t len) {
100+
int32_t i;
101+
#ifdef USE_SSE
88102
__m128i val;
89103
__m128i val_abs;
90104
const __m128i* x = reinterpret_cast<const __m128i*>(src);
91105
__m128i* y = reinterpret_cast<__m128i*>(dest);
92106

93-
int32_t i;
94107
for (i = 0; i < len - 4; i += 4) {
95108
val = _mm_loadu_si128(x++);
96109
val_abs = _mm_abs_epi32(val);
97110
_mm_storeu_si128(y++, val_abs);
98111
}
99112
for (; i < len; i++)
100113
dest[i] = (src[i] >= 0 ? src[i] : -src[i]);
114+
#else
115+
for (i = 0; i < len; i++)
116+
dest[i] = (src[i] >= 0 ? src[i] : -src[i]);
117+
#endif
101118
}
102119

103120
static inline void Square(const int32_t* src, uint32_t* dest, int32_t len) {
121+
int32_t i;
122+
#ifdef USE_SSE
104123
__m128i x1;
105124
const __m128i* x2 = reinterpret_cast<const __m128i*>(src);
106125
__m128i* y2 = reinterpret_cast<__m128i*>(dest);
107126

108-
int32_t i;
109127
for (i = 0; i < len - 4; i += 4) {
110128
x1 = _mm_loadu_si128(x2++);
111129
_mm_storeu_si128(y2++, _mm_mullo_epi32(x1, x1));
112130
}
113131
for (; i < len; i++)
114132
*(dest + i) = (*(src + i)) * (*(src + i));
133+
#else
134+
for (i = 0; i < len; i++)
135+
*(dest + i) = (*(src + i)) * (*(src + i));
136+
#endif
115137
}
116138

117139
static inline float VectorInnerProduct(const float* x, const float* y,
118140
int32_t len) {
141+
float prod = 0;
142+
int32_t i;
143+
#ifdef USE_SSE
119144
__m128 x1;
120145
__m128 y1;
121146
__m128 z1 = _mm_setzero_ps();
122-
float prod;
123147
float buf[4];
124148

125-
int32_t i;
126149
for (i = 0; i < len - 4; i += 4) {
127150
x1 = _mm_loadu_ps(x + i);
128151
y1 = _mm_loadu_ps(y + i);
@@ -132,7 +155,10 @@ class MathFunction {
132155
prod = buf[0] + buf[1] + buf[2] + buf[3];
133156
for (; i < len; i++)
134157
prod += x[i] * y[i];
135-
158+
#else
159+
for (i = 0; i < len; i++)
160+
prod += x[i] * y[i];
161+
#endif
136162
return prod;
137163
}
138164
};

FaceDetection/src/feat/surf_feature_map.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ void SURFFeatureMap::ComputeIntegralImages() {
223223
void SURFFeatureMap::MaskIntegralChannel() {
224224
const int32_t* grad_x = grad_x_.data();
225225
const int32_t* grad_y = grad_y_.data();
226+
int32_t len = width_ * height_;
227+
#ifdef USE_SSE
226228
__m128i dx;
227229
__m128i dy;
228230
__m128i dx_mask;
@@ -232,7 +234,6 @@ void SURFFeatureMap::MaskIntegralChannel() {
232234
__m128i data;
233235
__m128i result;
234236
__m128i* src = reinterpret_cast<__m128i*>(int_img_.data());
235-
int32_t len = width_ * height_;
236237

237238
for (int32_t i = 0; i < len; i++) {
238239
dx = _mm_set1_epi32(*(grad_x++));
@@ -247,6 +248,32 @@ void SURFFeatureMap::MaskIntegralChannel() {
247248
result = _mm_and_si128(data, dx_mask);
248249
_mm_storeu_si128(src++, result);
249250
}
251+
#else
252+
int32_t dx, dy, dx_mask, dy_mask, cmp;
253+
int32_t xor_bits[] = {-1, -1, 0, 0};
254+
255+
int32_t* src = int_img_.data();
256+
for (int32_t i = 0; i < len; i++) {
257+
dy = *(grad_y++);
258+
dx = *(grad_x++);
259+
260+
cmp = dy < 0 ? 0xffffffff : 0x0;
261+
for (int32_t j = 0; j < 4; j++) {
262+
// cmp xor xor_bits
263+
dy_mask = cmp ^ xor_bits[j];
264+
*(src) = (*src) & dy_mask;
265+
src++;
266+
}
267+
268+
cmp = dx < 0 ? 0xffffffff : 0x0;
269+
for (int32_t j = 0; j < 4; j++) {
270+
// cmp xor xor_bits
271+
dx_mask = cmp ^ xor_bits[j];
272+
*(src) = (*src) & dx_mask;
273+
src++;
274+
}
275+
}
276+
#endif
250277
}
251278

252279
void SURFFeatureMap::Integral() {
@@ -266,6 +293,7 @@ void SURFFeatureMap::Integral() {
266293

267294
void SURFFeatureMap::VectorCumAdd(int32_t* x, int32_t len,
268295
int32_t num_channel) {
296+
#ifdef USE_SSE
269297
__m128i x1;
270298
__m128i y1;
271299
__m128i z1;
@@ -289,6 +317,14 @@ void SURFFeatureMap::VectorCumAdd(int32_t* x, int32_t len,
289317
_mm_storeu_si128(z2, z1);
290318
z2 = y2;
291319
}
320+
#else
321+
int32_t cols = len / num_channel - 1;
322+
for (int32_t i = 0; i < cols; i++) {
323+
int32_t* col1 = x + i * num_channel;
324+
int32_t* col2 = col1 + num_channel;
325+
seeta::fd::MathFunction::VectorAdd(col1, col2, col2, num_channel);
326+
}
327+
#endif
292328
}
293329

294330
void SURFFeatureMap::ComputeFeatureVector(const SURFFeature & feat,

FaceDetection/src/test/facedetection_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ int main(int argc, char** argv) {
8282
#else
8383
cout << "OpenMP is not used. " << endl;
8484
#endif
85+
86+
#ifdef USE_SSE
87+
cout << "SSE is used." << endl;
88+
#else
89+
cout << "SSE is not used." << endl;
90+
#endif
91+
8592
cout << "Image size (wxh): " << img_data.width << "x"
8693
<< img_data.height << endl;
8794

0 commit comments

Comments
 (0)