人脸识别引擎SeetaFaceEngine中Detection模块使用的测试代码

参考链接:

点击打开链接

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}) 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Teleger

你的支持是我前进的方向

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值