├── Makefile ├── README.md ├── bin └── Readme ├── demo.conf ├── facecaffe ├── AlgThread.cpp ├── Makefile ├── caffe_mtcnn.cpp ├── comm_lib.cpp ├── config.cpp ├── face_align.cpp ├── face_demo.cpp ├── face_mem_store.cpp ├── face_verify.cpp ├── lock.cpp ├── mtcnn.cpp ├── preprocess.cpp ├── recognition.cpp ├── scale_angle.cpp ├── simple_verifier.cpp ├── svd.cpp ├── thread.cpp ├── util.cpp └── utils.cpp ├── faces └── Readme ├── include ├── AlgThread.h ├── ai_type.h ├── caffe_mtcnn.hpp ├── cameraThread.h ├── cblas.h ├── comm_lib.hpp ├── conf │ ├── com_openailab_speechrecognition_SpeechRecognitionJNI.h │ ├── config.hpp │ ├── decode.config │ ├── fbank.conf.backup │ ├── mfcc.conf │ ├── stdtostring.h │ └── tinyalsa │ │ └── asoundlib.h ├── config.h ├── f77blas.h ├── face_align.hpp ├── face_demo.hpp ├── face_mem_store.hpp ├── face_store.hpp ├── face_verify.hpp ├── gflags │ ├── gflags.h │ ├── gflags_completions.h │ ├── gflags_declare.h │ └── gflags_gflags.h ├── glog │ ├── config.h │ ├── log_severity.h │ ├── logging.h │ ├── raw_logging.h │ ├── stl_logging.h │ └── vlog_is_on.h ├── json │ ├── json-forwards.h │ └── json.h ├── lapacke.h ├── lapacke_config.h ├── lapacke_mangling.h ├── lapacke_utils.h ├── lock.h ├── mtcnn.hpp ├── mxnet_mtcnn.hpp ├── my_head.h ├── network_shell.hpp ├── openblas_config.h ├── preprocess.h ├── recognition.h ├── scale_angle.h ├── telnet_buf.h ├── tensorflow_mtcnn.hpp ├── thread.h ├── util.h └── utils.hpp ├── main.cpp ├── models ├── LightenedCNN_B.caffemodel ├── LightenedCNN_B.prototxt ├── det1.caffemodel ├── det1.prototxt ├── det2.caffemodel ├── det2.prototxt ├── det3.caffemodel ├── det3.prototxt └── face_demo.dat ├── obj └── Readme └── run.sh /Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS := facecaffe 2 | 3 | TOPDIR := $(shell pwd) 4 | 5 | export PKG_CONFIG_PATH=/usr/local/AID/pkgconfig 6 | 7 | OBJS_DIR := $(TOPDIR)/obj/ 8 | BIN_DIR := $(TOPDIR)/bin/ 9 | FACES_DIR := $(TOPDIR)/faces/ 10 | 11 | CUR_SRCS := $(wildcard *.cpp) 12 | CUR_OBJS = $(addprefix $(OBJS_DIR), $(patsubst %.cpp, %.o, ${CUR_SRCS})) 13 | 14 | BIN := $(BIN_DIR)fp 15 | 16 | CFLAGS = -g -O2 -Wall -ffunction-sections -fdata-sections 17 | LDFLAGS = -Wl,--gc-sections 18 | 19 | LIBS= -lpthread -ldl -lm 20 | 21 | CFLAGS += -DARCH_ARM -std=c++11 -DCPU_ONLY 22 | CROSS_COMPILE = aarch64-linux-gnu- 23 | 24 | INCLUDE_DIR := -I$(TOPDIR)/include/ \ 25 | `pkg-config --cflags opencv` \ 26 | `pkg-config --cflags caffe-hrt` \ 27 | `pkg-config --cflags tengine` 28 | 29 | LIBS += `pkg-config --libs tengine` `pkg-config --libs caffe-hrt` `pkg-config --libs computelibrary` `pkg-config --libs opencv` -lglog -lboost_system 30 | 31 | AS = $(CROSS_COMPILE)as 32 | LD = $(CROSS_COMPILE)ld 33 | CC = $(CROSS_COMPILE)gcc 34 | CXX = $(CROSS_COMPILE)g++ 35 | CPP = $(CC) -E 36 | STRIP = $(CROSS_COMPILE)strip 37 | OBJCOPY = $(CROSS_COMPILE)objcopy 38 | OBJDUMP = $(CROSS_COMPILE)objdump 39 | RM = -rm -rf 40 | 41 | export CC CXX RM CFLAGS INCLUDE_DIR OBJS_DIR TOPDIR 42 | 43 | all: DIRS $(BIN) 44 | 45 | DIRS: 46 | mkdir -p $(OBJS_DIR) 47 | mkdir -p $(BIN_DIR) 48 | mkdir -p $(FACES_DIR) 49 | 50 | $(BIN): $(SUBDIRS) $(CUR_OBJS) 51 | $(CXX) $(CFLAGS) $(INCLUDE_DIR) $(LDFLAGS) $(OBJS_DIR)*.o -o $@ $(LIBS) 52 | 53 | $(SUBDIRS): SUBMAKE 54 | 55 | SUBMAKE: 56 | $(foreach dir, $(SUBDIRS), make -C $(dir);) 57 | 58 | $(CUR_OBJS):$(CUR_SRCS) 59 | $(CC) -c $(CFLAGS) $(INCLUDE_DIR) $^ -o $@ 60 | 61 | 62 | clean: 63 | rm -f ${BIN} $(OBJS_DIR)/*.o 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EAIDK-Demo 2 | [![GitHub license](http://dmlc.github.io/img/apache2.svg)](./LICENSE) 3 | 4 | EAIDK-Demo is an implementation project of face detection and recognition. The face detection using MTCNN algorithm, and recognition using LightenedCNN algorithm. 5 | 6 | The release version is 0.1.0, is based on ROCK960 Platform, target OS is Ubuntu 16.04. 7 | 8 | * MTCNN is a deep cascaded multi-task framework to boost up face detection performance. See also [OAID/FaceDetection](https://github.com/OAID/FaceDetection). 9 | * Lightened CNN is a light CNN framework to learn a compact embedding on the large-scale face data with massive noisy labels. See also [LightenedCNN](https://github.com/AlfredXiangWu/face_verification_experiment). 10 | 11 | # Release History 12 | 13 | ### Version 0.1.0 - 2018-6-1 14 | 15 | Initial version supports face register, face detection, and face recognization. 16 | Support Caffe-HRT and Tengine 17 | 18 | ## Build 19 | #### install dependency library 20 | 21 | sudo apt-get install git cmake scons protobuf-compiler libgflags-dev libgoogle-glog-dev libblas-dev libhdf5-serial-dev liblmdb-dev libleveldb-dev liblapack-dev libsnappy-dev python-numpy libprotobuf-dev libopenblas-dev libgtk2.0-dev python-yaml python-numpy python-scipy python-six 22 | sudo apt-get install --no-install-recommends libboost-all-dev 23 | sudo apt-get install libreadline-dev xinetd telnet libtool autoconf wget perl subversion build-essential gfortran libatlas-dev libatlas-base-dev git build-essential vim-gtk libgtk-3-0 libgtk-3-dev libegl1-mesa-dev 24 | 25 | * [Caffe-HRT](https://github.com/OAID/Caffe-HRT) install 26 | Please see https://github.com/OAID/Caffe-HRT/blob/master/docs/installation.md 27 | 28 | * [Tengine](https://github.com/OAID/Tengine) compile 29 | Please see https://github.com/OAID/Tengine/blob/master/doc/install.md 30 | 31 | * [Tengine](https://github.com/OAID/Tengine) install 32 | sudo mkdir -p /usr/local/AID/Tengine 33 | sudo cp -rpf ~/Tengine/install/* /usr/local/AID/Tengine 34 | wget ftp://ftp.openailab.net/tools/script/gen-pkg-config-pc.sh 35 | chmod +x ./gen-pkg-config-pc.sh 36 | sudo ./gen-pkg-config-pc.sh 37 | 38 | #### Build the runtime shared libraries 39 | 40 | cd FaceRecognition2 41 | make -j4 42 | 43 | #### run the demo 44 | 45 | chmod +x ./run.sh 46 | ./run.sh Tengine 47 | ./run.sh Caffe-HRT 48 | -------------------------------------------------------------------------------- /bin/Readme: -------------------------------------------------------------------------------- 1 | this directory store the face images -------------------------------------------------------------------------------- /demo.conf: -------------------------------------------------------------------------------- 1 | Device=webcam 2 | VideoDeviceID=0 3 | VideoWidth=1280 4 | VideoHeight=720 5 | Scale=2 6 | MinFaceSize=100 7 | FaceAngle=0.4 8 | BoolDrawRect=1 9 | FacePicturePATH=./models/faces/ 10 | Engine=Caffe-HRT 11 | -------------------------------------------------------------------------------- /facecaffe/AlgThread.cpp: -------------------------------------------------------------------------------- 1 | #include "AlgThread.h" 2 | 3 | using namespace std; 4 | using namespace cv; 5 | 6 | void AlgThread::sendFrame(Mat &mat, Mat &src) 7 | { 8 | mt.lock(); 9 | m_Mat = mat.clone(); 10 | m_srcMat = src.clone(); 11 | mt.unlock(); 12 | } 13 | Mat AlgThread::getfacemat(int i) 14 | { 15 | Mat m; 16 | if(faces[i].lasttime > 0) { 17 | m = faces[i].pic.clone(); 18 | } 19 | return m; 20 | } 21 | Mat AlgThread::getframe() 22 | { 23 | Mat m; 24 | m = m_Mat.clone(); 25 | return m; 26 | } 27 | Mat AlgThread::getSrcframe() 28 | { 29 | Mat m; 30 | m = m_srcMat.clone(); 31 | return m; 32 | } 33 | Mface AlgThread::getFace(int i) 34 | { 35 | Mface r; 36 | r = m_face[i]; 37 | return r; 38 | } 39 | float AlgThread::getFps() 40 | { 41 | return fps; 42 | } 43 | float AlgThread::getReccost() 44 | { 45 | return reccost; 46 | } 47 | int AlgThread::getFaceID() 48 | { 49 | return face_id; 50 | } 51 | 52 | void AlgThread::FaceDemoInit(double threshold_p, double threshold_r, double threshold_o, double threshold_score, double factor, int mim_size) 53 | { 54 | int ret = mFace_demo.Init(threshold_p, threshold_r, threshold_o, threshold_score, factor, mim_size); 55 | mFace_demo.LocalLoad(MODEL_DIR); 56 | } 57 | 58 | char* AlgThread::FaceDemoRecognize(Mat &mRgb, bool track, char* posStr) 59 | { 60 | std::string ss = mFace_demo.Recognize(mRgb, 3); 61 | memcpy(posStr, (char*)ss.c_str(), ss.length()); 62 | 63 | return NULL; 64 | } 65 | 66 | void AlgThread::run() 67 | { 68 | bindToCpu(4, 5); 69 | int minsize = Util::String2Int(Config::Instance()->GetValue("MinFaceSize")); 70 | float face_angle = Util::String2Double(Config::Instance()->GetValue("FaceAngle")); 71 | char position[1024]; 72 | char handposi[1024]; 73 | char regiposi[1024]; 74 | const char *sep = " <>"; 75 | Mat mat; 76 | Mat src; 77 | struct timeval tv_start, tv_end; 78 | struct timeval tv1, tv2; 79 | int framecount = 0; 80 | int cost1 = 0; 81 | float cost2 = 0; 82 | 83 | mFace_demo.SetAlgType(alg_type); 84 | 85 | FaceDemoInit(0.9, 0.9, 0.9, 0.6, 0.7, minsize); 86 | 87 | while(1) { 88 | gettimeofday(&tv_start, NULL); 89 | mt.lock(); 90 | mat = getframe(); 91 | src = getSrcframe(); 92 | mt.unlock(); 93 | if(0 < mat.total()) { 94 | framecount ++; 95 | gettimeofday(&tv1, NULL); 96 | FaceDemoRecognize(mat, false, position); 97 | gettimeofday(&tv2, NULL); 98 | cost1 += tv2.tv_sec * 1000 + tv2.tv_usec / 1000 - tv1.tv_sec * 1000 - tv1.tv_usec / 1000; 99 | char *p; 100 | int i = 0; 101 | char *sub[150]; 102 | p = strtok(position, sep); 103 | while (p && i < 150) { 104 | sub[i] = p; 105 | p = strtok(NULL, sep); 106 | i++; 107 | } 108 | int shift = 1; 109 | float pos2[50]; 110 | for (int icount = 0; icount < atoi(sub[1]); icount++) { 111 | for (int j = 1; j <= 4; j++) { 112 | pos2[shift] = atof(sub[2 + icount * 47 + j * 3]); 113 | shift++; 114 | } 115 | m_face[icount].pos.x = pos2[icount * 14 + 1]; 116 | m_face[icount].pos.y = pos2[icount * 14 + 2]; 117 | m_face[icount].pos.width = pos2[icount * 14 + 3] - pos2[icount * 14 + 1]; 118 | m_face[icount].pos.height = pos2[icount * 14 + 4] - pos2[icount * 14 + 2]; 119 | m_face[icount].name = String(sub[icount * 47 + 18]); 120 | m_face[icount].id = atoi(sub[icount * 47 + 17]); 121 | m_face[icount].drawflag = 1; 122 | 123 | for (int j = 1; j <= 10; j++) { 124 | pos2[shift] = atof(sub[18 + icount * 47 + j * 3]); 125 | shift++; 126 | } 127 | m_face[icount].node[0].x = pos2[icount * 14 + 5]; 128 | m_face[icount].node[0].y = pos2[icount * 14 + 6]; 129 | m_face[icount].node[1].x = pos2[icount * 14 + 7]; 130 | m_face[icount].node[1].y = pos2[icount * 14 + 8]; 131 | m_face[icount].node[2].x = pos2[icount * 14 + 9]; 132 | m_face[icount].node[2].y = pos2[icount * 14 + 10]; 133 | m_face[icount].node[3].x = pos2[icount * 14 + 11]; 134 | m_face[icount].node[3].y = pos2[icount * 14 + 12]; 135 | m_face[icount].node[4].x = pos2[icount * 14 + 13]; 136 | m_face[icount].node[4].y = pos2[icount * 14 + 14]; 137 | 138 | 139 | Rect rcb; 140 | rcb.x = m_face[icount].pos.x - (m_face[icount].pos.width >> 2); 141 | rcb.width = (m_face[icount].pos.width * 3) >> 1; 142 | rcb.y = m_face[icount].pos.y - (m_face[icount].pos.height >> 2); 143 | rcb.height = (m_face[icount].pos.height * 3) >> 1; 144 | if(rcb.width > mat.cols) { 145 | rcb.width = mat.cols; 146 | } 147 | if(rcb.height > mat.rows) { 148 | rcb.height = mat.rows; 149 | } 150 | if((rcb.x) < 0) { 151 | rcb.x = 0; 152 | } 153 | if((rcb.y) < 0) { 154 | rcb.y = 0; 155 | } 156 | if((rcb.x + rcb.width) > mat.cols) { 157 | rcb.x = mat.cols - rcb.width; 158 | } 159 | if((rcb.y + rcb.height) > mat.rows) { 160 | rcb.y = mat.rows - rcb.height; 161 | } 162 | } 163 | 164 | for(int icount = 3; icount > atoi(sub[1]); icount--) { 165 | m_face[icount - 1].drawflag = 0; 166 | } 167 | struct timeval tv1; 168 | gettimeofday(&tv1, NULL); 169 | int curtime = tv1.tv_sec * 1000 + tv1.tv_usec / 1000; 170 | for(int i = 0; i < 9; i ++) { 171 | if(faces[i].lasttime >= 0) { 172 | faces[i].lasttime = -10; 173 | for (int j = 0; j < atoi(sub[1]); j++) { 174 | if(faces[i].id == m_face[j].id) { 175 | faces[i].pos = m_face[j].pos; 176 | if((m_face[j].node[1].x-m_face[j].node[0].x)>(m_face[j].pos.width*face_angle)) 177 | faces[i].lasttime = faces[i].capTime + 5000 - curtime; 178 | else 179 | faces[i].lasttime = 5000; 180 | if(faces[i].lasttime < 0) { 181 | face_id ++; 182 | char name[16]; 183 | sprintf(name, "%d", face_id); 184 | int ret = mFace_demo.Register(faces[i].id, name); 185 | if(ret == 0) 186 | mFace_demo.LocalSave(MODEL_DIR); 187 | faces[i].lasttime = -10; 188 | 189 | Rect rcb; 190 | rcb.x = faces[i].pos.x - (faces[i].pos.width >> 2); 191 | rcb.width = (faces[i].pos.width * 3) >> 1; 192 | rcb.y = faces[i].pos.y - (faces[i].pos.height >> 2); 193 | rcb.height = (faces[i].pos.height * 3) >> 1; 194 | if(rcb.width > mat.cols) { 195 | rcb.width = mat.cols; 196 | } 197 | if(rcb.height > mat.rows) { 198 | rcb.height = mat.rows; 199 | } 200 | if((rcb.x) < 0) { 201 | rcb.x = 0; 202 | } 203 | if((rcb.y) < 0) { 204 | rcb.y = 0; 205 | } 206 | if((rcb.x + rcb.width) > mat.cols) { 207 | rcb.x = mat.cols - rcb.width; 208 | } 209 | if((rcb.y + rcb.height) > mat.rows) { 210 | rcb.y = mat.rows - rcb.height; 211 | } 212 | 213 | Mat mat_tmp = src(Rect(rcb.x * framescale, rcb.y * framescale, rcb.width * framescale, rcb.height * framescale)); 214 | Mat rsmat = Mat(Size(120, 120), src.type()); 215 | resize(mat_tmp, rsmat, Size(120, 120), CV_INTER_LINEAR); 216 | 217 | char path[64]; 218 | sprintf(path, "./faces/%s.png", name); 219 | imwrite(String(path), rsmat); 220 | flushRegistMat = 1; 221 | 222 | } 223 | } 224 | } 225 | } 226 | } 227 | for (int icount = 0; icount < atoi(sub[1]); icount++) { 228 | int showflag = 0; 229 | for(int i = 0; i < 9; i ++) { 230 | if(faces[i].lasttime > 0) { 231 | if(faces[i].id == m_face[icount].id) { 232 | m_face[icount].time = faces[i].lasttime / 1000; 233 | showflag = 1; 234 | } 235 | } 236 | } 237 | if(showflag == 1) 238 | continue; 239 | for(int j = 0; j < 9; j ++) { 240 | if(faces[j].lasttime == -10 && m_face[icount].id < 10000) { 241 | faces[j].capTime = curtime; 242 | faces[j].lasttime = 5000; 243 | faces[j].id = m_face[icount].id; 244 | faces[j].name = m_face[icount].name; 245 | break; 246 | } 247 | } 248 | } 249 | } 250 | 251 | gettimeofday(&tv_end, NULL); 252 | cost2 += tv_end.tv_sec * 1000 + tv_end.tv_usec / 1000 - tv_start.tv_sec * 1000 - tv_start.tv_usec / 1000; 253 | 254 | if(framecount%10 == 0) 255 | { 256 | reccost = cost1/10; 257 | fps = (10*1000 / cost2); 258 | cost1 = 0; 259 | cost2 = 0; 260 | } 261 | mat.release(); 262 | src.release(); 263 | } 264 | } 265 | 266 | 267 | -------------------------------------------------------------------------------- /facecaffe/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS := 2 | OBJS := $(addprefix $(OBJS_DIR), $(patsubst %.cpp,%.o,$(wildcard *.cpp))) 3 | 4 | all: $(OBJS) 5 | $(foreach dir, $(SUBDIRS), make -C $(dir);) 6 | 7 | $(OBJS_DIR)%.o : %.cpp 8 | ${CXX} -c ${CFLAGS} ${INCLUDE_DIR} $< -o $@ 9 | $(OBJS_DIR)%.o : %.c 10 | ${CC} -c ${CFLAGS} ${INCLUDE_DIR} $< -o $@ 11 | 12 | clean: 13 | rm -f ${OBJS_DIR}*.o 14 | $(foreach dir, $(SUBDIRS), make clean -C $(dir);) 15 | 16 | 17 | -------------------------------------------------------------------------------- /facecaffe/comm_lib.cpp: -------------------------------------------------------------------------------- 1 | #include "mtcnn.hpp" 2 | #include "comm_lib.hpp" 3 | 4 | 5 | void nms_boxes(std::vector& input, float threshold, int type, std::vector&output) 6 | { 7 | 8 | std::sort(input.begin(),input.end(), 9 | [](const face_box& a, const face_box&b) { 10 | return a.score > b.score; 11 | }); 12 | 13 | int box_num=input.size(); 14 | 15 | std::vector merged(box_num,0); 16 | 17 | for(int i=0;ithreshold) 68 | merged[j]=1; 69 | } 70 | 71 | 72 | } 73 | 74 | 75 | } 76 | 77 | void regress_boxes(std::vector& rects) 78 | { 79 | for(unsigned int i=0;i& rects) 95 | { 96 | 97 | for(unsigned int i=0;i& rects) 112 | { 113 | for(unsigned int i=0; i& input, int img_h, int img_w, std::vector& rects) 124 | { 125 | 126 | nms_boxes(input,0.7,NMS_UNION,rects); 127 | 128 | regress_boxes(rects); 129 | 130 | square_boxes(rects); 131 | 132 | padding(img_h,img_w,rects); 133 | 134 | } 135 | 136 | void generate_bounding_box(const float * confidence_data, 137 | const float * reg_data, float scale, float threshold, 138 | int feature_h, int feature_w, std::vector& output, bool transposed) 139 | { 140 | 141 | int stride = 2; 142 | int cellSize = 12; 143 | 144 | int img_h= feature_h; 145 | int img_w = feature_w; 146 | int count=img_h*img_w; 147 | confidence_data += count; 148 | 149 | for (int i = 0; i= threshold){ 151 | int y = i / img_w; 152 | int x = i - img_w * y; 153 | 154 | float top_x = (int)((x*stride + 1) / scale); 155 | float top_y = (int)((y*stride + 1) / scale); 156 | float bottom_x = (int)((x*stride + cellSize) / scale); 157 | float bottom_y = (int)((y*stride + cellSize) / scale); 158 | 159 | face_box box; 160 | box.x0 = top_x; 161 | box.y0 = top_y; 162 | box.x1 = bottom_x; 163 | box.y1 = bottom_y; 164 | 165 | box.score = *(confidence_data + i); 166 | 167 | int c_offset=y*img_w+x; 168 | int c_size=img_w*img_h; 169 | 170 | if(transposed) 171 | { 172 | 173 | box.regress[1]=reg_data[c_offset]; 174 | box.regress[0]=reg_data[c_offset+c_size]; 175 | box.regress[3]=reg_data[c_offset+2*c_size]; 176 | box.regress[2]= reg_data[c_offset+3*c_size]; 177 | } 178 | else { 179 | 180 | box.regress[0]=reg_data[c_offset]; 181 | box.regress[1]=reg_data[c_offset+c_size]; 182 | box.regress[2]=reg_data[c_offset+2*c_size]; 183 | box.regress[3]= reg_data[c_offset+3*c_size]; 184 | } 185 | 186 | output.push_back(box); 187 | } 188 | } 189 | 190 | } 191 | 192 | 193 | void set_input_buffer(std::vector& input_channels, 194 | float* input_data, const int height, const int width) 195 | { 196 | for (int i = 0; i < 3; ++i) { 197 | cv::Mat channel(height, width, CV_32FC1, input_data); 198 | input_channels.push_back(channel); 199 | input_data += width * height; 200 | } 201 | } 202 | 203 | 204 | void cal_pyramid_list(int height, int width, int min_size, float factor,std::vector& list) 205 | { 206 | int min_side = std::min(height, width); 207 | double m = 12.0 / min_size; 208 | 209 | min_side=min_side*m; 210 | double cur_scale=1.0; 211 | 212 | double scale; 213 | 214 | 215 | while (min_side >= 12) 216 | { 217 | scale=m*cur_scale; 218 | cur_scale=cur_scale *factor; 219 | min_side *= factor; 220 | 221 | int hs = std::ceil(height*scale); 222 | int ws = std::ceil(width*scale); 223 | 224 | scale_window win; 225 | win.h=hs; 226 | win.w=ws; 227 | win.scale=scale; 228 | list.push_back(win); 229 | } 230 | 231 | } 232 | 233 | void cal_landmark(std::vector& box_list) 234 | { 235 | for(unsigned int i=0;i& box_list, int img_h, int img_w) 252 | { 253 | for(unsigned int i=0; i_conf_path = conf_path; 36 | 37 | ifstream fin(conf_path.c_str()); 38 | if (!fin) 39 | { 40 | return false; 41 | } 42 | string line = ""; 43 | while (getline(fin, line)) 44 | { 45 | if (line.empty()) 46 | { 47 | continue; 48 | } 49 | if ('#' == line[0]) 50 | { 51 | continue; 52 | } 53 | string::size_type pos = line.find("="); 54 | if (string::npos != pos) 55 | { 56 | string key = line.substr(0, pos); 57 | string value = ""; 58 | if (line.size() > pos) 59 | { 60 | value = line.substr(pos + 1, line.size() - pos); 61 | } 62 | 63 | key = Util::Trim(key); 64 | value = Util::Trim(value); 65 | this->conf_kvp[key] = value; 66 | } 67 | } 68 | fin.close(); 69 | 70 | return true; 71 | } 72 | 73 | void Config::PrintAll() 74 | { 75 | map::iterator it = this->conf_kvp.begin(); 76 | for(; it != this->conf_kvp.end(); ++it) 77 | { 78 | cout<<"key:"<first<<" value:"<second<::iterator it = this->conf_kvp.find(key); 87 | if (this->conf_kvp.end() != it) 88 | { 89 | return it->second; 90 | } 91 | return ""; 92 | } 93 | 94 | bool Config::SetValue(const string& key, const string& value) 95 | { 96 | ScopeLocker locker(&_mutex); 97 | 98 | this->conf_kvp[key] = value; 99 | 100 | ofstream fout; 101 | fout.open(this->_conf_path.c_str(), ios::out | ios::binary | ios::trunc); 102 | 103 | map::iterator it = this->conf_kvp.begin(); 104 | for(; it != this->conf_kvp.end(); ++it) 105 | { 106 | fout<first<<"="<second< 2 | #include 3 | #include "scale_angle.h" 4 | 5 | int get_aligned_face(const cv::Mat& img, float* landmark, int landmark_number, int desired_width, int desired_height,cv::Mat& out) 6 | { 7 | 8 | float scale; 9 | float angle; 10 | float from_center[2]; 11 | float to_center[2]; 12 | 13 | 14 | if(cal_scale_and_angle(landmark,landmark_number,desired_width,desired_height,&scale,&angle)<0) 15 | { 16 | return -1; 17 | } 18 | 19 | 20 | to_center[0]=desired_width*0.5; 21 | to_center[1]=desired_height*0.4; 22 | 23 | from_center[0]=(landmark[0]+landmark[1])/2; 24 | from_center[1]=(landmark[5]+landmark[6])/2; 25 | 26 | cv::Mat rot_mat=cv::getRotationMatrix2D(cv::Point2f(from_center[0],from_center[1]),-1*angle,scale); 27 | 28 | float ex=to_center[0]-from_center[0]; 29 | float ey=to_center[1]-from_center[1]; 30 | 31 | rot_mat.at( 0,2)+= ex; 32 | rot_mat.at(1,2) += ey; 33 | 34 | cv::warpAffine(img,out,rot_mat,cv::Size(desired_width,desired_height)); 35 | 36 | return 1; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /facecaffe/face_mem_store.cpp: -------------------------------------------------------------------------------- 1 | #include "face_mem_store.hpp" 2 | 3 | int face_mem_store::insert_new_record(face_info& new_record) 4 | { 5 | if(cur_record_num_==max_record_num_) 6 | return -1; 7 | 8 | // if(find_record(new_record.face_id)) 9 | // return -1; 10 | 11 | remove_record(new_record.face_id); 12 | 13 | face_info * p_info=new face_info(); 14 | 15 | *p_info=new_record; 16 | 17 | data_list_.push_back(p_info); 18 | 19 | cur_record_num_++; 20 | 21 | return 0; 22 | }; 23 | 24 | int face_mem_store::get_all_records(std::vector& list) 25 | { 26 | list.insert(list.end(),data_list_.begin(),data_list_.end()); 27 | 28 | return list.size(); 29 | } 30 | 31 | 32 | int face_mem_store::remove_record(int face_id) 33 | { 34 | std::vector::iterator it=data_list_.begin(); 35 | 36 | while(it!=data_list_.end()) 37 | { 38 | if((*it)->face_id == face_id) 39 | break; 40 | it++; 41 | } 42 | 43 | if(it==data_list_.end()) 44 | return -1; 45 | 46 | delete *it; 47 | 48 | data_list_.erase(it); 49 | 50 | cur_record_num_--; 51 | 52 | return 0; 53 | } 54 | 55 | int face_mem_store::remove_record(const std::string& name) 56 | { 57 | std::vector::iterator it=data_list_.begin(); 58 | int count=0; 59 | 60 | while(it!=data_list_.end()) 61 | { 62 | 63 | if((*it)->name == name) 64 | { 65 | cur_record_num_--; 66 | delete(*it); 67 | data_list_.erase(it); 68 | count++; 69 | } 70 | else 71 | it++; 72 | } 73 | 74 | return count; 75 | } 76 | 77 | face_info * face_mem_store::find_record(int face_id) 78 | { 79 | std::vector::iterator it=data_list_.begin(); 80 | 81 | while(it!=data_list_.end()) 82 | { 83 | if((*it)->face_id == face_id) 84 | break; 85 | it++; 86 | } 87 | 88 | if(it==data_list_.end()) 89 | return nullptr; 90 | 91 | return *it; 92 | } 93 | 94 | int face_mem_store::find_record(const std::string& name, std::vector& list) 95 | { 96 | 97 | std::vector::iterator it=data_list_.begin(); 98 | 99 | while(it!=data_list_.end()) 100 | { 101 | if((*it)->name == name) 102 | list.push_back(*it); 103 | it++; 104 | } 105 | 106 | return list.size(); 107 | } 108 | 109 | 110 | -------------------------------------------------------------------------------- /facecaffe/face_verify.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "face_verify.hpp" 5 | 6 | 7 | typedef std::map creator_map; 8 | 9 | static creator_map& get_registry(void) 10 | { 11 | static creator_map * instance_ptr=new creator_map(); 12 | 13 | return *instance_ptr; 14 | } 15 | 16 | face_verifier * get_face_verifier(const std::string& name) 17 | { 18 | creator_map& registry=get_registry(); 19 | 20 | if(registry.find(name)== registry.end()) 21 | return nullptr; 22 | 23 | face_verifier_creator& func=registry[name]; 24 | 25 | return func(name); 26 | } 27 | 28 | int register_face_verifier(const std::string& name, face_verifier_creator create_func) 29 | { 30 | creator_map& registry=get_registry(); 31 | 32 | registry[name]=create_func; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /facecaffe/lock.cpp: -------------------------------------------------------------------------------- 1 | #include "lock.h" 2 | 3 | Locker::Locker(void) 4 | { 5 | #ifdef _WIN32 6 | ::InitializeCriticalSection(&m_oCriticalSection); 7 | #else //for linux 8 | if(0 != pthread_mutex_init(&mutex, NULL)) 9 | { 10 | perror("Init mutex failed!"); 11 | } 12 | #endif 13 | } 14 | 15 | Locker::~Locker(void) 16 | { 17 | #ifdef _WIN32 18 | ::DeleteCriticalSection(&m_oCriticalSection); 19 | #else //for linux 20 | if(0 != pthread_mutex_destroy(&mutex)) 21 | { 22 | perror("Destory mutex failed!"); 23 | } 24 | #endif 25 | } 26 | 27 | void Locker::Lock() 28 | { 29 | #ifdef _WIN32 30 | ::EnterCriticalSection(&m_oCriticalSection); 31 | #else //for linux 32 | if(0 != pthread_mutex_lock(&mutex)) 33 | { 34 | perror("Lock mutex failed!"); 35 | } 36 | #endif 37 | } 38 | 39 | void Locker::Unlock() 40 | { 41 | #ifdef _WIN32 42 | ::LeaveCriticalSection(&m_oCriticalSection); 43 | #else //for linux 44 | if(0 != pthread_mutex_unlock(&mutex)) 45 | { 46 | perror("Unlock mutex failed!"); 47 | } 48 | #endif 49 | } 50 | 51 | ScopeLocker::ScopeLocker(void) 52 | { 53 | } 54 | 55 | ScopeLocker::ScopeLocker( Locker* pLocker ) 56 | { 57 | if (NULL != pLocker) 58 | { 59 | m_pLocker = pLocker; 60 | m_pLocker->Lock(); 61 | } 62 | } 63 | 64 | ScopeLocker::~ScopeLocker(void) 65 | { 66 | if (NULL != m_pLocker) 67 | { 68 | m_pLocker->Unlock(); 69 | } 70 | } -------------------------------------------------------------------------------- /facecaffe/mtcnn.cpp: -------------------------------------------------------------------------------- 1 | #include "mtcnn.hpp" 2 | 3 | 4 | typedef std::map creator_map; 5 | 6 | static creator_map& get_registry(void) 7 | { 8 | static creator_map * instance_ptr=new creator_map(); 9 | 10 | return *instance_ptr; 11 | } 12 | 13 | void mtcnn_factory::register_creator(const std::string& name, creator& create_func) 14 | { 15 | creator_map& registry=get_registry(); 16 | 17 | registry[name]=create_func; 18 | } 19 | 20 | std::vector mtcnn_factory::list(void) 21 | { 22 | std::vector ret; 23 | 24 | creator_map& registry=get_registry(); 25 | 26 | creator_map::iterator it=registry.begin(); 27 | 28 | while(it!=registry.end()) 29 | { 30 | ret.push_back(it->first); 31 | it++; 32 | } 33 | 34 | return ret; 35 | } 36 | 37 | 38 | mtcnn * mtcnn_factory::create_detector(const std::string& name) 39 | { 40 | 41 | creator_map& registry=get_registry(); 42 | 43 | if(registry.find(name)== registry.end()) 44 | return nullptr; 45 | 46 | creator func=registry[name]; 47 | 48 | return func(); 49 | } 50 | -------------------------------------------------------------------------------- /facecaffe/preprocess.cpp: -------------------------------------------------------------------------------- 1 | #include "preprocess.h" 2 | 3 | int alignFace(Mat& img, Mat& dstimg, const FaceBaseInfo& f5pt, cv::Size crop_size, float ec_mc_y, float ec_y) 4 | { 5 | // circle(img, f5pt.eyeleft, 2, Scalar(0, 0, 0), 2, 8, 0); 6 | // circle(img, f5pt.eyeright, 2, Scalar(60, 0, 0), 2, 8, 0); 7 | // circle(img, f5pt.nose, 2, Scalar(120, 0, 0), 2, 8, 0); 8 | // circle(img, f5pt.mouthleft, 2, Scalar(180, 0, 0), 2, 8, 0); 9 | // circle(img, f5pt.mouthright, 2, Scalar(240, 0, 0), 2, 8, 0); 10 | 11 | std::cout << "start align...\n"; 12 | 13 | float dex = f5pt.eyeleft.x - f5pt.eyeright.x; 14 | float dey = f5pt.eyeleft.y - f5pt.eyeright.y; 15 | float ang_tan = dey / dex; 16 | float arc = atan(ang_tan); 17 | float ang = arc / CV_PI * 180; 18 | Mat img_rot(600,600,CV_8UC3); 19 | 20 | float ecx = (f5pt.eyeleft.x + f5pt.eyeright.x)*0.5; 21 | float ecy = (f5pt.eyeleft.y + f5pt.eyeright.y)*0.5; 22 | float mcx = (f5pt.mouthleft.x + f5pt.mouthright.x)*0.5; 23 | float mcy = (f5pt.mouthleft.y + f5pt.mouthright.y)*0.5; 24 | Point2f center(ecx,ecy); 25 | float mcy1 = (mcx - ecx)*sin(-arc) + (mcy - ecy)*cos(-arc) + ecy; 26 | float resize_scale = ec_mc_y / fabs(mcy1 - ecy); 27 | // printf(" %f,",resize_scale); 28 | // circle(img, center, 2, Scalar(255, 255, 255), 2, 8, 0); 29 | Mat rot = getRotationMatrix2D(center, ang, resize_scale); 30 | //Mat rot = getRotationMatrix2D(Point2f(200, 200), 30, 1); 31 | 32 | warpAffine(img, img_rot(Rect(50,50,500,500)), rot, Size(500, 500)); 33 | 34 | circle(img_rot, center, 2, Scalar(255, 255, 255), 2, 8, 0); 35 | namedWindow("img1",0); imshow("img1", img);waitKey(0); 36 | namedWindow("rot1", 0); imshow("rot1", img_rot);waitKey(0); 37 | 38 | float crop_y = ecy - ec_y+50>0 ? ecy - ec_y + 50 :0; 39 | if (crop_y + crop_size.height > img_rot.rows){ 40 | std::cout << "crop_y error!!!" << std::endl; 41 | return 0;} 42 | float crop_x = ecx - crop_size.width*0.5 + 50>0 ? ecx - crop_size.width*0.5 + 50 :0; 43 | if (crop_x + crop_size.width > img_rot.cols){ 44 | std::cout << "crop_y error!!!" << std::endl; 45 | return 0;} 46 | dstimg = img_rot(Rect(crop_x+0.5, crop_y+0.5, crop_size.width, crop_size.height)); 47 | 48 | namedWindow("crop1", 0); 49 | resizeWindow("crop1",400,400); 50 | imshow("crop1", dstimg); 51 | waitKey(0); 52 | 53 | return 1; 54 | } 55 | 56 | int preprocess(Mat& img, FaceBaseInfo& f,Size objsize, Mat& d1) 57 | { 58 | Mat cropImg; 59 | int fg = alignFace(img, cropImg, f, Size(128, 128), 38, 50); //38 50 60 | if (fg) 61 | { 62 | resize(cropImg, d1, objsize); 63 | //cv::imwrite("a.bmp", d1); 64 | d1.convertTo(d1, CV_32FC3,1.0/128,-127.5/128); 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /facecaffe/recognition.cpp: -------------------------------------------------------------------------------- 1 | #include "recognition.h" 2 | 3 | #include 4 | 5 | //#include "head.h" 6 | 7 | using namespace std; 8 | 9 | Classifier::Classifier(){net_ = NULL;} 10 | 11 | Classifier::~Classifier() 12 | { 13 | if(net_) 14 | delete net_; 15 | } 16 | 17 | 18 | void Classifier::LoadModel(const string& model_file, const string& trained_file) { 19 | 20 | #ifdef CPU_ONLY 21 | Caffe::set_mode(Caffe::CPU); 22 | #else 23 | Caffe::set_mode(Caffe::GPU); 24 | #endif 25 | 26 | net_ = new Net((model_file + "/LightenedCNN_B.prototxt"), caffe::TEST); 27 | net_->CopyTrainedLayersFrom(model_file + "/LightenedCNN_B.caffemodel"); 28 | 29 | CHECK_EQ(net_->num_inputs(), 1) << "Network should have exactly one input."; 30 | CHECK_EQ(net_->num_outputs(), 1) << "Network should have exactly one output."; 31 | 32 | } 33 | std::vector Classifier::Classify(const cv::Mat& img1) { 34 | 35 | 36 | std::vector output = Predict(img1); 37 | return output; 38 | } 39 | 40 | std::vector Classifier::Predict(const cv::Mat& img1) { 41 | 42 | cv::Mat gray = img1; 43 | 44 | //cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY); 45 | 46 | 47 | Blob* input_blob = net_->input_blobs()[0]; 48 | float * input_data=input_blob->mutable_cpu_data(); 49 | 50 | 51 | if(gray.isContinuous()) 52 | { 53 | unsigned char * p_pixel=gray.ptr(0); 54 | 55 | for(int i=0;i<128*128;i++) 56 | { 57 | input_data[i]=((float)p_pixel[i])/256; 58 | } 59 | } 60 | else 61 | { 62 | for(int i=0;i<128;i++) 63 | { 64 | unsigned char * p_row=gray.ptr(i); 65 | 66 | for(int j=0;j<128;j++) 67 | { 68 | unsigned char p_pixel=p_row[j]; 69 | 70 | input_data[0]=((float)p_pixel)/255; 71 | input_data++; 72 | } 73 | } 74 | } 75 | 76 | net_->Forward(); 77 | 78 | /* get output*/ 79 | const Blob * feature_blob=net_->blob_by_name("eltwise_fc1").get(); 80 | 81 | 82 | const float * begin=feature_blob->cpu_data(); 83 | const float* end = begin + feature_blob->channels(); 84 | 85 | return std::vector(begin, end); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /facecaffe/scale_angle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "scale_angle.h" 3 | 4 | 5 | 6 | static float frob_norm(float * f, int n) 7 | { 8 | float sum=0; 9 | 10 | for(int i=0;i 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include "face_verify.hpp" 8 | 9 | cosine_distance_verifier::~cosine_distance_verifier(void) 10 | { 11 | for(int i=0;ip_score[0]) 72 | { 73 | p_score[0]=score; 74 | p_face_id[0]=e.face_id; 75 | } 76 | 77 | } 78 | 79 | return 0; 80 | } 81 | 82 | 83 | int cosine_distance_verifier::insert_feature(float * feature, unsigned int face_id) 84 | { 85 | face_pair fp; 86 | 87 | //enable override old record of the same face_id 88 | remove_feature(face_id); 89 | 90 | fp.p_feature=(float *)malloc(sizeof(float)*feature_len_); 91 | memcpy(fp.p_feature,feature,feature_len_*sizeof(float)); 92 | fp.face_id=face_id; 93 | 94 | feature_db_.push_back(fp); 95 | 96 | return 0; 97 | } 98 | 99 | 100 | void cosine_distance_verifier::remove_feature(unsigned int face_id) 101 | { 102 | std::vector::iterator it=feature_db_.begin(); 103 | 104 | while(it!=feature_db_.end()) 105 | { 106 | if(it->face_id==face_id) 107 | { 108 | free(it->p_feature); 109 | feature_db_.erase(it); 110 | break; 111 | } 112 | it++; 113 | } 114 | } 115 | 116 | 117 | static face_verifier * cosine_distance_verifier_creator(const std::string& name) 118 | { 119 | return new cosine_distance_verifier(); 120 | } 121 | 122 | REGISTER_SIMPLE_VERIFIER(cosine_distance,cosine_distance_verifier_creator); 123 | 124 | -------------------------------------------------------------------------------- /facecaffe/svd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * credit: http://www.public.iastate.edu/~dicook/JSS/paper/code/svd.c 3 | * 4 | * 5 | */ 6 | 7 | /* 8 | * svdcomp - SVD decomposition routine. 9 | * Takes an mxn matrix a and decomposes it into udv, where u,v are 10 | * left and right orthogonal transformation matrices, and d is a 11 | * diagonal matrix of singular values. 12 | * 13 | * This routine is adapted from svdecomp.c in XLISP-STAT 2.1 which is 14 | * code from Numerical Recipes adapted by Luke Tierney and David Betz. 15 | * 16 | * Input to dsvd is as follows: 17 | * a = mxn matrix to be decomposed, gets overwritten with u 18 | * m = row dimension of a 19 | * n = column dimension of a 20 | * w = returns the vector of singular values of a 21 | * v = returns the right orthogonal transformation matrix 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include "scale_angle.h" 28 | 29 | #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) 30 | #define MAX(a,b) (a>b?a:b) 31 | #define MIN(a,b) (a bt) { ct = bt / at; result = at * sqrt(1.0 + ct * ct); } 38 | else if (bt > 0.0) { ct = at / bt; result = bt * sqrt(1.0 + ct * ct); } 39 | else result = 0.0; 40 | return(result); 41 | } 42 | 43 | 44 | int dsvd(float a[][2], int m, int n, float *w, float v[][2]) 45 | { 46 | int flag, i, its, j, jj, k, l, nm; 47 | double c, f, h, s, x, y, z; 48 | double anorm = 0.0, g = 0.0, scale = 0.0; 49 | double *rv1; 50 | double rv1_buf[8]; 51 | 52 | if (m < n) 53 | { 54 | fprintf(stderr, "#rows must be > #cols \n"); 55 | return(0); 56 | } 57 | 58 | //rv1 = (double *)malloc((unsigned int) n*sizeof(double)); 59 | rv1=rv1_buf; 60 | 61 | 62 | /* Householder reduction to bidiagonal form */ 63 | for (i = 0; i < n; i++) 64 | { 65 | /* left-hand reduction */ 66 | l = i + 1; 67 | rv1[i] = scale * g; 68 | g = s = scale = 0.0; 69 | if (i < m) 70 | { 71 | for (k = i; k < m; k++) 72 | scale += fabs((double)a[k][i]); 73 | if (scale) 74 | { 75 | for (k = i; k < m; k++) 76 | { 77 | a[k][i] = (float)((double)a[k][i]/scale); 78 | s += ((double)a[k][i] * (double)a[k][i]); 79 | } 80 | f = (double)a[i][i]; 81 | g = -SIGN(sqrt(s), f); 82 | h = f * g - s; 83 | a[i][i] = (float)(f - g); 84 | if (i != n - 1) 85 | { 86 | for (j = l; j < n; j++) 87 | { 88 | for (s = 0.0, k = i; k < m; k++) 89 | s += ((double)a[k][i] * (double)a[k][j]); 90 | f = s / h; 91 | for (k = i; k < m; k++) 92 | a[k][j] += (float)(f * (double)a[k][i]); 93 | } 94 | } 95 | for (k = i; k < m; k++) 96 | a[k][i] = (float)((double)a[k][i]*scale); 97 | } 98 | } 99 | w[i] = (float)(scale * g); 100 | 101 | /* right-hand reduction */ 102 | g = s = scale = 0.0; 103 | if (i < m && i != n - 1) 104 | { 105 | for (k = l; k < n; k++) 106 | scale += fabs((double)a[i][k]); 107 | if (scale) 108 | { 109 | for (k = l; k < n; k++) 110 | { 111 | a[i][k] = (float)((double)a[i][k]/scale); 112 | s += ((double)a[i][k] * (double)a[i][k]); 113 | } 114 | f = (double)a[i][l]; 115 | g = -SIGN(sqrt(s), f); 116 | h = f * g - s; 117 | a[i][l] = (float)(f - g); 118 | for (k = l; k < n; k++) 119 | rv1[k] = (double)a[i][k] / h; 120 | if (i != m - 1) 121 | { 122 | for (j = l; j < m; j++) 123 | { 124 | for (s = 0.0, k = l; k < n; k++) 125 | s += ((double)a[j][k] * (double)a[i][k]); 126 | for (k = l; k < n; k++) 127 | a[j][k] += (float)(s * rv1[k]); 128 | } 129 | } 130 | for (k = l; k < n; k++) 131 | a[i][k] = (float)((double)a[i][k]*scale); 132 | } 133 | } 134 | anorm = MAX(anorm, (fabs((double)w[i]) + fabs(rv1[i]))); 135 | } 136 | 137 | /* accumulate the right-hand transformation */ 138 | for (i = n - 1; i >= 0; i--) 139 | { 140 | if (i < n - 1) 141 | { 142 | if (g) 143 | { 144 | for (j = l; j < n; j++) 145 | v[j][i] = (float)(((double)a[i][j] / (double)a[i][l]) / g); 146 | /* double division to avoid underflow */ 147 | for (j = l; j < n; j++) 148 | { 149 | for (s = 0.0, k = l; k < n; k++) 150 | s += ((double)a[i][k] * (double)v[k][j]); 151 | for (k = l; k < n; k++) 152 | v[k][j] += (float)(s * (double)v[k][i]); 153 | } 154 | } 155 | for (j = l; j < n; j++) 156 | v[i][j] = v[j][i] = 0.0; 157 | } 158 | v[i][i] = 1.0; 159 | g = rv1[i]; 160 | l = i; 161 | } 162 | 163 | /* accumulate the left-hand transformation */ 164 | for (i = n - 1; i >= 0; i--) 165 | { 166 | l = i + 1; 167 | g = (double)w[i]; 168 | if (i < n - 1) 169 | for (j = l; j < n; j++) 170 | a[i][j] = 0.0; 171 | if (g) 172 | { 173 | g = 1.0 / g; 174 | if (i != n - 1) 175 | { 176 | for (j = l; j < n; j++) 177 | { 178 | for (s = 0.0, k = l; k < m; k++) 179 | s += ((double)a[k][i] * (double)a[k][j]); 180 | f = (s / (double)a[i][i]) * g; 181 | for (k = i; k < m; k++) 182 | a[k][j] += (float)(f * (double)a[k][i]); 183 | } 184 | } 185 | for (j = i; j < m; j++) 186 | a[j][i] = (float)((double)a[j][i]*g); 187 | } 188 | else 189 | { 190 | for (j = i; j < m; j++) 191 | a[j][i] = 0.0; 192 | } 193 | ++a[i][i]; 194 | } 195 | 196 | /* diagonalize the bidiagonal form */ 197 | for (k = n - 1; k >= 0; k--) 198 | { /* loop over singular values */ 199 | for (its = 0; its < 30; its++) 200 | { /* loop over allowed iterations */ 201 | flag = 1; 202 | for (l = k; l >= 0; l--) 203 | { /* test for splitting */ 204 | nm = l - 1; 205 | if (fabs(rv1[l]) + anorm == anorm) 206 | { 207 | flag = 0; 208 | break; 209 | } 210 | if (fabs((double)w[nm]) + anorm == anorm) 211 | break; 212 | } 213 | if (flag) 214 | { 215 | c = 0.0; 216 | s = 1.0; 217 | for (i = l; i <= k; i++) 218 | { 219 | f = s * rv1[i]; 220 | if (fabs(f) + anorm != anorm) 221 | { 222 | g = (double)w[i]; 223 | h = PYTHAG(f, g); 224 | w[i] = (float)h; 225 | h = 1.0 / h; 226 | c = g * h; 227 | s = (- f * h); 228 | for (j = 0; j < m; j++) 229 | { 230 | y = (double)a[j][nm]; 231 | z = (double)a[j][i]; 232 | a[j][nm] = (float)(y * c + z * s); 233 | a[j][i] = (float)(z * c - y * s); 234 | } 235 | } 236 | } 237 | } 238 | z = (double)w[k]; 239 | if (l == k) 240 | { /* convergence */ 241 | if (z < 0.0) 242 | { /* make singular value nonnegative */ 243 | w[k] = (float)(-z); 244 | for (j = 0; j < n; j++) 245 | v[j][k] = (-v[j][k]); 246 | } 247 | break; 248 | } 249 | if (its >= 30) { 250 | //free((void*) rv1); 251 | fprintf(stderr, "No convergence after 30,000! iterations \n"); 252 | return(0); 253 | } 254 | 255 | /* shift from bottom 2 x 2 minor */ 256 | x = (double)w[l]; 257 | nm = k - 1; 258 | y = (double)w[nm]; 259 | g = rv1[nm]; 260 | h = rv1[k]; 261 | f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y); 262 | g = PYTHAG(f, 1.0); 263 | f = ((x - z) * (x + z) + h * ((y / (f + SIGN(g, f))) - h)) / x; 264 | 265 | /* next QR transformation */ 266 | c = s = 1.0; 267 | for (j = l; j <= nm; j++) 268 | { 269 | i = j + 1; 270 | g = rv1[i]; 271 | y = (double)w[i]; 272 | h = s * g; 273 | g = c * g; 274 | z = PYTHAG(f, h); 275 | rv1[j] = z; 276 | c = f / z; 277 | s = h / z; 278 | f = x * c + g * s; 279 | g = g * c - x * s; 280 | h = y * s; 281 | y = y * c; 282 | for (jj = 0; jj < n; jj++) 283 | { 284 | x = (double)v[jj][j]; 285 | z = (double)v[jj][i]; 286 | v[jj][j] = (float)(x * c + z * s); 287 | v[jj][i] = (float)(z * c - x * s); 288 | } 289 | z = PYTHAG(f, h); 290 | w[j] = (float)z; 291 | if (z) 292 | { 293 | z = 1.0 / z; 294 | c = f * z; 295 | s = h * z; 296 | } 297 | f = (c * g) + (s * y); 298 | x = (c * y) - (s * g); 299 | for (jj = 0; jj < m; jj++) 300 | { 301 | y = (double)a[jj][j]; 302 | z = (double)a[jj][i]; 303 | a[jj][j] = (float)(y * c + z * s); 304 | a[jj][i] = (float)(z * c - y * s); 305 | } 306 | } 307 | rv1[l] = 0.0; 308 | rv1[k] = f; 309 | w[k] = (float)x; 310 | } 311 | } 312 | //free((void*) rv1); 313 | return(1); 314 | } 315 | 316 | -------------------------------------------------------------------------------- /facecaffe/thread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void* Thread::run0(void* pVoid) 3 | { 4 | Thread* p = (Thread*) pVoid; 5 | p->run1(); 6 | return p; 7 | } 8 | 9 | void* Thread::run1() 10 | { 11 | 12 | threadStatus = THREAD_STATUS_RUNNING; 13 | tid = pthread_self(); 14 | run(); 15 | threadStatus = THREAD_STATUS_EXIT; 16 | tid = 0; 17 | pthread_exit(NULL); 18 | } 19 | 20 | Thread::Thread() 21 | { 22 | tid = 0; 23 | threadStatus = THREAD_STATUS_NEW; 24 | } 25 | 26 | bool Thread::start() 27 | { 28 | return pthread_create(&tid, NULL, run0, this) == 0; 29 | } 30 | 31 | pthread_t Thread::getThreadID() 32 | { 33 | return tid; 34 | } 35 | 36 | int Thread::getState() 37 | { 38 | return threadStatus; 39 | } 40 | 41 | void Thread::join() 42 | { 43 | if (tid > 0) 44 | { 45 | pthread_join(tid, NULL); 46 | } 47 | } 48 | 49 | void Thread::join(unsigned long millisTime) 50 | { 51 | 52 | if (tid == 0) 53 | { 54 | return; 55 | } 56 | if (millisTime == 0) 57 | { 58 | join(); 59 | }else 60 | { 61 | unsigned long k = 0; 62 | while (threadStatus != THREAD_STATUS_EXIT && k <= millisTime) 63 | { 64 | usleep(100); 65 | k++; 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /facecaffe/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | 12 | unsigned long get_cur_time(void) 13 | { 14 | struct timeval tv; 15 | unsigned long ts; 16 | 17 | gettimeofday(&tv,NULL); 18 | 19 | ts=tv.tv_sec*1000000+tv.tv_usec; 20 | 21 | return ts; 22 | } 23 | 24 | void save_float(const char * name, const float * data, int size) 25 | { 26 | char fname[128]; 27 | 28 | sprintf(fname,"%s",name); 29 | 30 | std::cout<<"save data to "<(i); 73 | 74 | for(int j=0;j 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include "ai_type.h" 25 | #include "util.h" 26 | #include "config.h" 27 | #include "face_demo.hpp" 28 | 29 | 30 | using namespace std; 31 | using namespace cv; 32 | typedef struct mutisensor_Face { 33 | CvRect pos; 34 | String name; 35 | CvPoint node[5]; 36 | int id; 37 | int time; 38 | int drawflag = 0; 39 | } Mface; 40 | typedef struct mutisensor_Face_Picture { 41 | Mat pic; 42 | CvRect pos; 43 | String name; 44 | int id = -1; 45 | int capTime = 0; 46 | int lasttime = 0; 47 | } MfaceP; 48 | 49 | class AlgThread : public Thread 50 | { 51 | private: 52 | int framescale = 1; 53 | int framewidth = 640; 54 | int frameheight = 480; 55 | Mat m_Mat; 56 | Mat m_srcMat; 57 | Mat m_facemat[9]; 58 | 59 | 60 | Mat detect_faces[10]; 61 | 62 | MfaceP faces[9]; 63 | std::string m_facename[9]; 64 | Mface m_face[3]; 65 | std::string registerFacesPath; 66 | Mutex mt; 67 | 68 | Rect res; 69 | FaceDemo mFace_demo; 70 | int frames = 0; 71 | int m_namecount = 0; 72 | int m_facecount = 0; 73 | int face_id = 10000; 74 | float fps = 5; 75 | float reccost = 200; 76 | ALG_TYPE alg_type = TENGINE; 77 | public: 78 | void bindToCpu(int cpu1, int cpu2) 79 | { 80 | 81 | cpu_set_t mask; 82 | CPU_ZERO(&mask); 83 | //CPU_SET(cpu,&mask); 84 | CPU_SET(cpu1, &mask); 85 | CPU_SET(cpu2, &mask); 86 | 87 | if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) { 88 | fprintf(stderr, "set thread affinity failed\n"); 89 | } 90 | } 91 | AlgThread(); 92 | AlgThread(int width, int height, int scale, string path, ALG_TYPE type = TENGINE) 93 | { 94 | framescale = scale; 95 | framewidth = width; 96 | frameheight = height; 97 | registerFacesPath = path; 98 | alg_type = type; 99 | }; 100 | ~AlgThread(); 101 | void sendFrame(Mat &mat, Mat &src); 102 | Mat getfacemat(int i); 103 | Mat getframe(); 104 | Mat getSrcframe(); 105 | Mface getFace(int i); 106 | float getFps(); 107 | float getReccost(); 108 | int getFaceID(); 109 | void FaceDemoInit(double threshold_p, double threshold_r, double threshold_o, double threshold_score, double factor, int mim_size); 110 | char* FaceDemoRecognize(Mat &mRgb, bool track, char* posStr); 111 | void run(); 112 | 113 | int flushRegistMat = 0; 114 | }; 115 | 116 | -------------------------------------------------------------------------------- /include/ai_type.h: -------------------------------------------------------------------------------- 1 | #ifndef __AI_TYPE__H__ 2 | #define __AI_TYPE__H__ 3 | 4 | enum ALG_TYPE 5 | { 6 | TENGINE = 0, 7 | CAFFE_HRT =1, 8 | }; 9 | 10 | #ifndef MODEL_DIR 11 | #define MODEL_DIR "./models" 12 | #endif 13 | 14 | #endif //__AI_TYPE__H__ -------------------------------------------------------------------------------- /include/caffe_mtcnn.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CAFFE_MTCNN_HPP__ 2 | #define __CAFFE_MTCNN_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include "ai_type.h" 13 | #include "mtcnn.hpp" 14 | #include "comm_lib.hpp" 15 | 16 | #include "tengine_c_api.h" 17 | 18 | 19 | using namespace caffe; 20 | 21 | class caffe_mtcnn: public mtcnn { 22 | 23 | public: 24 | caffe_mtcnn()=default; 25 | 26 | int load_3model(const std::string& model_dir); 27 | 28 | void detect(cv::Mat& img, std::vector& face_list); 29 | 30 | ~caffe_mtcnn(); 31 | 32 | protected: 33 | 34 | void copy_one_patch(const cv::Mat& img,face_box&input_box,float * data_to, int width, int height); 35 | 36 | int run_PNet(const cv::Mat& img, scale_window& win, std::vector& box_list); 37 | void run_RNet(const cv::Mat& img,std::vector& pnet_boxes, std::vector& output_boxes); 38 | void run_ONet(const cv::Mat& img,std::vector& rnet_boxes, std::vector& output_boxes); 39 | 40 | 41 | private: 42 | int run_PNet_Tengine(const cv::Mat& img, scale_window& win, std::vector& box_list); 43 | void run_RNet_Tengine(const cv::Mat& img,std::vector& pnet_boxes, std::vector& output_boxes); 44 | void run_ONet_Tengine(const cv::Mat& img,std::vector& rnet_boxes, std::vector& output_boxes); 45 | 46 | int run_PNet_Caffe_HRT(const cv::Mat& img, scale_window& win, std::vector& box_list); 47 | void run_RNet_Caffe_HRT(const cv::Mat& img,std::vector& pnet_boxes, std::vector& output_boxes); 48 | void run_ONet_Caffe_HRT(const cv::Mat& img,std::vector& rnet_boxes, std::vector& output_boxes); 49 | 50 | Net * PNet_ = NULL; 51 | Net * RNet_ = NULL; 52 | Net * ONet_ = NULL; 53 | 54 | const char * PNet_model_name="PNet"; 55 | const char * RNet_model_name="RNet"; 56 | const char * ONet_model_name="ONet"; 57 | graph_t PNet_graph = NULL; 58 | graph_t RNet_graph = NULL; 59 | graph_t ONet_graph = NULL; 60 | 61 | }; 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/cameraThread.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using namespace cv; 7 | class cameraThread : public Thread 8 | { 9 | private: 10 | int framewidth = 640; 11 | int frameheight = 480; 12 | Mat m_Mat; 13 | CvRect m_rect[3]; 14 | Mutex mt; 15 | public: 16 | 17 | 18 | void bindToCpu(int cpu1, int cpu2) { 19 | 20 | cpu_set_t mask; 21 | CPU_ZERO(&mask); 22 | //CPU_SET(cpu,&mask); 23 | CPU_SET(cpu1,&mask); 24 | CPU_SET(cpu2,&mask); 25 | 26 | if (sched_setaffinity(0, sizeof(mask), &mask) < 0) { 27 | perror("sched_setaffinity"); 28 | } 29 | 30 | } 31 | cameraThread(); 32 | cameraThread(int width, int height) 33 | { 34 | framewidth = width; 35 | frameheight = height; 36 | }; 37 | ~cameraThread(); 38 | Mat getframe() 39 | { 40 | Mat m; 41 | mt.lock(); 42 | m = m_Mat.clone(); 43 | mt.unlock(); 44 | return m; 45 | }; 46 | void sendmessage(float* pos, int num) 47 | { 48 | for(int i = 0; i < num; i ++) 49 | { 50 | m_rect[i].x = pos[num * 14 + 1]; 51 | m_rect[i].y = pos[num * 14 + 2]; 52 | m_rect[i].width = pos[num * 14 + 3] - pos[num * 14 + 1]; 53 | m_rect[i].height= pos[num * 14 + 4] - pos[num * 14 + 2]; 54 | printf("%f %f %f %f\n",m_rect[i].x,m_rect[i].y,m_rect[i].width,m_rect[i].height); 55 | } 56 | }; 57 | void sendmessage(CvRect &rect) 58 | { 59 | m_rect[0] = rect; 60 | } 61 | void run() 62 | { 63 | //bindToCpu(4,5); 64 | VideoCapture capture(1); 65 | if (!capture.isOpened()) { //判断能够打开摄像头 66 | cout<<"can not open the camera"<& input, float threshold, int type, std::vector&output); 19 | 20 | void regress_boxes(std::vector& rects); 21 | 22 | void square_boxes(std::vector& rects); 23 | 24 | void padding(int img_h, int img_w, std::vector& rects); 25 | 26 | void process_boxes(std::vector& input, int img_h, int img_w, std::vector& rects); 27 | 28 | void generate_bounding_box(const float * confidence_data, 29 | const float * reg_data, float scale, float threshold, 30 | int feature_h, int feature_w, std::vector& output, bool transposed); 31 | 32 | 33 | void set_input_buffer(std::vector& input_channels, 34 | float* input_data, const int height, const int width); 35 | 36 | 37 | void cal_pyramid_list(int height, int width, int min_size, float factor,std::vector& list); 38 | 39 | void cal_landmark(std::vector& box_list); 40 | 41 | void set_box_bound(std::vector& box_list, int img_h, int img_w); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/conf/com_openailab_speechrecognition_SpeechRecognitionJNI.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_openailab_speechrecognition_SpeechRecognitionJNI */ 4 | 5 | #ifndef _Included_com_openailab_speechrecognition_SpeechRecognitionJNI 6 | #define _Included_com_openailab_speechrecognition_SpeechRecognitionJNI 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_openailab_speechrecognition_SpeechRecognitionJNI 12 | * Method: ASRInit 13 | * Signature: (IIIII)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_openailab_speechrecognition_SpeechRecognitionJNI_ASRInit 16 | (JNIEnv *, jclass, jint, jint, jint, jint, jint, jdouble); 17 | 18 | /* 19 | * Class: com_openailab_speechrecognition_SpeechRecognitionJNI 20 | * Method: ASRStart 21 | * Signature: ()V 22 | */ 23 | JNIEXPORT void JNICALL Java_com_openailab_speechrecognition_SpeechRecognitionJNI_ASRStart 24 | (JNIEnv *, jclass); 25 | 26 | /* 27 | * Class: com_openailab_speechrecognition_SpeechRecognitionJNI 28 | * Method: ASRStop 29 | * Signature: ()V 30 | */ 31 | JNIEXPORT void JNICALL Java_com_openailab_speechrecognition_SpeechRecognitionJNI_ASRStop 32 | (JNIEnv *, jclass); 33 | 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | #endif 39 | -------------------------------------------------------------------------------- /include/conf/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_HPP_ 2 | #define _CONFIG_HPP_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | //#define ANALYZE_LATS 0 20 | 21 | //path configurations 22 | std::string KALDI_ROOT = "/data/local/tmp/SpeechRecognition"; 23 | std::string GRAPH_DIR = KALDI_ROOT + "/tri3b/graph_word"; 24 | std::string DECODE_DIR = KALDI_ROOT + "/tri3b/decode_test_word"; 25 | //std::string OPENFST_DIR = KALDI_ROOT + "/tools/openfst/lib"; 26 | 27 | 28 | int nj = 1; 29 | 30 | //MFCC configurations 31 | std::string MFCC_config_path = KALDI_ROOT + "/conf/mfcc.conf"; 32 | bool write_utt2num_frames = false; 33 | std::string mfcc_compress = "true"; 34 | std::string use_energy = "false"; 35 | std::string sample_rate = "16000"; 36 | 37 | //CMVN configurations 38 | bool cmvn_fake = false; 39 | std::string fake_dims = "\0"; 40 | bool cmvn_two_channel = false; 41 | //split configurations 42 | bool split_per_spk = true; 43 | std::string per_utt = "\0"; //"--per-utt"; 44 | 45 | //decode configurations 46 | std::string transform_dir="\0"; // this option won't normally be used, but it can be used if you want to 47 | // supply existing fMLLR transforms when decoding. 48 | std::string decode_iter = "\0"; 49 | std::string decode_model ="\0"; // You can specify the model to use 50 | int decode_stage = 0; 51 | std::string decode_max_active = "7000"; 52 | std::string decode_beam = "13.0"; 53 | std::string decode_lattice_beam = "6.0"; 54 | std::string decode_acwt = "0.083333"; // note: only really affects pruning (scoring is on lattices). 55 | int decode_num_threads = 1; // if >1, will use gmm-latgen-faster-parallel 56 | std::string decode_parallel_opts = "\0"; // ignored now. 57 | std::string decode_scoring_opts = "\0"; 58 | bool skip_scoring = false; 59 | std::string splice_opts = "\0"; 60 | std::string cmvn_opts = "\0"; 61 | std::string delta_opts = "\0"; 62 | 63 | 64 | //diagnose configuration 65 | float frequency_cutoff_percentage = 0.5; 66 | 67 | //score configuration 68 | int score_stage = 0; 69 | bool score_decode_mbr = false; 70 | bool score_stats = true; 71 | std::string score_beam = "6"; 72 | std::string word_ins_penalty = "1.0"; //please set this same as your best wer model 73 | std::string score_lmwt = "17"; // 74 | 75 | std::string score_field_begin = "1"; //range of score field, don't modify 76 | std::string score_field_end = "\0"; //range of score field, don't modify 77 | #endif 78 | -------------------------------------------------------------------------------- /include/conf/decode.config: -------------------------------------------------------------------------------- 1 | first_beam=10.0 2 | beam=13.0 #beam for decoding. 3 | lattic_beam=6.0 #this has most effect on size of the lattices. 4 | -------------------------------------------------------------------------------- /include/conf/fbank.conf.backup: -------------------------------------------------------------------------------- 1 | #No non-default options for now. 2 | #--sample -frequency=16000 3 | --num-mel-bins=10 4 | -------------------------------------------------------------------------------- /include/conf/mfcc.conf: -------------------------------------------------------------------------------- 1 | --use-energy=false #only non-default option 2 | --sample-frequency=16000 3 | -------------------------------------------------------------------------------- /include/conf/stdtostring.h: -------------------------------------------------------------------------------- 1 | #ifndef STDTOSTRING_H 2 | #define STDTOSTRING_H 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | namespace std 8 | { 9 | template < typename T > std::string to_string( const T& n ) 10 | { 11 | std::ostringstream stm ; 12 | stm << n ; 13 | return stm.str() ; 14 | } 15 | 16 | } 17 | 18 | 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /include/conf/tinyalsa/asoundlib.h: -------------------------------------------------------------------------------- 1 | /* asoundlib.h 2 | ** 3 | ** Copyright 2011, The Android Open Source Project 4 | ** 5 | ** Redistribution and use in source and binary forms, with or without 6 | ** modification, are permitted provided that the following conditions are met: 7 | ** * Redistributions of source code must retain the above copyright 8 | ** notice, this list of conditions and the following disclaimer. 9 | ** * Redistributions in binary form must reproduce the above copyright 10 | ** notice, this list of conditions and the following disclaimer in the 11 | ** documentation and/or other materials provided with the distribution. 12 | ** * Neither the name of The Android Open Source Project nor the names of 13 | ** its contributors may be used to endorse or promote products derived 14 | ** from this software without specific prior written permission. 15 | ** 16 | ** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND 17 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE 20 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | ** DAMAGE. 27 | */ 28 | 29 | #ifndef ASOUNDLIB_H 30 | #define ASOUNDLIB_H 31 | 32 | #include 33 | #include 34 | 35 | #if defined(__cplusplus) 36 | extern "C" { 37 | #endif 38 | 39 | /* 40 | * PCM API 41 | */ 42 | 43 | struct pcm; 44 | 45 | #define PCM_OUT 0x00000000 46 | #define PCM_IN 0x10000000 47 | #define PCM_MMAP 0x00000001 48 | #define PCM_NOIRQ 0x00000002 49 | #define PCM_NORESTART 0x00000004 /* PCM_NORESTART - when set, calls to 50 | * pcm_write for a playback stream will not 51 | * attempt to restart the stream in the case 52 | * of an underflow, but will return -EPIPE 53 | * instead. After the first -EPIPE error, the 54 | * stream is considered to be stopped, and a 55 | * second call to pcm_write will attempt to 56 | * restart the stream. 57 | */ 58 | #define PCM_MONOTONIC 0x00000008 /* see pcm_get_htimestamp */ 59 | 60 | /* PCM runtime states */ 61 | #define PCM_STATE_OPEN 0 62 | #define PCM_STATE_SETUP 1 63 | #define PCM_STATE_PREPARED 2 64 | #define PCM_STATE_RUNNING 3 65 | #define PCM_STATE_XRUN 4 66 | #define PCM_STATE_DRAINING 5 67 | #define PCM_STATE_PAUSED 6 68 | #define PCM_STATE_SUSPENDED 7 69 | #define PCM_STATE_DISCONNECTED 8 70 | 71 | /* Bit formats */ 72 | enum pcm_format { 73 | PCM_FORMAT_INVALID = -1, 74 | PCM_FORMAT_S16_LE = 0, /* 16-bit signed */ 75 | PCM_FORMAT_S32_LE, /* 32-bit signed */ 76 | PCM_FORMAT_S8, /* 8-bit signed */ 77 | PCM_FORMAT_S24_LE, /* 24-bits in 4-bytes */ 78 | PCM_FORMAT_S24_3LE, /* 24-bits in 3-bytes */ 79 | 80 | PCM_FORMAT_MAX, 81 | }; 82 | 83 | /* Bitmask has 256 bits (32 bytes) in asound.h */ 84 | struct pcm_mask { 85 | unsigned int bits[32 / sizeof(unsigned int)]; 86 | }; 87 | 88 | /* Configuration for a stream */ 89 | struct pcm_config { 90 | unsigned int channels; 91 | unsigned int rate; 92 | unsigned int period_size; 93 | unsigned int period_count; 94 | enum pcm_format format; 95 | 96 | /* Values to use for the ALSA start, stop and silence thresholds, and 97 | * silence size. Setting any one of these values to 0 will cause the 98 | * default tinyalsa values to be used instead. 99 | * Tinyalsa defaults are as follows. 100 | * 101 | * start_threshold : period_count * period_size 102 | * stop_threshold : period_count * period_size 103 | * silence_threshold : 0 104 | * silence_size : 0 105 | */ 106 | unsigned int start_threshold; 107 | unsigned int stop_threshold; 108 | unsigned int silence_threshold; 109 | unsigned int silence_size; 110 | 111 | /* Minimum number of frames available before pcm_mmap_write() will actually 112 | * write into the kernel buffer. Only used if the stream is opened in mmap mode 113 | * (pcm_open() called with PCM_MMAP flag set). Use 0 for default. 114 | */ 115 | int avail_min; 116 | int flag; 117 | }; 118 | 119 | /* PCM parameters */ 120 | enum pcm_param 121 | { 122 | /* mask parameters */ 123 | PCM_PARAM_ACCESS, 124 | PCM_PARAM_FORMAT, 125 | PCM_PARAM_SUBFORMAT, 126 | /* interval parameters */ 127 | PCM_PARAM_SAMPLE_BITS, 128 | PCM_PARAM_FRAME_BITS, 129 | PCM_PARAM_CHANNELS, 130 | PCM_PARAM_RATE, 131 | PCM_PARAM_PERIOD_TIME, 132 | PCM_PARAM_PERIOD_SIZE, 133 | PCM_PARAM_PERIOD_BYTES, 134 | PCM_PARAM_PERIODS, 135 | PCM_PARAM_BUFFER_TIME, 136 | PCM_PARAM_BUFFER_SIZE, 137 | PCM_PARAM_BUFFER_BYTES, 138 | PCM_PARAM_TICK_TIME, 139 | }; 140 | 141 | /* Mixer control types */ 142 | enum mixer_ctl_type { 143 | MIXER_CTL_TYPE_BOOL, 144 | MIXER_CTL_TYPE_INT, 145 | MIXER_CTL_TYPE_ENUM, 146 | MIXER_CTL_TYPE_BYTE, 147 | MIXER_CTL_TYPE_IEC958, 148 | MIXER_CTL_TYPE_INT64, 149 | MIXER_CTL_TYPE_UNKNOWN, 150 | 151 | MIXER_CTL_TYPE_MAX, 152 | }; 153 | 154 | /* Open and close a stream */ 155 | struct pcm *pcm_open(unsigned int card, unsigned int device, 156 | unsigned int flags, struct pcm_config *config); 157 | int pcm_close(struct pcm *pcm); 158 | int pcm_is_ready(struct pcm *pcm); 159 | 160 | /* Obtain the parameters for a PCM */ 161 | struct pcm_params *pcm_params_get(unsigned int card, unsigned int device, 162 | unsigned int flags); 163 | void pcm_params_free(struct pcm_params *pcm_params); 164 | 165 | struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params, 166 | enum pcm_param param); 167 | unsigned int pcm_params_get_min(struct pcm_params *pcm_params, 168 | enum pcm_param param); 169 | void pcm_params_set_min(struct pcm_params *pcm_params, 170 | enum pcm_param param, unsigned int val); 171 | unsigned int pcm_params_get_max(struct pcm_params *pcm_params, 172 | enum pcm_param param); 173 | void pcm_params_set_max(struct pcm_params *pcm_params, 174 | enum pcm_param param, unsigned int val); 175 | 176 | /* Converts the pcm parameters to a human readable string. 177 | * The string parameter is a caller allocated buffer of size bytes, 178 | * which is then filled up to size - 1 and null terminated, 179 | * if size is greater than zero. 180 | * The return value is the number of bytes copied to string 181 | * (not including null termination) if less than size; otherwise, 182 | * the number of bytes required for the buffer. 183 | */ 184 | int pcm_params_to_string(struct pcm_params *params, char *string, unsigned int size); 185 | 186 | /* Returns 1 if the pcm_format is present (format bit set) in 187 | * the pcm_params structure; 0 otherwise, or upon unrecognized format. 188 | */ 189 | int pcm_params_format_test(struct pcm_params *params, enum pcm_format format); 190 | 191 | /* Set and get config */ 192 | int pcm_get_config(struct pcm *pcm, struct pcm_config *config); 193 | int pcm_set_config(struct pcm *pcm, struct pcm_config *config); 194 | 195 | /* Returns a human readable reason for the last error */ 196 | const char *pcm_get_error(struct pcm *pcm); 197 | 198 | /* Returns the sample size in bits for a PCM format. 199 | * As with ALSA formats, this is the storage size for the format, whereas the 200 | * format represents the number of significant bits. For example, 201 | * PCM_FORMAT_S24_LE uses 32 bits of storage. 202 | */ 203 | unsigned int pcm_format_to_bits(enum pcm_format format); 204 | 205 | /* Returns the buffer size (int frames) that should be used for pcm_write. */ 206 | unsigned int pcm_get_buffer_size(struct pcm *pcm); 207 | unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames); 208 | unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes); 209 | 210 | /* Returns the pcm latency in ms */ 211 | unsigned int pcm_get_latency(struct pcm *pcm); 212 | 213 | /* Returns available frames in pcm buffer and corresponding time stamp. 214 | * The clock is CLOCK_MONOTONIC if flag PCM_MONOTONIC was specified in pcm_open, 215 | * otherwise the clock is CLOCK_REALTIME. 216 | * For an input stream, frames available are frames ready for the 217 | * application to read. 218 | * For an output stream, frames available are the number of empty frames available 219 | * for the application to write. 220 | */ 221 | int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail, 222 | struct timespec *tstamp); 223 | 224 | /* Write data to the fifo. 225 | * Will start playback on the first write or on a write that 226 | * occurs after a fifo underrun. 227 | */ 228 | int pcm_write(struct pcm *pcm, const void *data, unsigned int count); 229 | int pcm_read(struct pcm *pcm, void *data, unsigned int count); 230 | 231 | /* 232 | * mmap() support. 233 | */ 234 | int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count); 235 | int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count); 236 | int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, 237 | unsigned int *frames); 238 | int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames); 239 | int pcm_mmap_avail(struct pcm *pcm); 240 | 241 | /* Prepare the PCM substream to be triggerable */ 242 | int pcm_prepare(struct pcm *pcm); 243 | /* Start and stop a PCM channel that doesn't transfer data */ 244 | int pcm_start(struct pcm *pcm); 245 | int pcm_stop(struct pcm *pcm); 246 | 247 | /* ioctl function for PCM driver */ 248 | int pcm_ioctl(struct pcm *pcm, int request, ...); 249 | 250 | /* Interrupt driven API */ 251 | int pcm_wait(struct pcm *pcm, int timeout); 252 | int pcm_get_poll_fd(struct pcm *pcm); 253 | 254 | /* Change avail_min after the stream has been opened with no need to stop the stream. 255 | * Only accepted if opened with PCM_MMAP and PCM_NOIRQ flags 256 | */ 257 | int pcm_set_avail_min(struct pcm *pcm, int avail_min); 258 | 259 | /* 260 | * MIXER API 261 | */ 262 | 263 | struct mixer; 264 | struct mixer_ctl; 265 | 266 | /* Open and close a mixer */ 267 | struct mixer *mixer_open(unsigned int card); 268 | void mixer_close(struct mixer *mixer); 269 | 270 | /* Get info about a mixer */ 271 | const char *mixer_get_name(struct mixer *mixer); 272 | 273 | /* Obtain mixer controls */ 274 | unsigned int mixer_get_num_ctls(struct mixer *mixer); 275 | struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id); 276 | struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name); 277 | 278 | /* Get info about mixer controls */ 279 | const char *mixer_ctl_get_name(struct mixer_ctl *ctl); 280 | enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl); 281 | const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl); 282 | unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl); 283 | unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl); 284 | const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl, 285 | unsigned int enum_id); 286 | 287 | /* Some sound cards update their controls due to external events, 288 | * such as HDMI EDID byte data changing when an HDMI cable is 289 | * connected. This API allows the count of elements to be updated. 290 | */ 291 | void mixer_ctl_update(struct mixer_ctl *ctl); 292 | 293 | /* Set and get mixer controls */ 294 | int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id); 295 | int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent); 296 | 297 | int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id); 298 | int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count); 299 | int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value); 300 | int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count); 301 | int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string); 302 | 303 | /* Determe range of integer mixer controls */ 304 | int mixer_ctl_get_range_min(struct mixer_ctl *ctl); 305 | int mixer_ctl_get_range_max(struct mixer_ctl *ctl); 306 | 307 | #if defined(__cplusplus) 308 | } /* extern "C" */ 309 | #endif 310 | 311 | #endif 312 | -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H 2 | #define _CONFIG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "lock.h" 9 | using namespace std; 10 | 11 | class Config 12 | { 13 | private: 14 | Config(void); 15 | ~Config(void); 16 | 17 | static Config* _instance; 18 | 19 | public: 20 | static Config* Instance(); 21 | static void Release(); 22 | 23 | bool LoadConfig(const string& conf_path); 24 | string GetValue(const string& key); 25 | bool SetValue(const string& key, const string& value); 26 | 27 | void PrintAll(); 28 | 29 | private: 30 | string _conf_path; 31 | map conf_kvp; 32 | Locker _mutex; 33 | 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/face_align.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_ALIGN_HPP__ 2 | #define __FACE_ALIGN_HPP__ 3 | 4 | int get_aligned_face(const cv::Mat& img, float* landmark, int landmark_number, int desired_width, int desired_height,cv::Mat& out); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/face_demo.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_DEMO__HPP__ 2 | #define __FACE_DEMO__HPP__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "ai_type.h" 14 | #include "mtcnn.hpp" 15 | #include "face_align.hpp" 16 | #include "face_verify.hpp" 17 | 18 | #include "face_mem_store.hpp" 19 | #include "face_demo.hpp" 20 | #include "recognition.h" 21 | 22 | #include "utils.hpp" 23 | 24 | #include "tengine_c_api.h" 25 | 26 | 27 | #define DEBUG 0 28 | 29 | using namespace cv; 30 | 31 | struct face_window 32 | { 33 | face_box box; 34 | unsigned int face_id; 35 | unsigned int frame_seq; 36 | float center_x; 37 | float center_y; 38 | std::string name; 39 | char title[128]; 40 | std::list score_stored; 41 | 42 | int add_score(float score) 43 | { 44 | if(score_stored.size() == 3) 45 | { 46 | score_stored.pop_front(); 47 | } 48 | score_stored.push_back(score); 49 | return score_stored.size(); 50 | } 51 | 52 | float get_avg_score() 53 | { 54 | float sum = 0; 55 | for(auto i:score_stored) 56 | sum += i; 57 | return sum/score_stored.size(); 58 | } 59 | }; 60 | 61 | 62 | class FaceDemo { 63 | public: 64 | FaceDemo(ALG_TYPE _alg_type = TENGINE){ 65 | current_frame_count = 0; 66 | win_keep_limit = 10; 67 | trace_pixels = 100; 68 | database_name = "/face_demo.dat"; 69 | score_thresh = 0.55; 70 | alg_type = _alg_type; 71 | } 72 | int Init(double threshold_p, double threshold_r, double threshold_o, double threshold_score, double factor, int mim_size); 73 | std::string Recognize(cv::Mat &frame, int face_num); 74 | //Register a face in last frame by face_id 75 | int Register(int face_id, std::string name); 76 | //Register a face by a frame which must contain only 1 face 77 | int Register(cv::Mat &frame, std::string name); 78 | int LocalSave(std::string path); 79 | int LocalLoad(std::string path); 80 | void SetAlgType(ALG_TYPE _alg_type); 81 | 82 | protected: 83 | void get_data(float* input_data, Mat &gray, int img_h, int img_w); 84 | int get_new_unknown_face_id(void); 85 | unsigned int get_new_registry_id(void); 86 | void get_face_name_by_id(unsigned int face_id, std::string& name); 87 | void drop_aged_win(unsigned int frame_count); 88 | face_window * get_face_id_name_by_position(face_box& box,unsigned int frame_seq); 89 | void get_face_title(cv::Mat& frame,face_box& box,unsigned int frame_seq); 90 | 91 | std::vector face_win_list; 92 | mtcnn * p_mtcnn = NULL; 93 | //feature_extractor * p_extractor = NULL; 94 | Classifier classifier; 95 | face_verifier * p_verifier = NULL; 96 | face_mem_store * p_mem_store = NULL; 97 | cv::Mat p_cur_frame; 98 | int current_frame_count; 99 | int win_keep_limit; 100 | int trace_pixels; 101 | std::string database_name; 102 | double score_thresh; 103 | 104 | ALG_TYPE alg_type; 105 | 106 | std::string model_dir = MODEL_DIR; 107 | const char *input_node_name = "input"; 108 | const char *model_name = "lighten_cnn"; 109 | std::string proto_name_ = model_dir+"/LightenedCNN_B.prototxt"; 110 | std::string mdl_name_ = model_dir+"/LightenedCNN_B.caffemodel"; 111 | graph_t graph; 112 | float *input_data; 113 | const char *input_tensor_name = "data"; 114 | std::string input_fname = model_dir+"test.jpg"; 115 | tensor_t input_tensor; 116 | 117 | }; 118 | 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /include/face_mem_store.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_MEM_STORE_HPP__ 2 | #define __FACE_MEM_STORE_HPP__ 3 | 4 | #include "face_store.hpp" 5 | 6 | #include 7 | 8 | 9 | class face_mem_store :public face_info_store 10 | { 11 | public: 12 | face_mem_store(int feature_len):face_info_store(feature_len),cur_record_num_(0){max_record_num_=10;}; 13 | face_mem_store(int feature_len,int max_num):face_info_store(feature_len),cur_record_num_(0){max_record_num_=max_num;}; 14 | ~face_mem_store() 15 | { 16 | for(int i=0;i& list); 27 | 28 | int remove_record(int face_id); 29 | int remove_record(const std::string& name); 30 | face_info * find_record(int face_id); 31 | int find_record(const std::string& name, std::vector& list); 32 | 33 | 34 | private: 35 | int cur_record_num_; 36 | std::vector data_list_; 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/face_store.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_STORE_HPP__ 2 | #define __FACE_STORE_HPP__ 3 | 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #define DEFUALT_MAX_RECORD_NUMBER 100 12 | 13 | struct face_info 14 | { 15 | int face_id; 16 | std::string name; 17 | float * p_feature; 18 | int feature_len; 19 | 20 | face_info() 21 | { 22 | p_feature=nullptr; 23 | } 24 | 25 | ~face_info() 26 | { 27 | if(p_feature) 28 | free(p_feature); 29 | } 30 | 31 | face_info & operator =(const face_info& r) 32 | { 33 | face_id=r.face_id; 34 | name=r.name; 35 | feature_len=r.feature_len; 36 | 37 | p_feature=(float *)malloc(sizeof(float)*feature_len); 38 | 39 | memcpy(p_feature,r.p_feature,feature_len*sizeof(float)); 40 | 41 | return *this; 42 | } 43 | }; 44 | 45 | class face_info_store 46 | { 47 | public: 48 | face_info_store(int feature_len):feature_len_(feature_len),max_record_num_(DEFUALT_MAX_RECORD_NUMBER){}; 49 | 50 | virtual ~face_info_store(){}; 51 | 52 | virtual int get_record_number()=0; 53 | virtual int get_all_records(std::vector& list)=0; 54 | 55 | virtual int insert_new_record(face_info& new_record)=0; 56 | virtual int remove_record(int face_id)=0; 57 | virtual int remove_record(const std::string& name)=0; 58 | virtual face_info * find_record(int face_id)=0; 59 | virtual int find_record(const std::string& name, std::vector& list)=0; 60 | 61 | 62 | void set_max_record_number(int n) {max_record_num_=n;}; 63 | int get_max_record_number(void) { return max_record_num_;}; 64 | 65 | protected: 66 | 67 | int feature_len_; 68 | int max_record_num_; 69 | }; 70 | 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /include/face_verify.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_VERIFY_HPP__ 2 | #define __FACE_VERIFY_HPP__ 3 | 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | class face_verifier 14 | { 15 | public: 16 | virtual float compare(float * f0, float * f1, int len)=0; 17 | 18 | virtual int search(float * f, int * p_idx, float * p_score)=0; 19 | virtual int insert_feature(float * feature, unsigned int face_id)=0; 20 | virtual void set_feature_len(int feature_len)=0; 21 | virtual void remove_feature(unsigned int face_id)=0; 22 | 23 | protected: 24 | 25 | int feature_len_; 26 | std::string name_; 27 | }; 28 | 29 | struct face_pair 30 | { 31 | float * p_feature; 32 | unsigned int face_id; 33 | }; 34 | 35 | class cosine_distance_verifier: public face_verifier 36 | { 37 | public: 38 | 39 | float compare(float * f0, float * f1, int len); 40 | 41 | int search(float * f, int * face_id, float * p_score); 42 | 43 | 44 | int insert_feature(float * feature, unsigned int face_id); 45 | 46 | void remove_feature(unsigned int face_id); 47 | 48 | void set_feature_len(int feature_len) {feature_len_=feature_len;}; 49 | 50 | cosine_distance_verifier(void){feature_len_=256;}; 51 | 52 | ~cosine_distance_verifier(void); 53 | 54 | 55 | private: 56 | std::vector feature_db_; 57 | }; 58 | 59 | typedef face_verifier * (*face_verifier_creator)(const std::string& name); 60 | 61 | face_verifier * get_face_verifier(const std::string& name); 62 | 63 | int register_face_verifier(const std::string& name, face_verifier_creator verifier); 64 | 65 | class only_for_face_verfier_auto_register 66 | { 67 | public: 68 | only_for_face_verfier_auto_register(const std::string& name, face_verifier_creator func) 69 | { 70 | register_face_verifier(name,func); 71 | } 72 | 73 | }; 74 | 75 | #define REGISTER_SIMPLE_VERIFIER(name,func) \ 76 | static only_for_face_verfier_auto_register dummy_simple_verifier_creator_## name(#name, func) 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/gflags/gflags_completions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // --- 31 | 32 | // 33 | // Implement helpful bash-style command line flag completions 34 | // 35 | // ** Functional API: 36 | // HandleCommandLineCompletions() should be called early during 37 | // program startup, but after command line flag code has been 38 | // initialized, such as the beginning of HandleCommandLineHelpFlags(). 39 | // It checks the value of the flag --tab_completion_word. If this 40 | // flag is empty, nothing happens here. If it contains a string, 41 | // however, then HandleCommandLineCompletions() will hijack the 42 | // process, attempting to identify the intention behind this 43 | // completion. Regardless of the outcome of this deduction, the 44 | // process will be terminated, similar to --helpshort flag 45 | // handling. 46 | // 47 | // ** Overview of Bash completions: 48 | // Bash can be told to programatically determine completions for the 49 | // current 'cursor word'. It does this by (in this case) invoking a 50 | // command with some additional arguments identifying the command 51 | // being executed, the word being completed, and the previous word 52 | // (if any). Bash then expects a sequence of output lines to be 53 | // printed to stdout. If these lines all contain a common prefix 54 | // longer than the cursor word, bash will replace the cursor word 55 | // with that common prefix, and display nothing. If there isn't such 56 | // a common prefix, bash will display the lines in pages using 'more'. 57 | // 58 | // ** Strategy taken for command line completions: 59 | // If we can deduce either the exact flag intended, or a common flag 60 | // prefix, we'll output exactly that. Otherwise, if information 61 | // must be displayed to the user, we'll take the opportunity to add 62 | // some helpful information beyond just the flag name (specifically, 63 | // we'll include the default flag value and as much of the flag's 64 | // description as can fit on a single terminal line width, as specified 65 | // by the flag --tab_completion_columns). Furthermore, we'll try to 66 | // make bash order the output such that the most useful or relevent 67 | // flags are the most likely to be shown at the top. 68 | // 69 | // ** Additional features: 70 | // To assist in finding that one really useful flag, substring matching 71 | // was implemented. Before pressing a to get completion for the 72 | // current word, you can append one or more '?' to the flag to do 73 | // substring matching. Here's the semantics: 74 | // --foo Show me all flags with names prefixed by 'foo' 75 | // --foo? Show me all flags with 'foo' somewhere in the name 76 | // --foo?? Same as prior case, but also search in module 77 | // definition path for 'foo' 78 | // --foo??? Same as prior case, but also search in flag 79 | // descriptions for 'foo' 80 | // Finally, we'll trim the output to a relatively small number of 81 | // flags to keep bash quiet about the verbosity of output. If one 82 | // really wanted to see all possible matches, appending a '+' to the 83 | // search word will force the exhaustive list of matches to be printed. 84 | // 85 | // ** How to have bash accept completions from a binary: 86 | // Bash requires that it be informed about each command that programmatic 87 | // completion should be enabled for. Example addition to a .bashrc 88 | // file would be (your path to gflags_completions.sh file may differ): 89 | 90 | /* 91 | $ complete -o bashdefault -o default -o nospace -C \ 92 | '/home/build/eng/bash/bash_completions.sh --tab_completion_columns $COLUMNS' \ 93 | time env binary_name another_binary [...] 94 | */ 95 | 96 | // This would allow the following to work: 97 | // $ /path/to/binary_name --vmodule 98 | // Or: 99 | // $ ./bin/path/another_binary --gfs_u 100 | // (etc) 101 | // 102 | // Sadly, it appears that bash gives no easy way to force this behavior for 103 | // all commands. That's where the "time" in the above example comes in. 104 | // If you haven't specifically added a command to the list of completion 105 | // supported commands, you can still get completions by prefixing the 106 | // entire command with "env". 107 | // $ env /some/brand/new/binary --vmod 108 | // Assuming that "binary" is a newly compiled binary, this should still 109 | // produce the expected completion output. 110 | 111 | 112 | #ifndef GFLAGS_COMPLETIONS_H_ 113 | #define GFLAGS_COMPLETIONS_H_ 114 | 115 | namespace google { 116 | 117 | extern void HandleCommandLineCompletions(void); 118 | 119 | } 120 | 121 | #endif // GFLAGS_COMPLETIONS_H_ 122 | -------------------------------------------------------------------------------- /include/gflags/gflags_declare.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // --- 31 | // 32 | // Revamped and reorganized by Craig Silverstein 33 | // 34 | // This is the file that should be included by any file which declares 35 | // command line flag. 36 | 37 | #ifndef GFLAGS_DECLARE_H_ 38 | #define GFLAGS_DECLARE_H_ 39 | 40 | 41 | // --------------------------------------------------------------------------- 42 | // Namespace of gflags library symbols. 43 | #define GFLAGS_NAMESPACE google 44 | 45 | // --------------------------------------------------------------------------- 46 | // Windows DLL import/export. 47 | 48 | // Whether gflags library is a DLL. 49 | // 50 | // Set to 1 by default when the shared gflags library was built on Windows. 51 | // Must be overwritten when this header file is used with the optionally also 52 | // built static library instead; set by CMake's INTERFACE_COMPILE_DEFINITIONS. 53 | #ifndef GFLAGS_IS_A_DLL 54 | # define GFLAGS_IS_A_DLL 0 55 | #endif 56 | 57 | // We always want to import the symbols of the gflags library. 58 | #ifndef GFLAGS_DLL_DECL 59 | # if GFLAGS_IS_A_DLL && defined(_MSC_VER) 60 | # define GFLAGS_DLL_DECL __declspec(dllimport) 61 | # else 62 | # define GFLAGS_DLL_DECL 63 | # endif 64 | #endif 65 | 66 | // We always want to import variables declared in user code. 67 | #ifndef GFLAGS_DLL_DECLARE_FLAG 68 | # if GFLAGS_IS_A_DLL && defined(_MSC_VER) 69 | # define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport) 70 | # else 71 | # define GFLAGS_DLL_DECLARE_FLAG 72 | # endif 73 | #endif 74 | 75 | // --------------------------------------------------------------------------- 76 | // Flag types 77 | #include 78 | #if 1 79 | # include // the normal place uint32_t is defined 80 | #elif 1 81 | # include // the normal place u_int32_t is defined 82 | #elif 1 83 | # include // a third place for uint32_t or u_int32_t 84 | #endif 85 | 86 | namespace GFLAGS_NAMESPACE { 87 | 88 | #if 1 // C99 89 | typedef int32_t int32; 90 | typedef uint32_t uint32; 91 | typedef int64_t int64; 92 | typedef uint64_t uint64; 93 | #elif 0 // BSD 94 | typedef int32_t int32; 95 | typedef u_int32_t uint32; 96 | typedef int64_t int64; 97 | typedef u_int64_t uint64; 98 | #elif 0 // Windows 99 | typedef __int32 int32; 100 | typedef unsigned __int32 uint32; 101 | typedef __int64 int64; 102 | typedef unsigned __int64 uint64; 103 | #else 104 | # error Do not know how to define a 32-bit integer quantity on your system 105 | #endif 106 | 107 | } // namespace GFLAGS_NAMESPACE 108 | 109 | 110 | namespace fLS { 111 | 112 | // The meaning of "string" might be different between now and when the 113 | // macros below get invoked (e.g., if someone is experimenting with 114 | // other string implementations that get defined after this file is 115 | // included). Save the current meaning now and use it in the macros. 116 | typedef std::string clstring; 117 | 118 | } // namespace fLS 119 | 120 | 121 | #define DECLARE_VARIABLE(type, shorttype, name) \ 122 | /* We always want to import declared variables, dll or no */ \ 123 | namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \ 124 | using fL##shorttype::FLAGS_##name 125 | 126 | #define DECLARE_bool(name) \ 127 | DECLARE_VARIABLE(bool, B, name) 128 | 129 | #define DECLARE_int32(name) \ 130 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int32, I, name) 131 | 132 | #define DECLARE_uint32(name) \ 133 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint32, U, name) 134 | 135 | #define DECLARE_int64(name) \ 136 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int64, I64, name) 137 | 138 | #define DECLARE_uint64(name) \ 139 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint64, U64, name) 140 | 141 | #define DECLARE_double(name) \ 142 | DECLARE_VARIABLE(double, D, name) 143 | 144 | #define DECLARE_string(name) \ 145 | /* We always want to import declared variables, dll or no */ \ 146 | namespace fLS { \ 147 | using ::fLS::clstring; \ 148 | extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \ 149 | } \ 150 | using fLS::FLAGS_##name 151 | 152 | 153 | #endif // GFLAGS_DECLARE_H_ 154 | -------------------------------------------------------------------------------- /include/gflags/gflags_gflags.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, Andreas Schuh 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // ----------------------------------------------------------------------------- 31 | // Imports the gflags library symbols into an alternative/deprecated namespace. 32 | 33 | #ifndef GFLAGS_GFLAGS_H_ 34 | # error The internal header gflags_gflags.h may only be included by gflags.h 35 | #endif 36 | 37 | #ifndef GFLAGS_NS_GFLAGS_H_ 38 | #define GFLAGS_NS_GFLAGS_H_ 39 | 40 | 41 | namespace gflags { 42 | 43 | 44 | using GFLAGS_NAMESPACE::int32; 45 | using GFLAGS_NAMESPACE::uint32; 46 | using GFLAGS_NAMESPACE::int64; 47 | using GFLAGS_NAMESPACE::uint64; 48 | 49 | using GFLAGS_NAMESPACE::RegisterFlagValidator; 50 | using GFLAGS_NAMESPACE::CommandLineFlagInfo; 51 | using GFLAGS_NAMESPACE::GetAllFlags; 52 | using GFLAGS_NAMESPACE::ShowUsageWithFlags; 53 | using GFLAGS_NAMESPACE::ShowUsageWithFlagsRestrict; 54 | using GFLAGS_NAMESPACE::DescribeOneFlag; 55 | using GFLAGS_NAMESPACE::SetArgv; 56 | using GFLAGS_NAMESPACE::GetArgvs; 57 | using GFLAGS_NAMESPACE::GetArgv; 58 | using GFLAGS_NAMESPACE::GetArgv0; 59 | using GFLAGS_NAMESPACE::GetArgvSum; 60 | using GFLAGS_NAMESPACE::ProgramInvocationName; 61 | using GFLAGS_NAMESPACE::ProgramInvocationShortName; 62 | using GFLAGS_NAMESPACE::ProgramUsage; 63 | using GFLAGS_NAMESPACE::VersionString; 64 | using GFLAGS_NAMESPACE::GetCommandLineOption; 65 | using GFLAGS_NAMESPACE::GetCommandLineFlagInfo; 66 | using GFLAGS_NAMESPACE::GetCommandLineFlagInfoOrDie; 67 | using GFLAGS_NAMESPACE::FlagSettingMode; 68 | using GFLAGS_NAMESPACE::SET_FLAGS_VALUE; 69 | using GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT; 70 | using GFLAGS_NAMESPACE::SET_FLAGS_DEFAULT; 71 | using GFLAGS_NAMESPACE::SetCommandLineOption; 72 | using GFLAGS_NAMESPACE::SetCommandLineOptionWithMode; 73 | using GFLAGS_NAMESPACE::FlagSaver; 74 | using GFLAGS_NAMESPACE::CommandlineFlagsIntoString; 75 | using GFLAGS_NAMESPACE::ReadFlagsFromString; 76 | using GFLAGS_NAMESPACE::AppendFlagsIntoFile; 77 | using GFLAGS_NAMESPACE::ReadFromFlagsFile; 78 | using GFLAGS_NAMESPACE::BoolFromEnv; 79 | using GFLAGS_NAMESPACE::Int32FromEnv; 80 | using GFLAGS_NAMESPACE::Uint32FromEnv; 81 | using GFLAGS_NAMESPACE::Int64FromEnv; 82 | using GFLAGS_NAMESPACE::Uint64FromEnv; 83 | using GFLAGS_NAMESPACE::DoubleFromEnv; 84 | using GFLAGS_NAMESPACE::StringFromEnv; 85 | using GFLAGS_NAMESPACE::SetUsageMessage; 86 | using GFLAGS_NAMESPACE::SetVersionString; 87 | using GFLAGS_NAMESPACE::ParseCommandLineNonHelpFlags; 88 | using GFLAGS_NAMESPACE::HandleCommandLineHelpFlags; 89 | using GFLAGS_NAMESPACE::AllowCommandLineReparsing; 90 | using GFLAGS_NAMESPACE::ReparseCommandLineNonHelpFlags; 91 | using GFLAGS_NAMESPACE::ShutDownCommandLineFlags; 92 | using GFLAGS_NAMESPACE::FlagRegisterer; 93 | 94 | #ifndef SWIG 95 | using GFLAGS_NAMESPACE::ParseCommandLineFlags; 96 | #endif 97 | 98 | 99 | } // namespace gflags 100 | 101 | 102 | #endif // GFLAGS_NS_GFLAGS_H_ 103 | -------------------------------------------------------------------------------- /include/glog/config.h: -------------------------------------------------------------------------------- 1 | /* define if glog doesn't use RTTI */ 2 | /* #undef DISABLE_RTTI */ 3 | 4 | /* Namespace for Google classes */ 5 | #define GOOGLE_NAMESPACE google 6 | 7 | /* Define if you have the `dladdr' function */ 8 | #define HAVE_DLADDR 9 | 10 | /* Define if you have the `snprintf' function */ 11 | #define HAVE_SNPRINTF 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_DLFCN_H 15 | 16 | /* Define to 1 if you have the header file. */ 17 | /* #undef HAVE_EXECINFO_H */ 18 | 19 | /* Define if you have the `fcntl' function */ 20 | #define HAVE_FCNTL 21 | 22 | /* Define to 1 if you have the header file. */ 23 | /* #undef HAVE_GLOB_H */ 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 29 | /* #undef HAVE_LIBPTHREAD */ 30 | 31 | /* Define to 1 if you have the header file. */ 32 | /* #undef HAVE_LIBUNWIND_H */ 33 | 34 | /* define if you have google gflags library */ 35 | #define HAVE_LIB_GFLAGS 36 | 37 | /* define if you have google gmock library */ 38 | /* #undef HAVE_LIB_GMOCK */ 39 | 40 | /* define if you have google gtest library */ 41 | /* #undef HAVE_LIB_GTEST */ 42 | 43 | /* define if you have libunwind */ 44 | /* #undef HAVE_LIB_UNWIND */ 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_MEMORY_H 48 | 49 | /* define to disable multithreading support. */ 50 | /* #undef NO_THREADS */ 51 | 52 | /* define if the compiler implements namespaces */ 53 | #define HAVE_NAMESPACES 54 | 55 | /* Define if you have the 'pread' function */ 56 | #define HAVE_PREAD 57 | 58 | /* Define if you have POSIX threads libraries and header files. */ 59 | #define HAVE_PTHREAD 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_PWD_H 63 | 64 | /* Define if you have the 'pwrite' function */ 65 | #define HAVE_PWRITE 66 | 67 | /* define if the compiler implements pthread_rwlock_* */ 68 | #define HAVE_RWLOCK 69 | 70 | /* Define if you have the 'sigaction' function */ 71 | #define HAVE_SIGACTION 72 | 73 | /* Define if you have the `sigaltstack' function */ 74 | /* #undef HAVE_SIGALTSTACK */ 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_STDINT_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_STDLIB_H 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_STRINGS_H 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_STRING_H 87 | 88 | /* Define to 1 if you have the header file. */ 89 | /* #undef HAVE_SYSCALL_H */ 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_SYSLOG_H 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #define HAVE_SYS_STAT_H 96 | 97 | /* Define to 1 if you have the header file. */ 98 | #define HAVE_SYS_SYSCALL_H 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #define HAVE_SYS_TIME_H 102 | 103 | /* Define to 1 if you have the header file. */ 104 | #define HAVE_SYS_TYPES_H 1 105 | 106 | /* Define to 1 if you have the header file. */ 107 | /* #undef HAVE_SYS_UCONTEXT_H */ 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_SYS_UTSNAME_H 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_UCONTEXT_H 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_UNISTD_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_UNWIND_H 1 120 | 121 | /* define if the compiler supports using expression for operator */ 122 | #define HAVE_USING_OPERATOR 123 | 124 | /* define if your compiler has __attribute__ */ 125 | #define HAVE___ATTRIBUTE__ 126 | 127 | /* define if your compiler has __builtin_expect */ 128 | #define HAVE___BUILTIN_EXPECT 1 129 | 130 | /* define if your compiler has __sync_val_compare_and_swap */ 131 | #define HAVE___SYNC_VAL_COMPARE_AND_SWAP 132 | 133 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 134 | */ 135 | /* #undef LT_OBJDIR */ 136 | 137 | /* Name of package */ 138 | /* #undef PACKAGE */ 139 | 140 | /* Define to the address where bug reports for this package should be sent. */ 141 | /* #undef PACKAGE_BUGREPORT */ 142 | 143 | /* Define to the full name of this package. */ 144 | /* #undef PACKAGE_NAME */ 145 | 146 | /* Define to the full name and version of this package. */ 147 | /* #undef PACKAGE_STRING */ 148 | 149 | /* Define to the one symbol short name of this package. */ 150 | /* #undef PACKAGE_TARNAME */ 151 | 152 | /* Define to the home page for this package. */ 153 | /* #undef PACKAGE_URL */ 154 | 155 | /* Define to the version of this package. */ 156 | /* #undef PACKAGE_VERSION */ 157 | 158 | /* How to access the PC from a struct ucontext */ 159 | /* #undef PC_FROM_UCONTEXT */ 160 | 161 | /* Define to necessary symbol if this constant uses a non-standard name on 162 | your system. */ 163 | /* #undef PTHREAD_CREATE_JOINABLE */ 164 | 165 | /* The size of `void *', as computed by sizeof. */ 166 | #define SIZEOF_VOID_P 8 167 | 168 | /* Define to 1 if you have the ANSI C header files. */ 169 | /* #undef STDC_HEADERS */ 170 | 171 | /* the namespace where STL code like vector<> is defined */ 172 | #define STL_NAMESPACE std 173 | 174 | /* location of source code */ 175 | #define TEST_SRC_DIR "/home/felix/dl/openailab/caffe-android-lib/glog" 176 | 177 | /* Version number of package */ 178 | /* #undef VERSION */ 179 | 180 | /* Stops putting the code inside the Google namespace */ 181 | #define _END_GOOGLE_NAMESPACE_ } 182 | 183 | /* Puts following code inside the Google namespace */ 184 | #define _START_GOOGLE_NAMESPACE_ namespace google { 185 | -------------------------------------------------------------------------------- /include/glog/log_severity.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef BASE_LOG_SEVERITY_H__ 31 | #define BASE_LOG_SEVERITY_H__ 32 | 33 | // Annoying stuff for windows -- makes sure clients can import these functions 34 | #ifndef GOOGLE_GLOG_DLL_DECL 35 | # if defined(_WIN32) && !defined(__CYGWIN__) 36 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 37 | # else 38 | # define GOOGLE_GLOG_DLL_DECL 39 | # endif 40 | #endif 41 | 42 | // Variables of type LogSeverity are widely taken to lie in the range 43 | // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if 44 | // you ever need to change their values or add a new severity. 45 | typedef int LogSeverity; 46 | 47 | const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, 48 | NUM_SEVERITIES = 4; 49 | #ifndef GLOG_NO_ABBREVIATED_SEVERITIES 50 | # ifdef ERROR 51 | # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. 52 | # endif 53 | const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, 54 | ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; 55 | #endif 56 | 57 | // DFATAL is FATAL in debug mode, ERROR in normal mode 58 | #ifdef NDEBUG 59 | #define DFATAL_LEVEL ERROR 60 | #else 61 | #define DFATAL_LEVEL FATAL 62 | #endif 63 | 64 | extern GOOGLE_GLOG_DLL_DECL const char* const LogSeverityNames[NUM_SEVERITIES]; 65 | 66 | // NDEBUG usage helpers related to (RAW_)DCHECK: 67 | // 68 | // DEBUG_MODE is for small !NDEBUG uses like 69 | // if (DEBUG_MODE) foo.CheckThatFoo(); 70 | // instead of substantially more verbose 71 | // #ifndef NDEBUG 72 | // foo.CheckThatFoo(); 73 | // #endif 74 | // 75 | // IF_DEBUG_MODE is for small !NDEBUG uses like 76 | // IF_DEBUG_MODE( string error; ) 77 | // DCHECK(Foo(&error)) << error; 78 | // instead of substantially more verbose 79 | // #ifndef NDEBUG 80 | // string error; 81 | // DCHECK(Foo(&error)) << error; 82 | // #endif 83 | // 84 | #ifdef NDEBUG 85 | enum { DEBUG_MODE = 0 }; 86 | #define IF_DEBUG_MODE(x) 87 | #else 88 | enum { DEBUG_MODE = 1 }; 89 | #define IF_DEBUG_MODE(x) x 90 | #endif 91 | 92 | #endif // BASE_LOG_SEVERITY_H__ 93 | -------------------------------------------------------------------------------- /include/glog/raw_logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Maxim Lifantsev 31 | // 32 | // Thread-safe logging routines that do not allocate any memory or 33 | // acquire any locks, and can therefore be used by low-level memory 34 | // allocation and synchronization code. 35 | 36 | #ifndef BASE_RAW_LOGGING_H_ 37 | #define BASE_RAW_LOGGING_H_ 38 | 39 | #include 40 | 41 | namespace google { 42 | 43 | #include "glog/log_severity.h" 44 | #include "glog/vlog_is_on.h" 45 | 46 | // Annoying stuff for windows -- makes sure clients can import these functions 47 | #ifndef GOOGLE_GLOG_DLL_DECL 48 | # if defined(_WIN32) && !defined(__CYGWIN__) 49 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 50 | # else 51 | # define GOOGLE_GLOG_DLL_DECL 52 | # endif 53 | #endif 54 | 55 | // This is similar to LOG(severity) << format... and VLOG(level) << format.., 56 | // but 57 | // * it is to be used ONLY by low-level modules that can't use normal LOG() 58 | // * it is desiged to be a low-level logger that does not allocate any 59 | // memory and does not need any locks, hence: 60 | // * it logs straight and ONLY to STDERR w/o buffering 61 | // * it uses an explicit format and arguments list 62 | // * it will silently chop off really long message strings 63 | // Usage example: 64 | // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error); 65 | // RAW_VLOG(3, "status is %i", status); 66 | // These will print an almost standard log lines like this to stderr only: 67 | // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file 68 | // I0821 211317 file.cc:142] RAW: status is 20 69 | #define RAW_LOG(severity, ...) \ 70 | do { \ 71 | switch (google::GLOG_ ## severity) { \ 72 | case 0: \ 73 | RAW_LOG_INFO(__VA_ARGS__); \ 74 | break; \ 75 | case 1: \ 76 | RAW_LOG_WARNING(__VA_ARGS__); \ 77 | break; \ 78 | case 2: \ 79 | RAW_LOG_ERROR(__VA_ARGS__); \ 80 | break; \ 81 | case 3: \ 82 | RAW_LOG_FATAL(__VA_ARGS__); \ 83 | break; \ 84 | default: \ 85 | break; \ 86 | } \ 87 | } while (0) 88 | 89 | // The following STRIP_LOG testing is performed in the header file so that it's 90 | // possible to completely compile out the logging code and the log messages. 91 | #if STRIP_LOG == 0 92 | #define RAW_VLOG(verboselevel, ...) \ 93 | do { \ 94 | if (VLOG_IS_ON(verboselevel)) { \ 95 | RAW_LOG_INFO(__VA_ARGS__); \ 96 | } \ 97 | } while (0) 98 | #else 99 | #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__) 100 | #endif // STRIP_LOG == 0 101 | 102 | #if STRIP_LOG == 0 103 | #define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ 104 | __FILE__, __LINE__, __VA_ARGS__) 105 | #else 106 | #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) 107 | #endif // STRIP_LOG == 0 108 | 109 | #if STRIP_LOG <= 1 110 | #define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ 111 | __FILE__, __LINE__, __VA_ARGS__) 112 | #else 113 | #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) 114 | #endif // STRIP_LOG <= 1 115 | 116 | #if STRIP_LOG <= 2 117 | #define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ 118 | __FILE__, __LINE__, __VA_ARGS__) 119 | #else 120 | #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) 121 | #endif // STRIP_LOG <= 2 122 | 123 | #if STRIP_LOG <= 3 124 | #define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ 125 | __FILE__, __LINE__, __VA_ARGS__) 126 | #else 127 | #define RAW_LOG_FATAL(...) \ 128 | do { \ 129 | google::RawLogStub__(0, __VA_ARGS__); \ 130 | exit(1); \ 131 | } while (0) 132 | #endif // STRIP_LOG <= 3 133 | 134 | // Similar to CHECK(condition) << message, 135 | // but for low-level modules: we use only RAW_LOG that does not allocate memory. 136 | // We do not want to provide args list here to encourage this usage: 137 | // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args); 138 | // so that the args are not computed when not needed. 139 | #define RAW_CHECK(condition, message) \ 140 | do { \ 141 | if (!(condition)) { \ 142 | RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \ 143 | } \ 144 | } while (0) 145 | 146 | // Debug versions of RAW_LOG and RAW_CHECK 147 | #ifndef NDEBUG 148 | 149 | #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__) 150 | #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message) 151 | 152 | #else // NDEBUG 153 | 154 | #define RAW_DLOG(severity, ...) \ 155 | while (false) \ 156 | RAW_LOG(severity, __VA_ARGS__) 157 | #define RAW_DCHECK(condition, message) \ 158 | while (false) \ 159 | RAW_CHECK(condition, message) 160 | 161 | #endif // NDEBUG 162 | 163 | // Stub log function used to work around for unused variable warnings when 164 | // building with STRIP_LOG > 0. 165 | static inline void RawLogStub__(int /* ignored */, ...) { 166 | } 167 | 168 | // Helper function to implement RAW_LOG and RAW_VLOG 169 | // Logs format... at "severity" level, reporting it 170 | // as called from file:line. 171 | // This does not allocate memory or acquire locks. 172 | GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity, 173 | const char* file, 174 | int line, 175 | const char* format, ...) 176 | ; 177 | 178 | // Hack to propagate time information into this module so that 179 | // this module does not have to directly call localtime_r(), 180 | // which could allocate memory. 181 | GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs); 182 | 183 | } 184 | 185 | #endif // BASE_RAW_LOGGING_H_ 186 | -------------------------------------------------------------------------------- /include/glog/stl_logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Stream output operators for STL containers; to be used for logging *only*. 31 | // Inclusion of this file lets you do: 32 | // 33 | // list x; 34 | // LOG(INFO) << "data: " << x; 35 | // vector v1, v2; 36 | // CHECK_EQ(v1, v2); 37 | // 38 | // If you want to use this header file with hash maps or slist, you 39 | // need to define macros before including this file: 40 | // 41 | // - GLOG_STL_LOGGING_FOR_UNORDERED - and 42 | // - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - 43 | // - GLOG_STL_LOGGING_FOR_EXT_HASH - 44 | // - GLOG_STL_LOGGING_FOR_EXT_SLIST - 45 | // 46 | 47 | #ifndef UTIL_GTL_STL_LOGGING_INL_H_ 48 | #define UTIL_GTL_STL_LOGGING_INL_H_ 49 | 50 | #if !1 51 | # error We do not support stl_logging for this compiler 52 | #endif 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 63 | # include 64 | # include 65 | #endif 66 | 67 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 68 | # include 69 | # include 70 | #endif 71 | 72 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 73 | # include 74 | # include 75 | #endif 76 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST 77 | # include 78 | #endif 79 | 80 | // Forward declare these two, and define them after all the container streams 81 | // operators so that we can recurse from pair -> container -> container -> pair 82 | // properly. 83 | template 84 | std::ostream& operator<<(std::ostream& out, const std::pair& p); 85 | 86 | namespace google { 87 | 88 | template 89 | void PrintSequence(std::ostream& out, Iter begin, Iter end); 90 | 91 | } 92 | 93 | #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \ 94 | template \ 95 | inline std::ostream& operator<<(std::ostream& out, \ 96 | const Sequence& seq) { \ 97 | google::PrintSequence(out, seq.begin(), seq.end()); \ 98 | return out; \ 99 | } 100 | 101 | OUTPUT_TWO_ARG_CONTAINER(std::vector) 102 | OUTPUT_TWO_ARG_CONTAINER(std::deque) 103 | OUTPUT_TWO_ARG_CONTAINER(std::list) 104 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST 105 | OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist) 106 | #endif 107 | 108 | #undef OUTPUT_TWO_ARG_CONTAINER 109 | 110 | #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \ 111 | template \ 112 | inline std::ostream& operator<<(std::ostream& out, \ 113 | const Sequence& seq) { \ 114 | google::PrintSequence(out, seq.begin(), seq.end()); \ 115 | return out; \ 116 | } 117 | 118 | OUTPUT_THREE_ARG_CONTAINER(std::set) 119 | OUTPUT_THREE_ARG_CONTAINER(std::multiset) 120 | 121 | #undef OUTPUT_THREE_ARG_CONTAINER 122 | 123 | #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \ 124 | template \ 125 | inline std::ostream& operator<<(std::ostream& out, \ 126 | const Sequence& seq) { \ 127 | google::PrintSequence(out, seq.begin(), seq.end()); \ 128 | return out; \ 129 | } 130 | 131 | OUTPUT_FOUR_ARG_CONTAINER(std::map) 132 | OUTPUT_FOUR_ARG_CONTAINER(std::multimap) 133 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 134 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set) 135 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset) 136 | #endif 137 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 138 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set) 139 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset) 140 | #endif 141 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 142 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set) 143 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset) 144 | #endif 145 | 146 | #undef OUTPUT_FOUR_ARG_CONTAINER 147 | 148 | #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \ 149 | template \ 150 | inline std::ostream& operator<<(std::ostream& out, \ 151 | const Sequence& seq) { \ 152 | google::PrintSequence(out, seq.begin(), seq.end()); \ 153 | return out; \ 154 | } 155 | 156 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 157 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) 158 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) 159 | #endif 160 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 161 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map) 162 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap) 163 | #endif 164 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 165 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map) 166 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap) 167 | #endif 168 | 169 | #undef OUTPUT_FIVE_ARG_CONTAINER 170 | 171 | template 172 | inline std::ostream& operator<<(std::ostream& out, 173 | const std::pair& p) { 174 | out << '(' << p.first << ", " << p.second << ')'; 175 | return out; 176 | } 177 | 178 | namespace google { 179 | 180 | template 181 | inline void PrintSequence(std::ostream& out, Iter begin, Iter end) { 182 | // Output at most 100 elements -- appropriate if used for logging. 183 | for (int i = 0; begin != end && i < 100; ++i, ++begin) { 184 | if (i > 0) out << ' '; 185 | out << *begin; 186 | } 187 | if (begin != end) { 188 | out << " ..."; 189 | } 190 | } 191 | 192 | } 193 | 194 | // Note that this is technically undefined behavior! We are adding things into 195 | // the std namespace for a reason though -- we are providing new operations on 196 | // types which are themselves defined with this namespace. Without this, these 197 | // operator overloads cannot be found via ADL. If these definitions are not 198 | // found via ADL, they must be #included before they're used, which requires 199 | // this header to be included before apparently independent other headers. 200 | // 201 | // For example, base/logging.h defines various template functions to implement 202 | // CHECK_EQ(x, y) and stream x and y into the log in the event the check fails. 203 | // It does so via the function template MakeCheckOpValueString: 204 | // template 205 | // void MakeCheckOpValueString(strstream* ss, const T& v) { 206 | // (*ss) << v; 207 | // } 208 | // Because 'glog/logging.h' is included before 'glog/stl_logging.h', 209 | // subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only 210 | // find these operator definitions via ADL. 211 | // 212 | // Even this solution has problems -- it may pull unintended operators into the 213 | // namespace as well, allowing them to also be found via ADL, and creating code 214 | // that only works with a particular order of includes. Long term, we need to 215 | // move all of the *definitions* into namespace std, bet we need to ensure no 216 | // one references them first. This lets us take that step. We cannot define them 217 | // in both because that would create ambiguous overloads when both are found. 218 | namespace std { using ::operator<<; } 219 | 220 | #endif // UTIL_GTL_STL_LOGGING_INL_H_ 221 | -------------------------------------------------------------------------------- /include/glog/vlog_is_on.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999, 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Ray Sidney and many others 31 | // 32 | // Defines the VLOG_IS_ON macro that controls the variable-verbosity 33 | // conditional logging. 34 | // 35 | // It's used by VLOG and VLOG_IF in logging.h 36 | // and by RAW_VLOG in raw_logging.h to trigger the logging. 37 | // 38 | // It can also be used directly e.g. like this: 39 | // if (VLOG_IS_ON(2)) { 40 | // // do some logging preparation and logging 41 | // // that can't be accomplished e.g. via just VLOG(2) << ...; 42 | // } 43 | // 44 | // The truth value that VLOG_IS_ON(level) returns is determined by 45 | // the three verbosity level flags: 46 | // --v= Gives the default maximal active V-logging level; 47 | // 0 is the default. 48 | // Normally positive values are used for V-logging levels. 49 | // --vmodule= Gives the per-module maximal V-logging levels to override 50 | // the value given by --v. 51 | // E.g. "my_module=2,foo*=3" would change the logging level 52 | // for all code in source files "my_module.*" and "foo*.*" 53 | // ("-inl" suffixes are also disregarded for this matching). 54 | // 55 | // SetVLOGLevel helper function is provided to do limited dynamic control over 56 | // V-logging by overriding the per-module settings given via --vmodule flag. 57 | // 58 | // CAVEAT: --vmodule functionality is not available in non gcc compilers. 59 | // 60 | 61 | #ifndef BASE_VLOG_IS_ON_H_ 62 | #define BASE_VLOG_IS_ON_H_ 63 | 64 | #include "glog/log_severity.h" 65 | 66 | // Annoying stuff for windows -- makes sure clients can import these functions 67 | #ifndef GOOGLE_GLOG_DLL_DECL 68 | # if defined(_WIN32) && !defined(__CYGWIN__) 69 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 70 | # else 71 | # define GOOGLE_GLOG_DLL_DECL 72 | # endif 73 | #endif 74 | 75 | #if defined(__GNUC__) 76 | // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site. 77 | // (Normally) the first time every VLOG_IS_ON(n) site is hit, 78 | // we determine what variable will dynamically control logging at this site: 79 | // it's either FLAGS_v or an appropriate internal variable 80 | // matching the current source file that represents results of 81 | // parsing of --vmodule flag and/or SetVLOGLevel calls. 82 | #define VLOG_IS_ON(verboselevel) \ 83 | __extension__ \ 84 | ({ static google::int32* vlocal__ = &google::kLogSiteUninitialized; \ 85 | google::int32 verbose_level__ = (verboselevel); \ 86 | (*vlocal__ >= verbose_level__) && \ 87 | ((vlocal__ != &google::kLogSiteUninitialized) || \ 88 | (google::InitVLOG3__(&vlocal__, &FLAGS_v, \ 89 | __FILE__, verbose_level__))); }) 90 | #else 91 | // GNU extensions not available, so we do not support --vmodule. 92 | // Dynamic value of FLAGS_v always controls the logging level. 93 | #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel)) 94 | #endif 95 | 96 | // Set VLOG(_IS_ON) level for module_pattern to log_level. 97 | // This lets us dynamically control what is normally set by the --vmodule flag. 98 | // Returns the level that previously applied to module_pattern. 99 | // NOTE: To change the log level for VLOG(_IS_ON) sites 100 | // that have already executed after/during InitGoogleLogging, 101 | // one needs to supply the exact --vmodule pattern that applied to them. 102 | // (If no --vmodule pattern applied to them 103 | // the value of FLAGS_v will continue to control them.) 104 | extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern, 105 | int log_level); 106 | 107 | // Various declarations needed for VLOG_IS_ON above: ========================= 108 | 109 | // Special value used to indicate that a VLOG_IS_ON site has not been 110 | // initialized. We make this a large value, so the common-case check 111 | // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition 112 | // passes in such cases and InitVLOG3__ is then triggered. 113 | extern google::int32 kLogSiteUninitialized; 114 | 115 | // Helper routine which determines the logging info for a particalur VLOG site. 116 | // site_flag is the address of the site-local pointer to the controlling 117 | // verbosity level 118 | // site_default is the default to use for *site_flag 119 | // fname is the current source file name 120 | // verbose_level is the argument to VLOG_IS_ON 121 | // We will return the return value for VLOG_IS_ON 122 | // and if possible set *site_flag appropriately. 123 | extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__( 124 | google::int32** site_flag, 125 | google::int32* site_default, 126 | const char* fname, 127 | google::int32 verbose_level); 128 | 129 | #endif // BASE_VLOG_IS_ON_H_ 130 | -------------------------------------------------------------------------------- /include/json/json-forwards.h: -------------------------------------------------------------------------------- 1 | /// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/). 2 | /// It is intended to be used with #include "json/json-forwards.h" 3 | /// This header provides forward declaration for all JsonCpp types. 4 | 5 | // ////////////////////////////////////////////////////////////////////// 6 | // Beginning of content of file: LICENSE 7 | // ////////////////////////////////////////////////////////////////////// 8 | 9 | /* 10 | The JsonCpp library's source code, including accompanying documentation, 11 | tests and demonstration applications, are licensed under the following 12 | conditions... 13 | 14 | The JsonCpp Authors explicitly disclaim copyright in all 15 | jurisdictions which recognize such a disclaimer. In such jurisdictions, 16 | this software is released into the Public Domain. 17 | 18 | In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 19 | 2010), this software is Copyright (c) 2007-2010 by The JsonCpp Authors, and is 20 | released under the terms of the MIT License (see below). 21 | 22 | In jurisdictions which recognize Public Domain property, the user of this 23 | software may choose to accept it either as 1) Public Domain, 2) under the 24 | conditions of the MIT License (see below), or 3) under the terms of dual 25 | Public Domain/MIT License conditions described here, as they choose. 26 | 27 | The MIT License is about as close to Public Domain as a license can get, and is 28 | described in clear, concise terms at: 29 | 30 | http://en.wikipedia.org/wiki/MIT_License 31 | 32 | The full text of the MIT License follows: 33 | 34 | ======================================================================== 35 | Copyright (c) 2007-2010 The JsonCpp Authors 36 | 37 | Permission is hereby granted, free of charge, to any person 38 | obtaining a copy of this software and associated documentation 39 | files (the "Software"), to deal in the Software without 40 | restriction, including without limitation the rights to use, copy, 41 | modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be 46 | included in all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 49 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 50 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 51 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 52 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 53 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 54 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | ======================================================================== 57 | (END LICENSE TEXT) 58 | 59 | The MIT license is compatible with both the GPL and commercial 60 | software, affording one all of the rights of Public Domain with the 61 | minor nuisance of being required to keep the above copyright notice 62 | and license text in the source code. Note also that by accepting the 63 | Public Domain "license" you can re-license your copy using whatever 64 | license you like. 65 | 66 | */ 67 | 68 | // ////////////////////////////////////////////////////////////////////// 69 | // End of content of file: LICENSE 70 | // ////////////////////////////////////////////////////////////////////// 71 | 72 | 73 | 74 | 75 | 76 | #ifndef JSON_FORWARD_AMALGATED_H_INCLUDED 77 | # define JSON_FORWARD_AMALGATED_H_INCLUDED 78 | /// If defined, indicates that the source file is amalgated 79 | /// to prevent private header inclusion. 80 | #define JSON_IS_AMALGAMATION 81 | 82 | // ////////////////////////////////////////////////////////////////////// 83 | // Beginning of content of file: include/json/config.h 84 | // ////////////////////////////////////////////////////////////////////// 85 | 86 | // Copyright 2007-2010 Baptiste Lepilleur 87 | // Distributed under MIT license, or public domain if desired and 88 | // recognized in your jurisdiction. 89 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 90 | 91 | #ifndef JSON_CONFIG_H_INCLUDED 92 | #define JSON_CONFIG_H_INCLUDED 93 | #include 94 | #include //typedef String 95 | #include //typedef int64_t, uint64_t 96 | 97 | /// If defined, indicates that json library is embedded in CppTL library. 98 | //# define JSON_IN_CPPTL 1 99 | 100 | /// If defined, indicates that json may leverage CppTL library 101 | //# define JSON_USE_CPPTL 1 102 | /// If defined, indicates that cpptl vector based map should be used instead of 103 | /// std::map 104 | /// as Value container. 105 | //# define JSON_USE_CPPTL_SMALLMAP 1 106 | 107 | // If non-zero, the library uses exceptions to report bad input instead of C 108 | // assertion macros. The default is to use exceptions. 109 | #ifndef JSON_USE_EXCEPTION 110 | #define JSON_USE_EXCEPTION 1 111 | #endif 112 | 113 | /// If defined, indicates that the source file is amalgated 114 | /// to prevent private header inclusion. 115 | /// Remarks: it is automatically defined in the generated amalgated header. 116 | // #define JSON_IS_AMALGAMATION 117 | 118 | #ifdef JSON_IN_CPPTL 119 | #include 120 | #ifndef JSON_USE_CPPTL 121 | #define JSON_USE_CPPTL 1 122 | #endif 123 | #endif 124 | 125 | #ifdef JSON_IN_CPPTL 126 | #define JSON_API CPPTL_API 127 | #elif defined(JSON_DLL_BUILD) 128 | #if defined(_MSC_VER) || defined(__MINGW32__) 129 | #define JSON_API __declspec(dllexport) 130 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 131 | #endif // if defined(_MSC_VER) 132 | #elif defined(JSON_DLL) 133 | #if defined(_MSC_VER) || defined(__MINGW32__) 134 | #define JSON_API __declspec(dllimport) 135 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 136 | #endif // if defined(_MSC_VER) 137 | #endif // ifdef JSON_IN_CPPTL 138 | #if !defined(JSON_API) 139 | #define JSON_API 140 | #endif 141 | 142 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 143 | // integer 144 | // Storages, and 64 bits integer support is disabled. 145 | // #define JSON_NO_INT64 1 146 | 147 | #if defined(_MSC_VER) // MSVC 148 | # if _MSC_VER <= 1200 // MSVC 6 149 | // Microsoft Visual Studio 6 only support conversion from __int64 to double 150 | // (no conversion from unsigned __int64). 151 | # define JSON_USE_INT64_DOUBLE_CONVERSION 1 152 | // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255' 153 | // characters in the debug information) 154 | // All projects I've ever seen with VS6 were using this globally (not bothering 155 | // with pragma push/pop). 156 | # pragma warning(disable : 4786) 157 | # endif // MSVC 6 158 | 159 | # if _MSC_VER >= 1500 // MSVC 2008 160 | /// Indicates that the following function is deprecated. 161 | # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 162 | # endif 163 | 164 | #endif // defined(_MSC_VER) 165 | 166 | // In c++11 the override keyword allows you to explicity define that a function 167 | // is intended to override the base-class version. This makes the code more 168 | // managable and fixes a set of common hard-to-find bugs. 169 | #if __cplusplus >= 201103L 170 | # define JSONCPP_OVERRIDE override 171 | # define JSONCPP_NOEXCEPT noexcept 172 | #elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900 173 | # define JSONCPP_OVERRIDE override 174 | # define JSONCPP_NOEXCEPT throw() 175 | #elif defined(_MSC_VER) && _MSC_VER >= 1900 176 | # define JSONCPP_OVERRIDE override 177 | # define JSONCPP_NOEXCEPT noexcept 178 | #else 179 | # define JSONCPP_OVERRIDE 180 | # define JSONCPP_NOEXCEPT throw() 181 | #endif 182 | 183 | #ifndef JSON_HAS_RVALUE_REFERENCES 184 | 185 | #if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010 186 | #define JSON_HAS_RVALUE_REFERENCES 1 187 | #endif // MSVC >= 2010 188 | 189 | #ifdef __clang__ 190 | #if __has_feature(cxx_rvalue_references) 191 | #define JSON_HAS_RVALUE_REFERENCES 1 192 | #endif // has_feature 193 | 194 | #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 195 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L) 196 | #define JSON_HAS_RVALUE_REFERENCES 1 197 | #endif // GXX_EXPERIMENTAL 198 | 199 | #endif // __clang__ || __GNUC__ 200 | 201 | #endif // not defined JSON_HAS_RVALUE_REFERENCES 202 | 203 | #ifndef JSON_HAS_RVALUE_REFERENCES 204 | #define JSON_HAS_RVALUE_REFERENCES 0 205 | #endif 206 | 207 | #ifdef __clang__ 208 | #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 209 | # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 210 | # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 211 | # elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 212 | # define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) 213 | # endif // GNUC version 214 | #endif // __clang__ || __GNUC__ 215 | 216 | #if !defined(JSONCPP_DEPRECATED) 217 | #define JSONCPP_DEPRECATED(message) 218 | #endif // if !defined(JSONCPP_DEPRECATED) 219 | 220 | #if __GNUC__ >= 6 221 | # define JSON_USE_INT64_DOUBLE_CONVERSION 1 222 | #endif 223 | 224 | #if !defined(JSON_IS_AMALGAMATION) 225 | 226 | # include "version.h" 227 | 228 | # if JSONCPP_USING_SECURE_MEMORY 229 | # include "allocator.h" //typedef Allocator 230 | # endif 231 | 232 | #endif // if !defined(JSON_IS_AMALGAMATION) 233 | 234 | namespace Json { 235 | typedef int Int; 236 | typedef unsigned int UInt; 237 | #if defined(JSON_NO_INT64) 238 | typedef int LargestInt; 239 | typedef unsigned int LargestUInt; 240 | #undef JSON_HAS_INT64 241 | #else // if defined(JSON_NO_INT64) 242 | // For Microsoft Visual use specific types as long long is not supported 243 | #if defined(_MSC_VER) // Microsoft Visual Studio 244 | typedef __int64 Int64; 245 | typedef unsigned __int64 UInt64; 246 | #else // if defined(_MSC_VER) // Other platforms, use long long 247 | typedef int64_t Int64; 248 | typedef uint64_t UInt64; 249 | #endif // if defined(_MSC_VER) 250 | typedef Int64 LargestInt; 251 | typedef UInt64 LargestUInt; 252 | #define JSON_HAS_INT64 253 | #endif // if defined(JSON_NO_INT64) 254 | #if JSONCPP_USING_SECURE_MEMORY 255 | #define JSONCPP_STRING std::basic_string, Json::SecureAllocator > 256 | #define JSONCPP_OSTRINGSTREAM std::basic_ostringstream, Json::SecureAllocator > 257 | #define JSONCPP_OSTREAM std::basic_ostream> 258 | #define JSONCPP_ISTRINGSTREAM std::basic_istringstream, Json::SecureAllocator > 259 | #define JSONCPP_ISTREAM std::istream 260 | #else 261 | #define JSONCPP_STRING std::string 262 | #define JSONCPP_OSTRINGSTREAM std::ostringstream 263 | #define JSONCPP_OSTREAM std::ostream 264 | #define JSONCPP_ISTRINGSTREAM std::istringstream 265 | #define JSONCPP_ISTREAM std::istream 266 | #endif // if JSONCPP_USING_SECURE_MEMORY 267 | } // end namespace Json 268 | 269 | #endif // JSON_CONFIG_H_INCLUDED 270 | 271 | // ////////////////////////////////////////////////////////////////////// 272 | // End of content of file: include/json/config.h 273 | // ////////////////////////////////////////////////////////////////////// 274 | 275 | 276 | 277 | 278 | 279 | 280 | // ////////////////////////////////////////////////////////////////////// 281 | // Beginning of content of file: include/json/forwards.h 282 | // ////////////////////////////////////////////////////////////////////// 283 | 284 | // Copyright 2007-2010 Baptiste Lepilleur 285 | // Distributed under MIT license, or public domain if desired and 286 | // recognized in your jurisdiction. 287 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 288 | 289 | #ifndef JSON_FORWARDS_H_INCLUDED 290 | #define JSON_FORWARDS_H_INCLUDED 291 | 292 | #if !defined(JSON_IS_AMALGAMATION) 293 | #include "config.h" 294 | #endif // if !defined(JSON_IS_AMALGAMATION) 295 | 296 | namespace Json { 297 | 298 | // writer.h 299 | class FastWriter; 300 | class StyledWriter; 301 | 302 | // reader.h 303 | class Reader; 304 | 305 | // features.h 306 | class Features; 307 | 308 | // value.h 309 | typedef unsigned int ArrayIndex; 310 | class StaticString; 311 | class Path; 312 | class PathArgument; 313 | class Value; 314 | class ValueIteratorBase; 315 | class ValueIterator; 316 | class ValueConstIterator; 317 | 318 | } // namespace Json 319 | 320 | #endif // JSON_FORWARDS_H_INCLUDED 321 | 322 | // ////////////////////////////////////////////////////////////////////// 323 | // End of content of file: include/json/forwards.h 324 | // ////////////////////////////////////////////////////////////////////// 325 | 326 | 327 | 328 | 329 | 330 | #endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED 331 | -------------------------------------------------------------------------------- /include/lapacke_config.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (c) 2010, Intel Corp. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of Intel Corporation nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | THE POSSIBILITY OF SUCH DAMAGE. 28 | ****************************************************************************** 29 | * Contents: Native C interface to LAPACK 30 | * Author: Intel Corporation 31 | * Generated May, 2011 32 | *****************************************************************************/ 33 | 34 | #ifndef _LAPACKE_CONFIG_H_ 35 | #define _LAPACKE_CONFIG_H_ 36 | 37 | #ifdef __cplusplus 38 | #if defined(LAPACK_COMPLEX_CPP) 39 | #include 40 | #endif 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | #include 45 | 46 | #ifndef lapack_int 47 | #if defined(LAPACK_ILP64) 48 | #define lapack_int long 49 | #else 50 | #define lapack_int int 51 | #endif 52 | #endif 53 | 54 | #ifndef lapack_logical 55 | #define lapack_logical lapack_int 56 | #endif 57 | 58 | #ifndef LAPACK_COMPLEX_CUSTOM 59 | 60 | #if defined(LAPACK_COMPLEX_STRUCTURE) 61 | 62 | typedef struct { float real, imag; } _lapack_complex_float; 63 | typedef struct { double real, imag; } _lapack_complex_double; 64 | #define lapack_complex_float _lapack_complex_float 65 | #define lapack_complex_double _lapack_complex_double 66 | #define lapack_complex_float_real(z) ((z).real) 67 | #define lapack_complex_float_imag(z) ((z).imag) 68 | #define lapack_complex_double_real(z) ((z).real) 69 | #define lapack_complex_double_imag(z) ((z).imag) 70 | 71 | #elif defined(LAPACK_COMPLEX_C99) 72 | 73 | #include 74 | #define lapack_complex_float float _Complex 75 | #define lapack_complex_double double _Complex 76 | #define lapack_complex_float_real(z) (creal(z)) 77 | #define lapack_complex_float_imag(z) (cimag(z)) 78 | #define lapack_complex_double_real(z) (creal(z)) 79 | #define lapack_complex_double_imag(z) (cimag(z)) 80 | 81 | #elif defined(LAPACK_COMPLEX_CPP) 82 | 83 | #define lapack_complex_float std::complex 84 | #define lapack_complex_double std::complex 85 | #define lapack_complex_float_real(z) ((z).real()) 86 | #define lapack_complex_float_imag(z) ((z).imag()) 87 | #define lapack_complex_double_real(z) ((z).real()) 88 | #define lapack_complex_double_imag(z) ((z).imag()) 89 | 90 | #else 91 | 92 | #include 93 | #define lapack_complex_float float _Complex 94 | #define lapack_complex_double double _Complex 95 | #define lapack_complex_float_real(z) (creal(z)) 96 | #define lapack_complex_float_imag(z) (cimag(z)) 97 | #define lapack_complex_double_real(z) (creal(z)) 98 | #define lapack_complex_double_imag(z) (cimag(z)) 99 | 100 | #endif 101 | 102 | lapack_complex_float lapack_make_complex_float( float re, float im ); 103 | lapack_complex_double lapack_make_complex_double( double re, double im ); 104 | 105 | #endif 106 | 107 | #ifndef LAPACK_malloc 108 | #define LAPACK_malloc( size ) malloc( size ) 109 | #endif 110 | 111 | #ifndef LAPACK_free 112 | #define LAPACK_free( p ) free( p ) 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif /* __cplusplus */ 118 | 119 | #endif /* _LAPACKE_CONFIG_H_ */ 120 | -------------------------------------------------------------------------------- /include/lapacke_mangling.h: -------------------------------------------------------------------------------- 1 | #ifndef LAPACK_HEADER_INCLUDED 2 | #define LAPACK_HEADER_INCLUDED 3 | 4 | #ifndef LAPACK_GLOBAL 5 | #if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_) 6 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 7 | #elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER) 8 | #define LAPACK_GLOBAL(lcname,UCNAME) UCNAME 9 | #elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE) 10 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname 11 | #else 12 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 13 | #endif 14 | #endif 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /include/lock.h: -------------------------------------------------------------------------------- 1 | #ifndef _LOCK_H 2 | #define _LOCK_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef _WIN32 8 | #include 9 | #include 10 | #else //for linux 11 | #define INFINITE 0x7FFFFFFF 12 | #include 13 | #include 14 | #include 15 | #include 16 | #endif 17 | using namespace std; 18 | 19 | /************************************************************************/ 20 | /* Locker Class */ 21 | /************************************************************************/ 22 | class Locker 23 | { 24 | public: 25 | Locker(void); 26 | ~Locker(void); 27 | 28 | public: 29 | void Lock(); 30 | void Unlock(); 31 | 32 | private: 33 | #ifdef _WIN32 34 | CRITICAL_SECTION m_oCriticalSection; 35 | #else //for linux 36 | pthread_mutex_t mutex; 37 | #endif 38 | }; 39 | 40 | /************************************************************************/ 41 | /* Single lock class */ 42 | /************************************************************************/ 43 | class ScopeLocker 44 | { 45 | public: 46 | ScopeLocker(Locker* pLocker); 47 | ~ScopeLocker(void); 48 | 49 | private: 50 | ScopeLocker(void); 51 | 52 | private: 53 | Locker* m_pLocker; 54 | 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/mtcnn.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MTCNN_HPP__ 2 | #define __MTCNN_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include "ai_type.h" 8 | #include 9 | 10 | 11 | struct face_landmark 12 | { 13 | float x[5]; 14 | float y[5]; 15 | }; 16 | 17 | struct face_box 18 | { 19 | float x0; 20 | float y0; 21 | float x1; 22 | float y1; 23 | 24 | /* confidence score */ 25 | float score; 26 | 27 | /*regression scale */ 28 | 29 | float regress[4]; 30 | 31 | /* padding stuff*/ 32 | float px0; 33 | float py0; 34 | float px1; 35 | float py1; 36 | 37 | face_landmark landmark; 38 | }; 39 | 40 | 41 | 42 | class mtcnn { 43 | public: 44 | mtcnn(void){ 45 | min_size_=40; 46 | pnet_threshold_=0.6; 47 | rnet_threshold_=0.7; 48 | onet_threshold_=0.9; 49 | factor_=0.709; 50 | alg_type = TENGINE; 51 | 52 | } 53 | 54 | void set_threshold(float p, float r, float o) 55 | { 56 | pnet_threshold_=p; 57 | rnet_threshold_=r; 58 | onet_threshold_=o; 59 | } 60 | 61 | void set_factor_min_size(float factor, float min_size) 62 | { 63 | factor_=factor; 64 | min_size_=min_size; 65 | } 66 | 67 | 68 | void set_AI_type(ALG_TYPE _alg_type) 69 | { 70 | alg_type=_alg_type; 71 | } 72 | 73 | 74 | virtual int load_3model(const std::string& model_dir)=0; 75 | virtual void detect(cv::Mat& img, std::vector& face_list)=0; 76 | virtual ~mtcnn(void){}; 77 | 78 | protected: 79 | 80 | int min_size_; 81 | float pnet_threshold_; 82 | float rnet_threshold_; 83 | float onet_threshold_; 84 | float factor_; 85 | ALG_TYPE alg_type; 86 | 87 | }; 88 | 89 | /* factory part */ 90 | 91 | class mtcnn_factory 92 | { 93 | public: 94 | 95 | typedef mtcnn * (*creator)(void); 96 | 97 | static void register_creator(const std::string& name, creator& create_func); 98 | static mtcnn * create_detector(const std::string& name); 99 | static std::vector list(void); 100 | 101 | private: 102 | mtcnn_factory(){}; 103 | 104 | 105 | }; 106 | 107 | class only_for_auto_register 108 | { 109 | public: 110 | only_for_auto_register(std::string name, mtcnn_factory::creator func) 111 | { 112 | mtcnn_factory::register_creator(name,func); 113 | } 114 | 115 | }; 116 | 117 | #define REGISTER_MTCNN_CREATOR(name,func) \ 118 | static only_for_auto_register dummy_mtcnn_creator_## name (#name, func) 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /include/mxnet_mtcnn.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MXNET_MTCNN_HPP__ 2 | #define __MXNET_MTCNN_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include "mtcnn.hpp" 8 | #include "mxnet/c_predict_api.h" 9 | #include "comm_lib.hpp" 10 | 11 | class mxnet_mtcnn: public mtcnn { 12 | 13 | public: 14 | mxnet_mtcnn():rnet_batch_bound_(10),onet_batch_bound_(10){}; 15 | 16 | int load_model(const std::string& model_dir); 17 | 18 | void detect(cv::Mat& img, std::vector& face_list); 19 | 20 | void set_batch_mode_bound(int r, int o) 21 | { 22 | rnet_batch_bound_=r; 23 | onet_batch_bound_=o; 24 | } 25 | 26 | ~mxnet_mtcnn(); 27 | 28 | protected: 29 | 30 | void load_PNet(int h, int w); 31 | void free_PNet(void); 32 | 33 | void copy_one_patch(const cv::Mat& img,face_box&input_box,float * data_to, int width, int height); 34 | PredictorHandle load_RNet(int batch); 35 | PredictorHandle load_ONet(int batch); 36 | 37 | 38 | PredictorHandle load_mxnet_model(const std::string& param_file, const std::string& json_file, 39 | int batch, int channel,int input_h, int input_w); 40 | 41 | void run_PNet(const cv::Mat& img, scale_window& win, std::vector& box_list); 42 | 43 | int run_preload_RNet(const cv::Mat& img, face_box& input_box, face_box& output_box); 44 | int run_preload_ONet(const cv::Mat& img, face_box&input_box, face_box& output_box); 45 | 46 | void run_RNet(const cv::Mat& img,std::vector& pnet_boxes, std::vector& output_boxes); 47 | void run_ONet(const cv::Mat& img,std::vector& rnet_boxes, std::vector& output_boxes); 48 | 49 | 50 | private: 51 | 52 | std::string model_dir_; 53 | PredictorHandle PNet_; //PNet_ will create and destroyed frequently 54 | PredictorHandle RNet_; 55 | PredictorHandle ONet_; 56 | int rnet_batch_bound_; 57 | int onet_batch_bound_; 58 | 59 | }; 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/my_head.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_HEAD_H 2 | #define MY_HEAD_H 3 | 4 | // caffe 5 | #include 6 | 7 | // c++ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // opencv 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | // boost 25 | #include 26 | 27 | 28 | // matlab2c++ 29 | //#include 30 | //#include 31 | //#include 32 | //#include 33 | //#include "libmTransform.h" 34 | 35 | #endif -------------------------------------------------------------------------------- /include/network_shell.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __NETWORK_SHELL_HPP__ 2 | #define __NETWORK_SHELL_HPP__ 3 | 4 | #include 5 | 6 | 7 | void init_network_shell(void); 8 | 9 | typedef void (*net_shell_cmd_t)(int, char ** arg); 10 | 11 | /* the generate msg will be formate as: sprintf("%-32s%s",name,help_msg) */ 12 | 13 | int register_network_shell_cmd(const std::string& name, net_shell_cmd_t func,const std::string&cmd_line, const std::string& help_msg); 14 | 15 | /* 16 | let run_network_shell quit. 17 | in_shell -- 0 18 | a blocking function: when it returns, all created threads have terminated and resources are released 19 | in_shell --- 1 20 | this function is called in the same thread that shell runs. It is an async function: 21 | a new thread will be created to execute the block parts. 22 | */ 23 | 24 | void quit_network_shell(int in_shell); 25 | 26 | /* a dead loop to handle user input and to execute registered commands */ 27 | 28 | int run_network_shell(const char * prompt,int port); 29 | 30 | 31 | /* create a thread inside ...*/ 32 | int create_network_shell_thread(const char * prompt,int port); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/openblas_config.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENBLAS_CONFIG_H 2 | #define OPENBLAS_CONFIG_H 3 | #define OPENBLAS_OS_ANDROID 1 4 | #define OPENBLAS_ARCH_ARM64 1 5 | #define OPENBLAS_C_GCC 1 6 | #define OPENBLAS___64BIT__ 1 7 | #define OPENBLAS_PTHREAD_CREATE_FUNC pthread_create 8 | #define OPENBLAS_BUNDERSCORE _ 9 | #define OPENBLAS_NEEDBUNDERSCORE 1 10 | #define OPENBLAS_CORTEXA57 11 | #define OPENBLAS_L1_CODE_SIZE 49152 12 | #define OPENBLAS_L1_CODE_LINESIZE 64 13 | #define OPENBLAS_L1_CODE_ASSOCIATIVE 3 14 | #define OPENBLAS_L1_DATA_SIZE 32768 15 | #define OPENBLAS_L1_DATA_LINESIZE 64 16 | #define OPENBLAS_L1_DATA_ASSOCIATIVE 2 17 | #define OPENBLAS_L2_SIZE 2097152 18 | #define OPENBLAS_L2_LINESIZE 64 19 | #define OPENBLAS_L2_ASSOCIATIVE 16 20 | #define OPENBLAS_DTB_DEFAULT_ENTRIES 64 21 | #define OPENBLAS_DTB_SIZE 4096 22 | #define OPENBLAS_HAVE_VFPV4 23 | #define OPENBLAS_HAVE_VFPV3 24 | #define OPENBLAS_HAVE_VFP 25 | #define OPENBLAS_HAVE_NEON 26 | #define OPENBLAS_CORE_CORTEXA57 27 | #define OPENBLAS_CHAR_CORENAME "CORTEXA57" 28 | #define OPENBLAS_GEMM_MULTITHREAD_THRESHOLD 4 29 | #define OPENBLAS_VERSION " OpenBLAS 0.2.20 " 30 | /*This is only for "make install" target.*/ 31 | 32 | #if defined(OPENBLAS_OS_WINNT) || defined(OPENBLAS_OS_CYGWIN_NT) || defined(OPENBLAS_OS_INTERIX) 33 | #define OPENBLAS_WINDOWS_ABI 34 | #define OPENBLAS_OS_WINDOWS 35 | 36 | #ifdef DOUBLE 37 | #define DOUBLE_DEFINED DOUBLE 38 | #undef DOUBLE 39 | #endif 40 | #endif 41 | 42 | #ifdef OPENBLAS_NEEDBUNDERSCORE 43 | #define BLASFUNC(FUNC) FUNC##_ 44 | #else 45 | #define BLASFUNC(FUNC) FUNC 46 | #endif 47 | 48 | #ifdef OPENBLAS_QUAD_PRECISION 49 | typedef struct { 50 | unsigned long x[2]; 51 | } xdouble; 52 | #elif defined OPENBLAS_EXPRECISION 53 | #define xdouble long double 54 | #else 55 | #define xdouble double 56 | #endif 57 | 58 | #if defined(OPENBLAS_OS_WINDOWS) && defined(OPENBLAS___64BIT__) 59 | typedef long long BLASLONG; 60 | typedef unsigned long long BLASULONG; 61 | #else 62 | typedef long BLASLONG; 63 | typedef unsigned long BLASULONG; 64 | #endif 65 | 66 | #ifdef OPENBLAS_USE64BITINT 67 | typedef BLASLONG blasint; 68 | #else 69 | typedef int blasint; 70 | #endif 71 | 72 | #if defined(XDOUBLE) || defined(DOUBLE) 73 | #define FLOATRET FLOAT 74 | #else 75 | #ifdef NEED_F2CCONV 76 | #define FLOATRET double 77 | #else 78 | #define FLOATRET float 79 | #endif 80 | #endif 81 | 82 | /* Inclusion of a standard header file is needed for definition of __STDC_* 83 | predefined macros with some compilers (e.g. GCC 4.7 on Linux). This occurs 84 | as a side effect of including either or . */ 85 | #include 86 | 87 | /* C99 supports complex floating numbers natively, which GCC also offers as an 88 | extension since version 3.0. If neither are available, use a compatible 89 | structure as fallback (see Clause 6.2.5.13 of the C99 standard). */ 90 | #if ((defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || \ 91 | (__GNUC__ >= 3 && !defined(__cplusplus))) && !(defined(FORCE_OPENBLAS_COMPLEX_STRUCT))) 92 | #define OPENBLAS_COMPLEX_C99 93 | #ifndef __cplusplus 94 | #include 95 | #endif 96 | typedef float _Complex openblas_complex_float; 97 | typedef double _Complex openblas_complex_double; 98 | typedef xdouble _Complex openblas_complex_xdouble; 99 | #define openblas_make_complex_float(real, imag) ((real) + ((imag) * _Complex_I)) 100 | #define openblas_make_complex_double(real, imag) ((real) + ((imag) * _Complex_I)) 101 | #define openblas_make_complex_xdouble(real, imag) ((real) + ((imag) * _Complex_I)) 102 | #define openblas_complex_float_real(z) (creal(z)) 103 | #define openblas_complex_float_imag(z) (cimag(z)) 104 | #define openblas_complex_double_real(z) (creal(z)) 105 | #define openblas_complex_double_imag(z) (cimag(z)) 106 | #define openblas_complex_xdouble_real(z) (creal(z)) 107 | #define openblas_complex_xdouble_imag(z) (cimag(z)) 108 | #else 109 | #define OPENBLAS_COMPLEX_STRUCT 110 | typedef struct { float real, imag; } openblas_complex_float; 111 | typedef struct { double real, imag; } openblas_complex_double; 112 | typedef struct { xdouble real, imag; } openblas_complex_xdouble; 113 | #define openblas_make_complex_float(real, imag) {(real), (imag)} 114 | #define openblas_make_complex_double(real, imag) {(real), (imag)} 115 | #define openblas_make_complex_xdouble(real, imag) {(real), (imag)} 116 | #define openblas_complex_float_real(z) ((z).real) 117 | #define openblas_complex_float_imag(z) ((z).imag) 118 | #define openblas_complex_double_real(z) ((z).real) 119 | #define openblas_complex_double_imag(z) ((z).imag) 120 | #define openblas_complex_xdouble_real(z) ((z).real) 121 | #define openblas_complex_xdouble_imag(z) ((z).imag) 122 | #endif 123 | #endif /* OPENBLAS_CONFIG_H */ 124 | -------------------------------------------------------------------------------- /include/preprocess.h: -------------------------------------------------------------------------------- 1 | #ifndef Preprocess_H11 2 | #define Preprocess_H11 3 | 4 | #include 5 | 6 | using namespace cv; 7 | typedef struct FaceBaseInfo { 8 | Rect bbox; 9 | Point2f eyeleft; 10 | Point2f eyeright; 11 | Point2f nose; 12 | Point2f mouthleft; 13 | Point2f mouthright; 14 | } FaceBaseInfo; 15 | int preprocess(Mat& img, FaceBaseInfo& f, Size objsize, Mat& d1); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/recognition.h: -------------------------------------------------------------------------------- 1 | #ifndef RECOGNITION_H 2 | #define RECOGNITION_H 3 | 4 | #include "my_head.h" 5 | using namespace caffe; 6 | using std::string; 7 | 8 | class Classifier { 9 | public: 10 | Classifier(); 11 | ~Classifier(); 12 | void LoadModel(const string& model_file, const string& trained_file); 13 | std::vector Classify(const cv::Mat& img1); 14 | 15 | private: 16 | std::vector Predict(const cv::Mat& img); 17 | 18 | 19 | private: 20 | Net * net_; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/scale_angle.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCALE_ANGLE_H__ 2 | #define __SCALE_ANGLE_H__ 3 | 4 | extern int cal_scale_and_angle(float * landmark, int landmark_number, int desired_width, int desired_height,float * scale, float * angle); 5 | extern int dsvd(float a[][2], int m, int n, float *w, float v[][2]); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/telnet_buf.h: -------------------------------------------------------------------------------- 1 | #ifndef __TELNET_BUF_H__ 2 | #define __TELNET_BUF_H__ 3 | 4 | /* get the data removed IAC commands, return parsed data length*/ 5 | int get_parsed_data(char * output, int output_len); 6 | 7 | /* the maximum data one time can save to parser buf */ 8 | int get_max_data_batch_len(void); 9 | 10 | /* save the data receiving from network to parser buffer */ 11 | void save_data_to_buffer(char * data, int len); 12 | 13 | /* get the initial setting command */ 14 | 15 | const char * get_init_cmd_buf(void); 16 | int get_init_cmd_len(void); 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/tensorflow_mtcnn.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TENSORFLOW_MTCNN_HPP__ 2 | #define __TENSORFLOW_MTCNN_HPP__ 3 | 4 | #include "tensorflow/c/c_api.h" 5 | #include "mtcnn.hpp" 6 | #include "comm_lib.hpp" 7 | 8 | class tf_mtcnn: public mtcnn { 9 | 10 | public: 11 | tf_mtcnn()=default; 12 | 13 | int load_model(const std::string& model_dir); 14 | 15 | void detect(cv::Mat& img, std::vector& face_list); 16 | 17 | ~tf_mtcnn(); 18 | 19 | 20 | protected: 21 | 22 | 23 | void run_PNet(const cv::Mat& img, scale_window& win, std::vector& box_list); 24 | 25 | 26 | void run_RNet(const cv::Mat& img,std::vector& pnet_boxes, std::vector& output_boxes); 27 | void run_ONet(const cv::Mat& img,std::vector& rnet_boxes, std::vector& output_boxes); 28 | private: 29 | 30 | TF_Session * sess_; 31 | TF_Graph * graph_; 32 | 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: Thread.h 3 | * Author: Null 4 | */ 5 | 6 | /* 7 | * 在编译的时候记得加上参数:-lpthread 8 | * 9 | */ 10 | 11 | #ifndef _THREAD_H 12 | #define _THREAD_H 13 | 14 | 15 | #include 16 | #include 17 | 18 | class Thread 19 | { 20 | private: 21 | //当前线程的线程ID 22 | pthread_t tid; 23 | //线程的状态 24 | int threadStatus; 25 | //获取执行方法的指针 26 | static void* run0(void* pVoid); 27 | //内部执行方法 28 | void* run1(); 29 | public: 30 | //线程的状态-新建 31 | static const int THREAD_STATUS_NEW = 0; 32 | //线程的状态-正在运行 33 | static const int THREAD_STATUS_RUNNING = 1; 34 | //线程的状态-运行结束 35 | static const int THREAD_STATUS_EXIT = -1; 36 | //构造函数 37 | Thread(); 38 | //线程的运行实体 39 | virtual void run() = 0; 40 | //开始执行线程 41 | bool start(); 42 | //获取线程ID 43 | pthread_t getThreadID(); 44 | //获取线程状态 45 | int getState(); 46 | //等待线程直至退出 47 | void join(); 48 | //等待线程退出或者超时 49 | void join(unsigned long millisTime); 50 | }; 51 | 52 | 53 | #endif /* _THREAD_H */ 54 | 55 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_H 2 | #define _UTIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef _WIN32 //Windows 9 | #include 10 | #include 11 | #include 12 | #include 13 | #else //Linux 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #endif 29 | 30 | #include 31 | 32 | using namespace std; 33 | 34 | class Util 35 | { 36 | public: 37 | static string Uint2String(unsigned int value); 38 | static string Int2String(int value); 39 | static string Ulint2String( unsigned long long value); 40 | static string Lint2String(long long value); 41 | static int String2Int(const string& value); 42 | static unsigned int String2Uint(const string& value); 43 | static long long String2Lint(const string& value); 44 | static unsigned long long String2Ulint(const string& value); 45 | static string Double2String(double value, int length); 46 | static double String2Double(const string& value); 47 | static const string Trim(const string& value); 48 | static vector Split( const string& src, const string& split); 49 | 50 | static bool IsFileExist(const string& strPath); //判断文件和目录是否存在 51 | static bool CreateDir(const string& strDirectory); //创建目录 52 | static long long GetFileSize(FILE* fStream); //获取文件大小 53 | static long long GetFileSize(const char* strFile); //获取文件大小 54 | static vector GetFileList(const string& strDir, const string& strExtension ); 55 | static vector GetFileListByName(const string& strDir, const string& strFileName); 56 | static bool GetCurWorkDir(string& strCurWorkDir); 57 | static string GetRootDir(); 58 | static string GetFileDir(const string& strFilePath); 59 | static bool DeleteDir(const string& strDir); 60 | static bool DeleteFile(const string& strFile); 61 | 62 | static int16_t Net2Host16(int16_t net16); 63 | static int16_t Host2Net16(int16_t host16); 64 | static int32_t Net2Host32(int32_t net32); 65 | static int32_t Host2Net32(int32_t host32); 66 | static int64_t Net2Host64(int64_t net64); 67 | static int64_t Host2Net64(int64_t host64); 68 | 69 | static bool KillProcess(int32_t process_id); 70 | static void Wait(int64_t mill_second); 71 | static long GetCurrentThreadID(); 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /include/utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MTCNN_UTILS_HPP__ 2 | #define __MTCNN_UTILS_HPP__ 3 | 4 | /* get current time: in us */ 5 | unsigned long get_cur_time(void); 6 | 7 | /* 8 | for debug purpose, to save a image or float vector to file. 9 | the image should be in cv::Mat. 10 | To avoid OpenCV header file dependency, use void * instead of cv::Mat * 11 | */ 12 | 13 | 14 | void save_img(const char * name,void * p_img ); 15 | 16 | void save_float(const char * name, const float * data, int size); 17 | 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "config.h" 16 | #include "util.h" 17 | 18 | 19 | #define CONFIG_FILE_PATH "demo.conf" 20 | 21 | using namespace std; 22 | using namespace cv; 23 | 24 | 25 | void bindToCpu(int cpu1, int cpu2) 26 | { 27 | 28 | cpu_set_t mask; 29 | CPU_ZERO(&mask); 30 | //CPU_SET(cpu,&mask); 31 | CPU_SET(cpu1, &mask); 32 | CPU_SET(cpu2, &mask); 33 | 34 | if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) { 35 | fprintf(stderr, "set thread affinity failed\n"); 36 | } 37 | 38 | } 39 | 40 | void _strlwr_d(char* src) 41 | { 42 | while (*src != '\0') 43 | { 44 | if (*src >= 'A' && *src <= 'Z') 45 | { 46 | *src += 32; 47 | } 48 | src++; 49 | } 50 | } 51 | 52 | 53 | int main(int argc, char * argv[]) 54 | { 55 | if(!Config::Instance()->LoadConfig(CONFIG_FILE_PATH)) { 56 | cerr << "load config failed" << endl; 57 | return -1; 58 | } 59 | 60 | int DeviceID = Util::String2Int(Config::Instance()->GetValue("VideoDeviceID")); 61 | int videoWidth = Util::String2Int(Config::Instance()->GetValue("VideoWidth")); 62 | int videoHeight = Util::String2Int(Config::Instance()->GetValue("VideoHeight")); 63 | int scale = Util::String2Int(Config::Instance()->GetValue("Scale")); 64 | int bDrawRect = Util::String2Int(Config::Instance()->GetValue("BoolDrawRect")); 65 | std::string facePicturePATH = Config::Instance()->GetValue("FacePicturePATH"); 66 | std::string videoStreamAddress = Config::Instance()->GetValue("VideoURL"); 67 | std::string engine = "Tengine"; 68 | ALG_TYPE alg_type = TENGINE; 69 | 70 | if(argc == 2) 71 | { 72 | _strlwr_d(argv[1]); 73 | std::string str_src = argv[1]; 74 | 75 | std::cout << "str_src = " << str_src << endl; 76 | 77 | if(str_src == "tengine") 78 | { 79 | engine = "Tengine"; 80 | alg_type = TENGINE; 81 | } 82 | else if(str_src == "caffe-hrt") 83 | { 84 | engine = "Caffe-HRT"; 85 | alg_type = CAFFE_HRT; 86 | } 87 | } 88 | 89 | VideoCapture capture; 90 | 91 | capture.open(DeviceID); 92 | if (!capture.isOpened()) { //判断能够打开摄像头 93 | cout << "can not open the camera" << endl; 94 | cin.get(); 95 | exit(1); 96 | } 97 | capture.set(CV_CAP_PROP_FRAME_WIDTH, videoWidth); 98 | capture.set(CV_CAP_PROP_FRAME_HEIGHT, videoHeight); 99 | 100 | 101 | Mat frame; 102 | int width = videoWidth / scale; 103 | int height = videoHeight / scale; 104 | 105 | namedWindow("AID-SHOW", 0); 106 | moveWindow("AID-SHOW", 320, 0); 107 | 108 | 109 | AlgThread *algThd = new AlgThread(width, height, scale, facePicturePATH, alg_type); 110 | algThd->start(); 111 | cv::Size ResImgSiz = cv::Size(videoWidth / scale, videoHeight / scale); 112 | cv::Size ShowImgSiz = cv::Size(videoWidth + 240, videoHeight); 113 | Mat ResImg = Mat(ResImgSiz, frame.type()); 114 | Mat ShowImg = Mat(ShowImgSiz, CV_8UC3); 115 | Mat show_recognized = Mat(720, 120, CV_8UC3); 116 | Mat show_registed = Mat(720,120,CV_8UC3); 117 | 118 | int showreg = 0; 119 | bindToCpu(2, 3); 120 | while(1) { 121 | capture.read(frame); 122 | if(!frame.empty()) { 123 | 124 | cv::resize(frame, ResImg, ResImgSiz, CV_INTER_LINEAR); 125 | show_recognized -= show_recognized; 126 | algThd->sendFrame(ResImg, frame); 127 | if(1 == bDrawRect) { 128 | int step = 0; 129 | for(int i = 0; i < 3; i ++) { 130 | Mface f = algThd->getFace(i); 131 | if(f.drawflag == 1) { 132 | if(f.id < 10000) 133 | cv::putText(frame, Util::Int2String(f.time), cvPoint(f.pos.x * scale, (f.pos.y + f.pos.height) * scale), 1, 8, cvScalar(0, 0, 255, 0), 8); 134 | else 135 | cv::putText(frame, Util::Int2String(f.id), cvPoint(f.pos.x * scale, f.pos.y * scale + 20), 1, 1, cvScalar(0, 255, 0, 0), 2); 136 | cv::rectangle(frame, cvPoint(f.pos.x * scale, f.pos.y * scale), cvPoint((f.pos.x + f.pos.width)*scale, (f.pos.y + f.pos.height)*scale), cvScalar(0, 255, 0, 0), 3); 137 | std::string facepath = "./faces/" + f.name + ".png"; 138 | Mat showmat = imread(facepath, CV_LOAD_IMAGE_UNCHANGED); 139 | if(!showmat.empty()) { 140 | showreg = 1; 141 | cv::rectangle(showmat, cvPoint(0, 0), cvPoint(120, 120), cvScalar(255, 255, 255, 0), 3); 142 | Mat bgROIMat = show_recognized(Rect(0, step * 120, 120, 120)); 143 | step++; 144 | showmat.copyTo(bgROIMat); 145 | } 146 | } 147 | } 148 | } 149 | } 150 | char fps[32]; 151 | sprintf(fps, "fps : %.1f", algThd->getFps()); 152 | char cost[32]; 153 | sprintf(cost, "cost : %.1f", algThd->getReccost()); 154 | cv::putText(frame, String(fps), cvPoint(10, 80), 2, 3, cvScalar(192, 0, 0, 0), 6); 155 | cv::putText(frame, engine, cvPoint(570,680), 2, 3, cvScalar(0, 0, 192, 0), 6); 156 | //cv::putText(frame, String(cost), cvPoint(10, 80), 1, 3, cvScalar(192, 192, 192, 0), 2); 157 | if(algThd->flushRegistMat == 1){ 158 | int step = 0; 159 | int face_id = algThd->getFaceID(); 160 | for(int m = face_id; m > face_id - 6; m --) { 161 | char string_m[16]; 162 | sprintf(string_m, "%d", m); 163 | std::string facepath = "./faces/" + String(string_m) + ".png"; 164 | Mat rsmat = imread(facepath, CV_LOAD_IMAGE_UNCHANGED); 165 | cv::rectangle(rsmat, cvPoint(0, 0), cvPoint(120, 120), cvScalar(255, 255, 255, 0), 3); 166 | if(rsmat.empty()) { 167 | continue; 168 | } 169 | Mat bgROIMat = show_registed(Rect(0, step * 120, 120, 120)); 170 | step++; 171 | rsmat.copyTo(bgROIMat); 172 | } 173 | show_registed.copyTo(ShowImg(cv::Rect(frame.cols+show_recognized.cols, 0, show_registed.cols, show_registed.rows))); 174 | algThd->flushRegistMat = 0; 175 | } 176 | show_recognized.copyTo(ShowImg(cv::Rect(0, 0, show_recognized.cols, show_recognized.rows))); 177 | frame.copyTo(ShowImg(cv::Rect(120, 0, frame.cols, frame.rows))); 178 | imshow("AID-SHOW", ShowImg); 179 | waitKey(1); 180 | } 181 | algThd->join(); 182 | return 0; 183 | } 184 | -------------------------------------------------------------------------------- /models/LightenedCNN_B.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OAID/FaceRecognition2/e9636a8d0f602eda71db2ea35baaf1a70d0fdc4b/models/LightenedCNN_B.caffemodel -------------------------------------------------------------------------------- /models/LightenedCNN_B.prototxt: -------------------------------------------------------------------------------- 1 | name: "lighten_cnn_B" 2 | layer { 3 | name: "input" 4 | type: "Input" 5 | top: "data" 6 | input_param { shape: { dim: 1 dim: 1 dim: 128 dim: 128 } } 7 | } 8 | 9 | layer{ 10 | name: "conv1" 11 | type: "Convolution" 12 | convolution_param { 13 | num_output: 96 14 | kernel_size: 5 15 | stride: 1 16 | pad: 2 17 | } 18 | bottom: "data" 19 | top: "conv1" 20 | } 21 | layer{ 22 | name: "slice1" 23 | type:"Slice" 24 | slice_param { 25 | slice_dim: 1 26 | } 27 | bottom: "conv1" 28 | top: "slice1_1" 29 | top: "slice1_2" 30 | } 31 | layer{ 32 | name: "etlwise1" 33 | type: "Eltwise" 34 | bottom: "slice1_1" 35 | bottom: "slice1_2" 36 | top: "eltwise1" 37 | eltwise_param { 38 | operation: MAX 39 | } 40 | } 41 | layer{ 42 | name: "pool1" 43 | type: "Pooling" 44 | pooling_param { 45 | pool: MAX 46 | kernel_size: 2 47 | stride: 2 48 | } 49 | bottom: "eltwise1" 50 | top: "pool1" 51 | } 52 | 53 | layer{ 54 | name: "conv2a" 55 | type: "Convolution" 56 | convolution_param { 57 | num_output: 96 58 | kernel_size: 1 59 | stride: 1 60 | } 61 | bottom: "pool1" 62 | top: "conv2a" 63 | } 64 | layer{ 65 | name: "slice2a" 66 | type:"Slice" 67 | slice_param { 68 | slice_dim: 1 69 | } 70 | bottom: "conv2a" 71 | top: "slice2a_1" 72 | top: "slice2a_2" 73 | } 74 | layer{ 75 | name: "etlwise2a" 76 | type: "Eltwise" 77 | bottom: "slice2a_1" 78 | bottom: "slice2a_2" 79 | top: "eltwise2a" 80 | eltwise_param { 81 | operation: MAX 82 | } 83 | } 84 | 85 | layer{ 86 | name: "conv2" 87 | type: "Convolution" 88 | convolution_param { 89 | num_output: 192 90 | kernel_size: 3 91 | stride: 1 92 | pad: 1 93 | } 94 | bottom: "eltwise2a" 95 | top: "conv2" 96 | } 97 | layer{ 98 | name: "slice2" 99 | type:"Slice" 100 | slice_param { 101 | slice_dim: 1 102 | } 103 | bottom: "conv2" 104 | top: "slice2_1" 105 | top: "slice2_2" 106 | } 107 | layer{ 108 | name: "etlwise2" 109 | type: "Eltwise" 110 | bottom: "slice2_1" 111 | bottom: "slice2_2" 112 | top: "eltwise2" 113 | eltwise_param { 114 | operation: MAX 115 | } 116 | } 117 | layer{ 118 | name: "pool2" 119 | type: "Pooling" 120 | pooling_param { 121 | pool: MAX 122 | kernel_size: 2 123 | stride: 2 124 | } 125 | bottom: "eltwise2" 126 | top: "pool2" 127 | } 128 | 129 | layer{ 130 | name: "conv3a" 131 | type: "Convolution" 132 | convolution_param { 133 | num_output: 192 134 | kernel_size: 1 135 | stride: 1 136 | } 137 | bottom: "pool2" 138 | top: "conv3a" 139 | } 140 | layer{ 141 | name: "slice3a" 142 | type:"Slice" 143 | slice_param { 144 | slice_dim: 1 145 | } 146 | bottom: "conv3a" 147 | top: "slice3a_1" 148 | top: "slice3a_2" 149 | } 150 | layer{ 151 | name: "etlwise3a" 152 | type: "Eltwise" 153 | bottom: "slice3a_1" 154 | bottom: "slice3a_2" 155 | top: "eltwise3a" 156 | eltwise_param { 157 | operation: MAX 158 | } 159 | } 160 | 161 | layer{ 162 | name: "conv3" 163 | type: "Convolution" 164 | convolution_param { 165 | num_output: 384 166 | kernel_size: 3 167 | stride: 1 168 | pad: 1 169 | } 170 | bottom: "eltwise3a" 171 | top: "conv3" 172 | } 173 | layer{ 174 | name: "slice3" 175 | type:"Slice" 176 | slice_param { 177 | slice_dim: 1 178 | } 179 | bottom: "conv3" 180 | top: "slice3_1" 181 | top: "slice3_2" 182 | } 183 | layer{ 184 | name: "etlwise3" 185 | type: "Eltwise" 186 | bottom: "slice3_1" 187 | bottom: "slice3_2" 188 | top: "eltwise3" 189 | eltwise_param { 190 | operation: MAX 191 | } 192 | } 193 | layer{ 194 | name: "pool3" 195 | type: "Pooling" 196 | pooling_param { 197 | pool: MAX 198 | kernel_size: 2 199 | stride: 2 200 | } 201 | bottom: "eltwise3" 202 | top: "pool3" 203 | } 204 | 205 | layer{ 206 | name: "conv4a" 207 | type: "Convolution" 208 | convolution_param{ 209 | num_output: 384 210 | kernel_size: 1 211 | stride: 1 212 | } 213 | bottom: "pool3" 214 | top: "conv4a" 215 | } 216 | layer{ 217 | name: "slice4a" 218 | type:"Slice" 219 | slice_param { 220 | slice_dim: 1 221 | } 222 | bottom: "conv4a" 223 | top: "slice4a_1" 224 | top: "slice4a_2" 225 | } 226 | layer{ 227 | name: "etlwise4a" 228 | type: "Eltwise" 229 | bottom: "slice4a_1" 230 | bottom: "slice4a_2" 231 | top: "eltwise4a" 232 | eltwise_param { 233 | operation: MAX 234 | } 235 | } 236 | layer{ 237 | name: "conv4" 238 | type: "Convolution" 239 | convolution_param{ 240 | num_output: 256 241 | kernel_size: 3 242 | stride: 1 243 | pad: 1 244 | } 245 | bottom: "eltwise4a" 246 | top: "conv4" 247 | } 248 | layer{ 249 | name: "slice4" 250 | type:"Slice" 251 | slice_param { 252 | slice_dim: 1 253 | } 254 | bottom: "conv4" 255 | top: "slice4_1" 256 | top: "slice4_2" 257 | } 258 | layer{ 259 | name: "etlwise4" 260 | type: "Eltwise" 261 | bottom: "slice4_1" 262 | bottom: "slice4_2" 263 | top: "eltwise4" 264 | eltwise_param { 265 | operation: MAX 266 | } 267 | } 268 | 269 | layer{ 270 | name: "conv5a" 271 | type: "Convolution" 272 | convolution_param{ 273 | num_output: 256 274 | kernel_size: 1 275 | stride: 1 276 | } 277 | bottom: "eltwise4" 278 | top: "conv5a" 279 | } 280 | layer{ 281 | name: "slice5a" 282 | type:"Slice" 283 | slice_param { 284 | slice_dim: 1 285 | } 286 | bottom: "conv5a" 287 | top: "slice5a_1" 288 | top: "slice5a_2" 289 | } 290 | layer{ 291 | name: "etlwise5a" 292 | type: "Eltwise" 293 | bottom: "slice5a_1" 294 | bottom: "slice5a_2" 295 | top: "eltwise5a" 296 | eltwise_param { 297 | operation: MAX 298 | } 299 | } 300 | layer{ 301 | name: "conv5" 302 | type: "Convolution" 303 | convolution_param{ 304 | num_output: 256 305 | kernel_size: 3 306 | stride: 1 307 | pad: 1 308 | } 309 | bottom: "eltwise5a" 310 | top: "conv5" 311 | } 312 | layer{ 313 | name: "slice5" 314 | type:"Slice" 315 | slice_param { 316 | slice_dim: 1 317 | } 318 | bottom: "conv5" 319 | top: "slice5_1" 320 | top: "slice5_2" 321 | } 322 | layer{ 323 | name: "etlwise5" 324 | type: "Eltwise" 325 | bottom: "slice5_1" 326 | bottom: "slice5_2" 327 | top: "eltwise5" 328 | eltwise_param { 329 | operation: MAX 330 | } 331 | } 332 | 333 | layer{ 334 | name: "pool4" 335 | type: "Pooling" 336 | pooling_param { 337 | pool: MAX 338 | kernel_size: 2 339 | stride: 2 340 | } 341 | bottom: "eltwise5" 342 | top: "pool4" 343 | } 344 | 345 | layer{ 346 | name: "fc1" 347 | type: "InnerProduct" 348 | inner_product_param { 349 | num_output: 512 350 | } 351 | bottom: "pool4" 352 | top: "fc1" 353 | } 354 | layer{ 355 | name: "slice_fc1" 356 | type:"Slice" 357 | slice_param { 358 | slice_dim: 1 359 | } 360 | bottom: "fc1" 361 | top: "slice_fc1_1" 362 | top: "slice_fc1_2" 363 | } 364 | layer{ 365 | name: "etlwise_fc1" 366 | type: "Eltwise" 367 | bottom: "slice_fc1_1" 368 | bottom: "slice_fc1_2" 369 | top: "eltwise_fc1" 370 | eltwise_param { 371 | operation: MAX 372 | } 373 | } 374 | 375 | -------------------------------------------------------------------------------- /models/det1.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OAID/FaceRecognition2/e9636a8d0f602eda71db2ea35baaf1a70d0fdc4b/models/det1.caffemodel -------------------------------------------------------------------------------- /models/det1.prototxt: -------------------------------------------------------------------------------- 1 | name: "PNet" 2 | layer { 3 | name: "input" 4 | type: "Input" 5 | top: "data" 6 | input_param { 7 | shape { 8 | dim: 1 9 | dim: 3 10 | dim: 12 11 | dim: 12 12 | } 13 | } 14 | } 15 | layer { 16 | name: "conv1" 17 | type: "Convolution" 18 | bottom: "data" 19 | top: "conv1" 20 | param { 21 | lr_mult: 1 22 | decay_mult: 1 23 | } 24 | param { 25 | lr_mult: 2 26 | decay_mult: 0 27 | } 28 | convolution_param { 29 | num_output: 10 30 | kernel_size: 3 31 | stride: 1 32 | weight_filler { 33 | type: "xavier" 34 | } 35 | bias_filler { 36 | type: "constant" 37 | value: 0 38 | } 39 | } 40 | } 41 | layer { 42 | name: "PReLU1" 43 | type: "PReLU" 44 | bottom: "conv1" 45 | top: "conv1" 46 | } 47 | layer { 48 | name: "pool1" 49 | type: "Pooling" 50 | bottom: "conv1" 51 | top: "pool1" 52 | pooling_param { 53 | pool: MAX 54 | kernel_size: 2 55 | stride: 2 56 | } 57 | } 58 | 59 | layer { 60 | name: "conv2" 61 | type: "Convolution" 62 | bottom: "pool1" 63 | top: "conv2" 64 | param { 65 | lr_mult: 1 66 | decay_mult: 1 67 | } 68 | param { 69 | lr_mult: 2 70 | decay_mult: 0 71 | } 72 | convolution_param { 73 | num_output: 16 74 | kernel_size: 3 75 | stride: 1 76 | weight_filler { 77 | type: "xavier" 78 | } 79 | bias_filler { 80 | type: "constant" 81 | value: 0 82 | } 83 | } 84 | } 85 | layer { 86 | name: "PReLU2" 87 | type: "PReLU" 88 | bottom: "conv2" 89 | top: "conv2" 90 | } 91 | 92 | layer { 93 | name: "conv3" 94 | type: "Convolution" 95 | bottom: "conv2" 96 | top: "conv3" 97 | param { 98 | lr_mult: 1 99 | decay_mult: 1 100 | } 101 | param { 102 | lr_mult: 2 103 | decay_mult: 0 104 | } 105 | convolution_param { 106 | num_output: 32 107 | kernel_size: 3 108 | stride: 1 109 | weight_filler { 110 | type: "xavier" 111 | } 112 | bias_filler { 113 | type: "constant" 114 | value: 0 115 | } 116 | } 117 | } 118 | layer { 119 | name: "PReLU3" 120 | type: "PReLU" 121 | bottom: "conv3" 122 | top: "conv3" 123 | } 124 | 125 | 126 | layer { 127 | name: "conv4-1" 128 | type: "Convolution" 129 | bottom: "conv3" 130 | top: "conv4-1" 131 | param { 132 | lr_mult: 1 133 | decay_mult: 1 134 | } 135 | param { 136 | lr_mult: 2 137 | decay_mult: 0 138 | } 139 | convolution_param { 140 | num_output: 2 141 | kernel_size: 1 142 | stride: 1 143 | weight_filler { 144 | type: "xavier" 145 | } 146 | bias_filler { 147 | type: "constant" 148 | value: 0 149 | } 150 | } 151 | } 152 | 153 | layer { 154 | name: "conv4-2" 155 | type: "Convolution" 156 | bottom: "conv3" 157 | top: "conv4-2" 158 | param { 159 | lr_mult: 1 160 | decay_mult: 1 161 | } 162 | param { 163 | lr_mult: 2 164 | decay_mult: 0 165 | } 166 | convolution_param { 167 | num_output: 4 168 | kernel_size: 1 169 | stride: 1 170 | weight_filler { 171 | type: "xavier" 172 | } 173 | bias_filler { 174 | type: "constant" 175 | value: 0 176 | } 177 | } 178 | } 179 | layer { 180 | name: "prob1" 181 | type: "Softmax" 182 | bottom: "conv4-1" 183 | top: "prob1" 184 | } 185 | -------------------------------------------------------------------------------- /models/det2.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OAID/FaceRecognition2/e9636a8d0f602eda71db2ea35baaf1a70d0fdc4b/models/det2.caffemodel -------------------------------------------------------------------------------- /models/det2.prototxt: -------------------------------------------------------------------------------- 1 | name: "RNet" 2 | layer { 3 | name: "input" 4 | type: "Input" 5 | top: "data" 6 | input_param { 7 | shape { 8 | dim: 1 9 | dim: 3 10 | dim: 24 11 | dim: 24 12 | } 13 | } 14 | } 15 | ########################## 16 | ###################### 17 | layer { 18 | name: "conv1" 19 | type: "Convolution" 20 | bottom: "data" 21 | top: "conv1" 22 | param { 23 | lr_mult: 0 24 | decay_mult: 0 25 | } 26 | param { 27 | lr_mult: 0 28 | decay_mult: 0 29 | } 30 | convolution_param { 31 | num_output: 28 32 | kernel_size: 3 33 | stride: 1 34 | weight_filler { 35 | type: "xavier" 36 | } 37 | bias_filler { 38 | type: "constant" 39 | value: 0 40 | } 41 | } 42 | } 43 | layer { 44 | name: "prelu1" 45 | type: "PReLU" 46 | bottom: "conv1" 47 | top: "conv1" 48 | propagate_down: true 49 | } 50 | layer { 51 | name: "pool1" 52 | type: "Pooling" 53 | bottom: "conv1" 54 | top: "pool1" 55 | pooling_param { 56 | pool: MAX 57 | kernel_size: 3 58 | stride: 2 59 | } 60 | } 61 | 62 | layer { 63 | name: "conv2" 64 | type: "Convolution" 65 | bottom: "pool1" 66 | top: "conv2" 67 | param { 68 | lr_mult: 0 69 | decay_mult: 0 70 | } 71 | param { 72 | lr_mult: 0 73 | decay_mult: 0 74 | } 75 | convolution_param { 76 | num_output: 48 77 | kernel_size: 3 78 | stride: 1 79 | weight_filler { 80 | type: "xavier" 81 | } 82 | bias_filler { 83 | type: "constant" 84 | value: 0 85 | } 86 | } 87 | } 88 | layer { 89 | name: "prelu2" 90 | type: "PReLU" 91 | bottom: "conv2" 92 | top: "conv2" 93 | propagate_down: true 94 | } 95 | layer { 96 | name: "pool2" 97 | type: "Pooling" 98 | bottom: "conv2" 99 | top: "pool2" 100 | pooling_param { 101 | pool: MAX 102 | kernel_size: 3 103 | stride: 2 104 | } 105 | } 106 | #################################### 107 | 108 | ################################## 109 | layer { 110 | name: "conv3" 111 | type: "Convolution" 112 | bottom: "pool2" 113 | top: "conv3" 114 | param { 115 | lr_mult: 0 116 | decay_mult: 0 117 | } 118 | param { 119 | lr_mult: 0 120 | decay_mult: 0 121 | } 122 | convolution_param { 123 | num_output: 64 124 | kernel_size: 2 125 | stride: 1 126 | weight_filler { 127 | type: "xavier" 128 | } 129 | bias_filler { 130 | type: "constant" 131 | value: 0 132 | } 133 | } 134 | } 135 | layer { 136 | name: "prelu3" 137 | type: "PReLU" 138 | bottom: "conv3" 139 | top: "conv3" 140 | propagate_down: true 141 | } 142 | ############################### 143 | 144 | ############################### 145 | 146 | layer { 147 | name: "conv4" 148 | type: "InnerProduct" 149 | bottom: "conv3" 150 | top: "conv4" 151 | param { 152 | lr_mult: 0 153 | decay_mult: 0 154 | } 155 | param { 156 | lr_mult: 0 157 | decay_mult: 0 158 | } 159 | inner_product_param { 160 | num_output: 128 161 | weight_filler { 162 | type: "xavier" 163 | } 164 | bias_filler { 165 | type: "constant" 166 | value: 0 167 | } 168 | } 169 | } 170 | layer { 171 | name: "prelu4" 172 | type: "PReLU" 173 | bottom: "conv4" 174 | top: "conv4" 175 | } 176 | 177 | layer { 178 | name: "conv5-1" 179 | type: "InnerProduct" 180 | bottom: "conv4" 181 | top: "conv5-1" 182 | param { 183 | lr_mult: 0 184 | decay_mult: 0 185 | } 186 | param { 187 | lr_mult: 0 188 | decay_mult: 0 189 | } 190 | inner_product_param { 191 | num_output: 2 192 | #kernel_size: 1 193 | #stride: 1 194 | weight_filler { 195 | type: "xavier" 196 | } 197 | bias_filler { 198 | type: "constant" 199 | value: 0 200 | } 201 | } 202 | } 203 | layer { 204 | name: "conv5-2" 205 | type: "InnerProduct" 206 | bottom: "conv4" 207 | top: "conv5-2" 208 | param { 209 | lr_mult: 1 210 | decay_mult: 1 211 | } 212 | param { 213 | lr_mult: 2 214 | decay_mult: 1 215 | } 216 | inner_product_param { 217 | num_output: 4 218 | #kernel_size: 1 219 | #stride: 1 220 | weight_filler { 221 | type: "xavier" 222 | } 223 | bias_filler { 224 | type: "constant" 225 | value: 0 226 | } 227 | } 228 | } 229 | layer { 230 | name: "prob1" 231 | type: "Softmax" 232 | bottom: "conv5-1" 233 | top: "prob1" 234 | } -------------------------------------------------------------------------------- /models/det3.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OAID/FaceRecognition2/e9636a8d0f602eda71db2ea35baaf1a70d0fdc4b/models/det3.caffemodel -------------------------------------------------------------------------------- /models/det3.prototxt: -------------------------------------------------------------------------------- 1 | name: "ONet" 2 | layer { 3 | name: "input" 4 | type: "Input" 5 | top: "data" 6 | input_param { 7 | shape { 8 | dim: 1 9 | dim: 3 10 | dim: 48 11 | dim: 48 12 | } 13 | } 14 | } 15 | layer { 16 | name: "conv1" 17 | type: "Convolution" 18 | bottom: "data" 19 | top: "conv1" 20 | param { 21 | lr_mult: 1 22 | decay_mult: 1 23 | } 24 | param { 25 | lr_mult: 2 26 | decay_mult: 1 27 | } 28 | convolution_param { 29 | num_output: 32 30 | kernel_size: 3 31 | stride: 1 32 | weight_filler { 33 | type: "xavier" 34 | } 35 | bias_filler { 36 | type: "constant" 37 | value: 0 38 | } 39 | } 40 | } 41 | layer { 42 | name: "prelu1" 43 | type: "PReLU" 44 | bottom: "conv1" 45 | top: "conv1" 46 | } 47 | layer { 48 | name: "pool1" 49 | type: "Pooling" 50 | bottom: "conv1" 51 | top: "pool1" 52 | pooling_param { 53 | pool: MAX 54 | kernel_size: 3 55 | stride: 2 56 | } 57 | } 58 | layer { 59 | name: "conv2" 60 | type: "Convolution" 61 | bottom: "pool1" 62 | top: "conv2" 63 | param { 64 | lr_mult: 1 65 | decay_mult: 1 66 | } 67 | param { 68 | lr_mult: 2 69 | decay_mult: 1 70 | } 71 | convolution_param { 72 | num_output: 64 73 | kernel_size: 3 74 | stride: 1 75 | weight_filler { 76 | type: "xavier" 77 | } 78 | bias_filler { 79 | type: "constant" 80 | value: 0 81 | } 82 | } 83 | } 84 | 85 | layer { 86 | name: "prelu2" 87 | type: "PReLU" 88 | bottom: "conv2" 89 | top: "conv2" 90 | } 91 | layer { 92 | name: "pool2" 93 | type: "Pooling" 94 | bottom: "conv2" 95 | top: "pool2" 96 | pooling_param { 97 | pool: MAX 98 | kernel_size: 3 99 | stride: 2 100 | } 101 | } 102 | 103 | layer { 104 | name: "conv3" 105 | type: "Convolution" 106 | bottom: "pool2" 107 | top: "conv3" 108 | param { 109 | lr_mult: 1 110 | decay_mult: 1 111 | } 112 | param { 113 | lr_mult: 2 114 | decay_mult: 1 115 | } 116 | convolution_param { 117 | num_output: 64 118 | kernel_size: 3 119 | weight_filler { 120 | type: "xavier" 121 | } 122 | bias_filler { 123 | type: "constant" 124 | value: 0 125 | } 126 | } 127 | } 128 | layer { 129 | name: "prelu3" 130 | type: "PReLU" 131 | bottom: "conv3" 132 | top: "conv3" 133 | } 134 | layer { 135 | name: "pool3" 136 | type: "Pooling" 137 | bottom: "conv3" 138 | top: "pool3" 139 | pooling_param { 140 | pool: MAX 141 | kernel_size: 2 142 | stride: 2 143 | } 144 | } 145 | layer { 146 | name: "conv4" 147 | type: "Convolution" 148 | bottom: "pool3" 149 | top: "conv4" 150 | param { 151 | lr_mult: 1 152 | decay_mult: 1 153 | } 154 | param { 155 | lr_mult: 2 156 | decay_mult: 1 157 | } 158 | convolution_param { 159 | num_output: 128 160 | kernel_size: 2 161 | weight_filler { 162 | type: "xavier" 163 | } 164 | bias_filler { 165 | type: "constant" 166 | value: 0 167 | } 168 | } 169 | } 170 | layer { 171 | name: "prelu4" 172 | type: "PReLU" 173 | bottom: "conv4" 174 | top: "conv4" 175 | } 176 | 177 | 178 | layer { 179 | name: "conv5" 180 | type: "InnerProduct" 181 | bottom: "conv4" 182 | top: "conv5" 183 | param { 184 | lr_mult: 1 185 | decay_mult: 1 186 | } 187 | param { 188 | lr_mult: 2 189 | decay_mult: 1 190 | } 191 | inner_product_param { 192 | #kernel_size: 3 193 | num_output: 256 194 | weight_filler { 195 | type: "xavier" 196 | } 197 | bias_filler { 198 | type: "constant" 199 | value: 0 200 | } 201 | } 202 | } 203 | 204 | layer { 205 | name: "drop5" 206 | type: "Dropout" 207 | bottom: "conv5" 208 | top: "conv5" 209 | dropout_param { 210 | dropout_ratio: 0.25 211 | } 212 | } 213 | layer { 214 | name: "prelu5" 215 | type: "PReLU" 216 | bottom: "conv5" 217 | top: "conv5" 218 | } 219 | 220 | 221 | layer { 222 | name: "conv6-1" 223 | type: "InnerProduct" 224 | bottom: "conv5" 225 | top: "conv6-1" 226 | param { 227 | lr_mult: 1 228 | decay_mult: 1 229 | } 230 | param { 231 | lr_mult: 2 232 | decay_mult: 1 233 | } 234 | inner_product_param { 235 | #kernel_size: 1 236 | num_output: 2 237 | weight_filler { 238 | type: "xavier" 239 | } 240 | bias_filler { 241 | type: "constant" 242 | value: 0 243 | } 244 | } 245 | } 246 | layer { 247 | name: "conv6-2" 248 | type: "InnerProduct" 249 | bottom: "conv5" 250 | top: "conv6-2" 251 | param { 252 | lr_mult: 1 253 | decay_mult: 1 254 | } 255 | param { 256 | lr_mult: 2 257 | decay_mult: 1 258 | } 259 | inner_product_param { 260 | #kernel_size: 1 261 | num_output: 4 262 | weight_filler { 263 | type: "xavier" 264 | } 265 | bias_filler { 266 | type: "constant" 267 | value: 0 268 | } 269 | } 270 | } 271 | layer { 272 | name: "conv6-3" 273 | type: "InnerProduct" 274 | bottom: "conv5" 275 | top: "conv6-3" 276 | param { 277 | lr_mult: 1 278 | decay_mult: 1 279 | } 280 | param { 281 | lr_mult: 2 282 | decay_mult: 1 283 | } 284 | inner_product_param { 285 | #kernel_size: 1 286 | num_output: 10 287 | weight_filler { 288 | type: "xavier" 289 | } 290 | bias_filler { 291 | type: "constant" 292 | value: 0 293 | } 294 | } 295 | } 296 | layer { 297 | name: "prob1" 298 | type: "Softmax" 299 | bottom: "conv6-1" 300 | top: "prob1" 301 | } 302 | -------------------------------------------------------------------------------- /models/face_demo.dat: -------------------------------------------------------------------------------- 1 | 10001 2 | 10001 3 | 256 4 | -10.7438 4.0511 -3.98833 4.45968 -4.95891 2.64161 -0.680792 4.68052 -3.95091 1.79175 -7.69385 3.06007 -6.25957 -9.09965 -9.27708 11.5835 -3.64177 9.26463 6.64146 12.6087 8.53087 -13.9296 -10.8452 -6.67376 -9.14305 -1.50012 7.03426 -3.68792 6.91679 -15.3766 -3.8919 0.357827 -3.31793 9.78534 5.2705 -13.5363 -0.862643 -3.52194 0.636001 -2.33634 -8.36508 3.7729 -8.59887 1.63587 -1.37122 -3.12747 -2.48814 2.86255 1.29017 3.01862 4.82357 -5.7937 -6.87151 -7.9083 -12.2007 7.31118 -2.63057 -8.07156 -9.39251 1.04606 -0.540404 4.61707 14.2208 -5.57286 -5.92494 -8.91064 -11.4938 -6.93958 7.33408 -6.52302 1.61797 -5.20327 3.8505 7.64215 -4.80501 -14.0409 -0.121743 -0.462571 -9.33156 5.67895 11.4488 -12.693 6.17293 1.63534 7.43143 11.3966 -3.87498 -7.71842 3.64051 -0.143742 9.39426 5.82711 -3.46636 9.15556 -4.21109 -4.61351 -3.15478 -0.107714 5.79214 -11.0866 -13.4226 -6.30294 -1.17475 4.54155 -4.04484 -10.0875 -2.6583 -6.21692 4.86277 -6.76836 -7.50317 3.84142 -2.19092 -9.30288 -2.71496 1.70719 -12.5126 -6.37549 -5.57686 -7.68066 -2.24843 -3.09725 14.3965 -0.544848 -11.4633 -3.13118 -13.2057 4.6524 -6.37712 4.88642 -7.40566 -6.45747 0.208418 -6.20571 3.83285 -2.98114 7.38977 14.9905 -10.002 -1.98523 -9.23142 7.31193 -10.7587 0.12115 0.0310595 0.542001 -5.45768 -1.56281 -5.23401 -0.898829 4.08608 3.79953 12.6254 -12.4154 3.33421 -0.641792 2.19454 -3.86595 -9.92832 -3.82295 -0.640177 -3.91015 7.88343 -5.83995 2.57085 -7.68212 -0.66308 1.05932 -2.76806 -3.70248 11.0755 4.51612 -6.88055 -1.56156 7.53149 -3.17485 7.76987 1.42318 6.38773 7.54521 4.93069 0.53951 -1.18415 4.07869 2.31801 -3.14783 12.6136 -1.84364 -1.06394 1.793 -4.10534 4.82726 -6.03155 -4.58201 7.37691 -5.26491 8.45842 -8.85707 -4.46209 -4.74944 -8.9101 -2.33791 -6.72004 -4.67995 1.87516 -8.89224 -3.52397 -10.1881 3.65026 5.01583 0.67462 -8.90965 8.48878 -13.0553 -3.97272 6.9611 -4.81898 -6.59949 7.40852 1.7743 -7.03971 -2.19499 -14.2979 -2.14756 -1.30607 2.60047 -4.40404 -0.746732 -7.1054 11.7676 -6.12018 -2.08286 4.22474 -4.29041 -17.9611 5.79251 -6.07965 -13.962 -10.1919 -5.74811 -2.17656 -0.910249 -7.08994 -9.67116 -0.89745 -10.3857 5.18862 6.442 -2.97499 -7.61704 -18.9037 -2.1225 -8.6061 8.22269 -6.94803 -2.78114 5 | -------------------------------------------------------------------------------- /obj/Readme: -------------------------------------------------------------------------------- 1 | this directory store the face images -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | rm -rf faces/*.png 2 | rm -rf models/face_demo.dat 3 | 4 | export OPENBLAS_NUM_THREADS=1 5 | export BYPASSACL=0x0 6 | export CONV_INT_PRIO=2000 7 | export CAFFELIB=/usr/local/AID/Caffe-HRT/lib/ 8 | export LD_LIBRARY_PATH=/usr/local/AID/AID-lib 9 | 10 | if [ $# == 0 ] ; then 11 | ./bin/fp Tengine 12 | else 13 | case $1 in 14 | Caffe-HRT) 15 | ./bin/fp Caffe-HRT 16 | ;; 17 | Tengine) 18 | ./bin/fp Tengine 19 | ;; 20 | *) 21 | echo "Ignorant" 22 | ;; 23 | esac 24 | fi 25 | --------------------------------------------------------------------------------