Determine the intersection area of ​​two rectangles

I have two rectangles, each of which is defined by a set of four coordinates. I read how to see if they intersect, but how can I calculate the intersection area? Rectangles are not aligned along the axes.

Is there an OpenCV feature for this? I was told that there is, but I did not find it.

+8
c ++ intersection
source share
2 answers

Treat your rectangles as common polygons and lay out the problem in two steps:

  • calculate the intersection of two polygons, which itself is a polygon (or empty);
  • calculate the area of ​​the resulting polygon.

Both issues have a lot of literature on the Internet.

I do not know anything about OpenCV, so I can not give any advice.

+2
source share

You can easily convert the Qt library code for this to use it with OpenCV.

Look for this feature:

QRect QRect::operator&(const QRect &r) const 

In qrect.cpp .

+1
source share

Source: https://habr.com/ru/post/649863/


All Articles