uni*_*ent 7 c++ opencv rect dlib
我使用OpenCV的面部检测器和C++进行dlib的面部对齐,而不是dlib的检测器,因为速度很慢.
要使用dlib的面部对齐,我必须将检测矩形传递给面部对齐功能.
但是,即使dlib的探测器没问题,我也不能这样做.
因为std::vector<rectangle> dets
在dlib的示例代码中使用,我尝试分配如下所示,但我不能.
注意,detect_rect
OpenCV的探测器是人脸检测矩形.
dets[0].l = detect_rect.left;
dets[0].t = detect_rect.top;
dets[0].r = detect_rect.right;
dets[0].b = detect_rect.bottom;
Run Code Online (Sandbox Code Playgroud)
你能告诉我什么建议吗?
谢谢.
lah*_*n_j 19
需要注意的是,OpenCV使用以下定义:
OpenCV通常假设矩形的顶部和左边界是包含的,而右边界和底边界不是.
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));
}
Run Code Online (Sandbox Code Playgroud)
反过来说:
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);
}
Run Code Online (Sandbox Code Playgroud)
这个想法是正确的,但是您在访问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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11622 次 |
最近记录: |