如何编写dlib shape_pedictor 连同视频采集
How to write dlib shape_pedictor together with the video capture
我正在尝试将摄像机的每一帧写入视频。直到这里都很好。但是,我希望我的视频在每一帧中也包含 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
剩下的,你可以按照我上面链接的示例程序来做。这是跟踪器 运行 的部分。您必须将检测器的输出(边界框)return 传递给跟踪器才能工作。下面的代码遍历检测器 return 编辑的所有框。
// 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);
}
我正在尝试将摄像机的每一帧写入视频。直到这里都很好。但是,我希望我的视频在每一帧中也包含 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
剩下的,你可以按照我上面链接的示例程序来做。这是跟踪器 运行 的部分。您必须将检测器的输出(边界框)return 传递给跟踪器才能工作。下面的代码遍历检测器 return 编辑的所有框。
// 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);
}