前言html
最近使用dlib库的同时也会用到opencv,特别是因为对dlib库的画图函数不熟悉,都想着转换到opencv进行show。本文介绍一下两种开源库中rectangle类型之间的转换。函数
类型说明url
opencv中cv::Rect 以及opencv中的rectangle函数:spa
void cv::rectangle( InputOutputArray img, Point pt1, Point pt2, const Scalar & color, int thickness = 1, int lineType = LINE_8, int shift = 0)
或者.net
void cv::rectangle(Mat & img, Rect rec, const Scalar & color, int thickness = 1, int lineType = LINE_8, int shift = 0)
dlib中的rectangle类型:3d
rectangle ( long left_, long top_, long right_, long bottom_ );
或者code
template <typename T> rectangle ( const vector<T,2>& p1, const vector<T,2>& p2);
如何转换htm
static cv::Rect dlibRectangleToOpenCV(dlib::rectangle r) { return cv::Rect(cv::Point2i(r.left(), r.top()), cv::Point2i(r.right() + 1, r.bottom() + 1)); }
或者blog
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); }
或者get
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.stackoverflow-convert-opencvs-rect-to-dlibs-rectangle;
完