前言
最近使用dlib库的同时也会用到opencv,特别是由于对dlib库的画图函数不熟悉,都想着转换到opencv进行show。本文介绍一下两种开源库中rectangle类型之间的转换。
类型说明
opencv中cv::Rect 以及opencv中的rectangle函数:
void cv::rectangle( InputOutputArray img, Point pt1, Point pt2, const Scalar & color, int thickness = , int lineType = LINE_8, int shift = )
或者
void cv::rectangle(Mat & img, Rect rec, const Scalar & color, int thickness = , int lineType = LINE_8, int shift = )
dlib中的rectangle类型:
rectangle ( long left_, long top_, long right_, long bottom_ );
或者
template <typename T> rectangle ( const vector<T,>& p1, const vector<T,>& p2);
如何转换
static cv::Rect dlibRectangleToOpenCV(dlib::rectangle r)
{
return cv::Rect(cv::Point2i(r.left(), r.top()), cv::Point2i(r.right() + , r.bottom() + ));
}
或者
static dlib::rectangle openCVRectToDlib(cv::Rect r)
{
return dlib::rectangle((long)r.tl().x, (long)r.tl().y, (long)r.br().x - , (long)r.br().y - );
}
或者
dets.l = detect_rect.x;
dets.t = detect_rect.y;
dets.r = detect_rect.x + detect_rect.width;
dets.b = detect_rect.y + detect_rect.height;
其中detect_rect是opencv类型,dets是dlib类型;
参考
3.*-convert-opencvs-rect-to-dlibs-rectangle;
完