【问题标题】:Face Landmark Detection algorithm, output image disappear C++, Dlib人脸地标检测算法,输出图像消失 C++, Dlib
【发布时间】:2017-10-28 01:35:12
【问题描述】:

我正在尝试提取面部图像的所有面部特征并将该图像保存在我的目录中。就我而言,我必须遵循这些步骤。

  1. 输入图片
  2. 提取人脸 ROI
  3. 然后使用 Dlib 提取面部特征
  4. 为图像添加叠加层
  5. 将该图像保存在我的目录中

我已经尝试过这个 c++ 代码,它给出了我需要的输出。但是在显示叠加图像后它会很快消失。谁能告诉我这段代码有什么问题。

#include <dlib\opencv\cv_image.h>
#include <opencv2/highgui/highgui.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;
using namespace cv;

int main()
{
    try
    {

        cv::Mat src1;
        src1 = imread("obama.jpg", CV_LOAD_IMAGE_COLOR);

        //image_window win, win_faces;
        image_window win;
        Mat atom_image = Mat::zeros(500, 500, CV_8UC3);


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

            //cv::Mat temp;
            //temp = src1;

            cv_image<bgr_pixel> cimg(src1);
            cv_image<bgr_pixel> black(atom_image);
            // Detect faces 
            std::vector<rectangle> faces = detector(cimg);

            cout << "Number of faces detected: " << faces.size() << endl;

            // Find the pose of each face.
            std::vector<full_object_detection> shapes;
            //for (int i = 0; i < faces.size(); i++) {
                //shapes.push_back(pose_model(cimg, faces[i]));


                full_object_detection shape = pose_model(cimg, faces[0]);


                shapes.push_back(pose_model(cimg, faces[0]));


                //const full_object_detection& d = shapes[0];
                //ofstream outputfile;
                //outputfile.open("data1.txt");


                cout << "pixel position of first part:  " << shape.part(2) << endl;

            // Display it all on the screen
            //win.clear_overlay();
            win.set_image(cimg);
            win.add_overlay(render_face_detections(shapes));

    }
    catch (serialization_error& e)
    {
        cout << "You need dlib's default face landmarking model file to run this example." << endl;
        cout << "You can get it from the following URL: " << endl;
        cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
        cout << endl << e.what() << endl;
    }
    catch (exception& e)
    {
        cout << e.what() << endl;
    }
} 

【问题讨论】:

    标签: c++ opencv dlib


    【解决方案1】:

    您没有握住图像窗口。一个简单的方法是

    win.set_image(cimg);
    win.add_overlay(render_face_detections(shapes));
    waitKey(0);
    

    此外,我没有看到任何代码,您将输出保存到当前目录,正如您在问题中提到的那样。你可以看看 imwrite 。

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 2017-10-18
      • 2019-12-01
      • 2017-07-19
      • 2019-02-20
      • 1970-01-01
      • 2017-01-18
      • 2018-01-20
      • 2017-06-01
      相关资源
      最近更新 更多