Skip to content

Commit c5b5d5c

Browse files
author
Piotr Semenov
committed
Fix. Now cv::Rect() is the identity under cv::Rect::operator| operation
1 parent f670a99 commit c5b5d5c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/core/include/opencv2/core/types.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,12 +1803,17 @@ Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
18031803
template<typename _Tp> static inline
18041804
Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
18051805
{
1806-
_Tp x1 = std::min(a.x, b.x);
1807-
_Tp y1 = std::min(a.y, b.y);
1808-
a.width = std::max(a.x + a.width, b.x + b.width) - x1;
1809-
a.height = std::max(a.y + a.height, b.y + b.height) - y1;
1810-
a.x = x1;
1811-
a.y = y1;
1806+
if (!a.area()) {
1807+
a = b;
1808+
}
1809+
else if (b.area()) {
1810+
_Tp x1 = std::min(a.x, b.x);
1811+
_Tp y1 = std::min(a.y, b.y);
1812+
a.width = std::max(a.x + a.width, b.x + b.width) - x1;
1813+
a.height = std::max(a.y + a.height, b.y + b.height) - y1;
1814+
a.x = x1;
1815+
a.y = y1;
1816+
}
18121817
return a;
18131818
}
18141819

0 commit comments

Comments
 (0)