ubuntu dlib 编译 人脸检测

编译:

ubuntu14.04 + dlib19.2+【 C++ 】+Face Landmark Detection_FR-0912的博客-CSDN博客

 

也可这样

cmake .. -DUSE_AVX_INSTRUCTIONS=1
cmake --build .

测试代码

linux安装dlib,关键点检测_dlib linux_Peanut_范的博客-CSDN博客

CmakeList.txt

cmake_minimum_required(VERSION 3.5)


PROJECT(dlib_facedetector)   #设置工程名

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O2 -DDLIB_JPEG_SUPPORT")

IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
ENDIF()

#INCLUDE OPENCV
FIND_PACKAGE(OpenCV REQUIRED)
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv include dir found at ${OpenCV_INCLUDE_DIRS}")

#包含头文件
INCLUDE_DIRECTORIES(/home/jason/file/dlib) #dlib根目录地址

LINK_DIRECTORIES(/home/jason/file/dlib/build/dlib) #dlib编译后bulid下dlib地址

#生产类似于.exe的可执行文件
ADD_EXECUTABLE(dlib_facedetector main.cpp)
#链接库
TARGET_LINK_LIBRARIES(dlib_facedetector dlib ${OpenCV_LIBS})
#TARGET_LINK_LIBRARIES(dlib_detector libjpeg.so)

main.cpp

#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>

using namespace dlib;
using namespace std;

int main()
{
    try
    {

        // Load face detection and pose estimation models.
        frontal_face_detector detector = get_frontal_face_detector();
        shape_predictor pose_model;
        deserialize("/home/jason/file/dlib/shape_predictor_68_face_landmarks.dat") >> pose_model;

        // Grab a frame
        string path = "/home/jason/work/01-img/shuchang.png";
        cv::Mat temp = cv::imread(path);

        cv_image<bgr_pixel> cimg(temp);
        // Detect faces
        std::vector<rectangle> faces = detector(cimg);
        // Find the pose of each face.
        std::vector<full_object_detection> shapes;
        for (unsigned long i = 0; i < faces.size(); ++i)
            shapes.push_back(pose_model(cimg, faces[i]));

        if (!shapes.empty()) {
            for (int i = 0; i < 68; i++) {
                circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
                //	shapes[0].part(i).x();//68个
            }
        }
        imshow("Dlib特征点", temp);
        cv::imwrite("saveXZQ_landmark.jpg", temp);
        cv::waitKey(0);

    }
    catch (exception& e)
    {
        cout << e.what() << endl;
    }
}

效果:

舒畅大美人!

猜你喜欢

转载自blog.csdn.net/weixin_45824067/article/details/131277075