我想检查两个CvRect*变量之间是否有任何部分重叠。是否有内置的opencv功能来进行此检查。我在opencv的c版本中写作。
OpenCV对此没有C API。C++方法就是简单的CCD_ 1。&=
的OpenCV源是
template<typename _Tp> static inline Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
{
_Tp x1 = std::max(a.x, b.x), y1 = std::max(a.y, b.y);
a.width = std::min(a.x + a.width, b.x + b.width) - x1;
a.height = std::min(a.y + a.height, b.y + b.height) - y1;
a.x = x1; a.y = y1;
if( a.width <= 0 || a.height <= 0 )
a = Rect();
return a;
}
所以你只需要把它翻译成C:
CvRect rect_intersect(CvRect a, CvRect b)
{
CvRect r;
r.x = (a.x > b.x) ? a.x : b.x;
r.y = (a.y > b.y) ? a.y : b.y;
r.width = (a.x + a.width < b.x + b.width) ?
a.x + a.width - r.x : b.x + b.width - r.x;
r.height = (a.y + a.height < b.y + b.height) ?
a.y + a.height - r.y : b.y + b.height - r.y;
if(r.width <= 0 || r.height <= 0)
r = cvRect(0, 0, 0, 0);
return r;
}