开发者

Determine the area of the intersection of two rectangles

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜