gpt4 book ai didi

c++ - 如何将 dlib shape_pedictor 与视频捕获一起编写

转载 作者:行者123 更新时间:2023-11-28 00:16:50 25 4
gpt4 key购买 nike

我正在尝试将相机的每一帧写入视频。直到这里都很好。但是,我希望我的视频在每一帧中也包含 shape_predictor,因此当它被复制时它也会出现在图像上。到目前为止我已经知道了......有什么想法吗?谢谢

cap >> frame;
cv::VideoWriter oVideoWriter;
// . . .
cv_image<bgr_pixel> cimg(frame); //Mat to something dlib can deal with
frontal_face_detector detector = get_frontal_face_detector();
std::vector<rectangle> faces = detector(cimg);
pose_model(cimg, faces[0]);
oVideoWriter.write(dlib::toMat(cimg)); //Turn it into an Opencv Mat

最佳答案

形状预测器不是人脸检测器。您必须先调用人脸检测器,然后调用形状预测器。

请参阅此示例程序:http://dlib.net/face_landmark_detection_ex.cpp.html

您正确初始化了面部检测器..然后您必须初始化跟踪器。像这样:

shape_predictor sp;
deserialize("shape_predictor_68_face_landmarks.dat") >> sp;

模型可以在这里找到:http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2

剩下的部分,您可以按照我上面链接的示例程序进行操作。这是运行跟踪器的部分。您必须将检测器返回的输出(边界框)传递给跟踪器才能工作。下面的代码遍历检测器返回的所有框。

        // Now tell the face detector to give us a list of bounding boxes
// around all the faces in the image.
std::vector<rectangle> dets = detector(img);
cout << "Number of faces detected: " << dets.size() << endl;

// Now we will go ask the shape_predictor to tell us the pose of
// each face we detected.
std::vector<full_object_detection> shapes;
for (unsigned long j = 0; j < dets.size(); ++j)
{
full_object_detection shape = sp(img, dets[j]);
cout << "number of parts: "<< shape.num_parts() << endl;
cout << "pixel position of first part: " << shape.part(0) << endl;
cout << "pixel position of second part: " << shape.part(1) << endl;
// You get the idea, you can get all the face part locations if
// you want them. Here we just store them in shapes so we can
// put them on the screen.
shapes.push_back(shape);
}

关于c++ - 如何将 dlib shape_pedictor 与视频捕获一起编写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29702900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com