Как написать dlib shape_pedictor вместе с захватом видео

Я пытаюсь записать каждый кадр с камеры в видео. Пока здесь все хорошо. Однако я хочу, чтобы мое видео также включало 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

0

Решение

Предсказатель формы — это не детектор лица. Вы должны сначала вызвать детектор лица, а затем предиктор формы.

Смотрите этот пример программы: 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);
}
3

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector