号称很快的算法:搭个顺车,编个make

下载源码:

git clone https://github.com/ShiqiYu/libfacedetection

目录结构如下:

├── ChangeLog
├── example
│   └── libfacedetectcnn-example.cpp
├── images
│   ├── 20190314160527.jpg
│   ├── chloecalmon.png
│   ├── cnnresult.png
│   ├── keliamoniz1.jpg
│   ├── keliamoniz2.jpg
│   └── pic2.jpg
├── LICENSE
├── models
│   ├── caffe
│   │   ├── yufacedetectnet-open-v1.caffemodel
│   │   └── yufacedetectnet-open-v1.prototxt
│   └── openvino
│       ├── yufacedetectnet-open-v1-320x240.bin
│       └── yufacedetectnet-open-v1-320x240.xml
├── README.md
└── src
    ├── facedetectcnn.cpp
    ├── facedetectcnn-floatdata.cpp
    ├── facedetectcnn.h
    ├── facedetectcnn-int8data.cpp
    ├── facedetectcnn-model.cpp
    └── Makefile

1.从里层开始,在src目录中加入Makefile内容如下:

#./src/Makefile
FLAGS = -fPIC -c -std=c++11 -O3 -mavx -mfma #编译选项,在linux上编译

OBJ = facedetectcnn.o                       #编译的中间文件
OBJ += facedetectcnn-floatdata.o
OBJ += facedetectcnn-int8data.o 
OBJ += facedetectcnn-model.o  

SO = libfacedetectcnn.so                    #编成的so库
 #添加需要的文件就行,类似内核编译那种

%.o:%.cpp
	$(CC)  $(FLAGS) $^

all:$(OBJ)
	@echo "Compile..."
	g++ -shared -fpic -o $(SO) $(OBJ)
	@echo "End"

clean:
	-rm $(OBJ) *.so

2.工程目录的Makefile

#!/bin/bash

CC = g++
FLAGS = 
TAG = test

TOPDIR = $(PWD)

OBJDIR = $(TOPDIR)/obj
BINDIR = $(TOPDIR)/bin
SRCDIR = $(TOPDIR)/src
INCDIR = $(TOPDIR)/include
LIBDIR = $(TOPDIR)/lib

# EXAMPLE = $(TOPDIR)/example
# INCLUDE = -I/home/oeasy/install/opencv-3.4.0/build_install/include 
# LIB = -L/home/oeasy/install/opencv-3.4.0/build_install/lib -L$(TOPDIR)/src/kernel
# LDL = -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -fpermissive -lfacedetectcnn

# INC = -I./src/kernel 

export CC TAG TOPDIR SUBDIR OBJDIR BINDIR INC #导出全局变量 
all:CHECK $(SRCDIR) $(TAG) 

CHECK:
	mkdir -p $(OBJDIR) $(BINDIR) $(INCDIR) $(LIBDIR)

$(SRCDIR):ECHO
	make -C $@



# $(TAG):
# 	$(CC) -o  $(addprefix $(BINDIR)/,$(TAG))   $(EXAMPLE)/libfacedetectcnn-example.cpp  $(INC)  $(INCLUDE) $(LIB) $(LDL)   


install:
	cp $(SRCDIR)/*.h $(INCDIR)
	cp $(SRCDIR)/*.so $(LIBDIR)
	sudo cp $(LIBDIR)/*.so /usr/local/lib/
	sudo ldconfig



ECHO:  
	@echo $@


CLEANDIR:ECHO
	make -C $(SRCDIR) clean

.PHONY : clean
clean :CLEANDIR
	-rm $(BINDIR)/$(TAG)
	-rm -rf $(INCDIR)
	-rm -rf $(LIBDIR)
	-rm -rf $(OBJDIR)

这个没啥 好说的,默认编译成so库,然后,install 就能安装到相应目录 打开#就能编译libfacedetectcnn-example.cpp成二进制的文件。
编译后的目录如下 :

├── bin
│   └── test
├── ChangeLog
├── example
│   └── libfacedetectcnn-example.cpp
├── images
│   ├── 20190314160527.jpg
│   ├── chloecalmon.png
│   ├── cnnresult.png
│   ├── keliamoniz1.jpg
│   ├── keliamoniz2.jpg
│   └── pic2.jpg
├── include
│   └── facedetectcnn.h
├── lib
│   └── libfacedetectcnn.so
├── LICENSE
├── Makefile
├── models
│   ├── caffe
│   │   ├── yufacedetectnet-open-v1.caffemodel
│   │   └── yufacedetectnet-open-v1.prototxt
│   └── openvino
│       ├── yufacedetectnet-open-v1-320x240.bin
│       └── yufacedetectnet-open-v1-320x240.xml
├── obj
├── README.md
└── src
    ├── facedetectcnn.cpp
    ├── facedetectcnn-floatdata.cpp
    ├── facedetectcnn-floatdata.o
    ├── facedetectcnn.h
    ├── facedetectcnn-int8data.cpp
    ├── facedetectcnn-int8data.o
    ├── facedetectcnn-model.cpp
    ├── facedetectcnn-model.o
    ├── facedetectcnn.o
    ├── libfacedetectcnn.so
    └── Makefile

在bin目录下,运行./test …/images/20190314160527.jpg
具体测试如下。
41个小人脸53ms,只是右下脚框的图有点歪。
在这里插入图片描述
二。
另附 cmake 文件 :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT (facedetection)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
SET(BUILD_SHARED_LIBS ON)

FIND_PACKAGE(OpenCV REQUIRED)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src
                    ${OpenCV_INCLUDE_DIRS})
ADD_LIBRARY(facedetection src/facedetectcnn.cpp 
                          src/facedetectcnn-floatdata.cpp 
                          src/facedetectcnn-int8data.cpp 
                          src/facedetectcnn-model.cpp)
ADD_EXECUTABLE(face_detect example/libfacedetectcnn-example.cpp)
TARGET_LINK_LIBRARIES(face_detect ${OpenCV_LIBS} facedetection)

简单明了。。。。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐