Convert OpenCV Rect rectangle to dlib?

I am using an OpenCV face detector with C ++ to align a dlib face instead of a dlib detector due to slow speed.
To use dlib face alignment, I have to pass the detection rectangle to the face alignment function.
However, I cannot do this, although the dlib detector is ok.
Since it is std::vector<rectangle> detsused in the dlib sample code , I tried to assign as shown below, but I could not.
Note that detect_rectis the face detection rectangle with the OpenCV detector.

dets[0].l = detect_rect.left;
dets[0].t = detect_rect.top;
dets[0].r = detect_rect.right;
dets[0].b = detect_rect.bottom;

Could you tell me any tips?

Thanks.

+4
source share
2

, OpenCV :

OpenCV , , .. p >

dlib , 1.

, Utils.h

static cv::Rect dlibRectangleToOpenCV(dlib::rectangle r)
{
  return cv::Rect(cv::Point2i(r.left(), r.top()), cv::Point2i(r.right() + 1, r.bottom() + 1));
}

:

static dlib::rectangle openCVRectToDlib(cv::Rect r)
{
  return dlib::rectangle((long)r.tl().x, (long)r.tl().y, (long)r.br().x - 1, (long)r.br().y - 1);
}
+14

, cv::Rect.

:

dets[0].l = detect_rect.x;
dets[0].t = detect_rect.y;
dets[0].r = detect_rect.x + detect_rect.width;
dets[0].b = detect_rect.y + detect_rect.height;
+3

Source: https://habr.com/ru/post/1624922/


All Articles