参考链接:
testDetection.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/videoio/videoio_c.h>
#include <dirent.h>
#include "face_detection.h"
using namespace seeta;
int test_detection(const std::string& path_images,const std::string& suffix)
{
cvNamedWindow("PicTest 0",CV_WINDOW_AUTOSIZE); //create a window called "PicTest 0"
DIR *dir;
struct dirent *ent;
seeta::FaceDetection detector("/home/menethis/work/Test/SeetaFaceEngine/FaceDetection/model/seeta_fd_frontal_v1.0.bin");
detector.SetMinFaceSize(20);
detector.SetMaxFaceSize(200);
detector.SetScoreThresh(2.f);
detector.SetImagePyramidScaleFactor(0.8f);
detector.SetWindowStep(4, 4);
if( (dir = opendir(path_images.c_str())) != NULL)
{
while((ent = readdir(dir)) != NULL)
{
std::string s1 = ent->d_name;
if (s1.find(suffix) != std::string::npos){
std::string names = std::string(path_images) + std::string("/") + s1;
cv::Mat src_ = cv::imread(names, cv::IMREAD_COLOR);
if (src_.empty()) {
fprintf(stderr, "read image error: %s\n", names.c_str());
continue;
}
cv::Mat src;
cv::cvtColor(src_, src, CV_BGR2GRAY);
seeta::ImageData img_data;
img_data.data = src.data;
img_data.width = src.cols;
img_data.height = src.rows;
img_data.num_channels = 1;
std::vector<seeta::FaceInfo> faces = detector.Detect(img_data);
fprintf(stderr, "image_name: %s, faces_num: %d\n", names.c_str(), faces.size());
for (int num = 0; num < faces.size(); num++) {
fprintf(stderr, " score = %f\n",/*, roll = %f, pitch = %f, yaw = %f*/
faces[num].score/*, faces[num].roll, faces[num].pitch, faces[num].yaw*/);
cv::rectangle(src_, cv::Rect(faces[num].bbox.x, faces[num].bbox.y,
faces[num].bbox.width, faces[num].bbox.height), cv::Scalar(0, 255, 0), 2);
}
cv::imshow("PicTest 0", src_);
char exit_c = cvWaitKey(1);
if (exit_c > 0 )
{
break;
}
}
}
closedir(dir);
}
return 0;
}
int main(int argc, char const *argv[])
{
test_detection("/home/menethis/work/ArcSoft_Test/ArcFace_opencv_gitee/ArcFace_opencv/src/jpg2",".jpg");
return 0;
}
下面是 cmakelists:
cmake_minimum_required(VERSION 3.1.0)
project(seeta_facedet)
SET(CMAKE_BUILE_TYPE "RELEASE")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 ")
SET(CMAKE_BUILE_TYPE "DEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Werror")
# Use C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++11 support has been enabled by default.")
set(src_files
src/util/nms.cpp
src/util/image_pyramid.cpp
src/io/lab_boost_model_reader.cpp
src/io/surf_mlp_model_reader.cpp
src/feat/lab_feature_map.cpp
src/feat/surf_feature_map.cpp
src/classifier/lab_boosted_classifier.cpp
src/classifier/mlp.cpp
src/classifier/surf_mlp.cpp
src/face_detection.cpp
src/fust.cpp
src/face_detection.cpp
src/testDetection.cpp
)
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/libs/opencv-install/lib/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_search_module(PKG_OPENCV REQUIRED opencv)
include_directories(${PKG_OPENCV_INCLUDE_DIRS} ./include)
# Build shared library
add_executable(FaceDetector ${src_files})
target_link_libraries(FaceDetector ${PKG_OPENCV_LDFLAGS})