开发者

Determine the area of the intersection of two rectangles

开发者 https://www.devze.com 2023-01-28 20:53 出处:网络
I have two rectangles, each identified by a set of four coordina开发者_C百科tes. I\'ve read up on how to see whether they intersect, but how can I calculate the area of the intersection? The rectangle

I have two rectangles, each identified by a set of four coordina开发者_C百科tes. I've read up on how to see whether they intersect, but how can I calculate the area of the intersection? The rectangles are not axis-aligned.

Is there an OpenCV function for this? I was told there was, but I fail to find it.


Treat your rectangles as general polygons, and decompose the problem into two steps:

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

There's plenty of literature on the Web for both problems.

I don't know anything about OpenCV so can't give any advice there.


You can easily convert the Qt libraries code for that in order to be used with OpenCV.

Look for this function:

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

In qrect.cpp.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号