I have two rectangles, each identified by a set of four coordinates. 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.
We basically add areas of two rectangles. This includes the intersecting part twice, so we subtract the area of intersecting part. Similarly, we can compute area of 2nd rectangle. If the x_distance or y_distance is negative, then the two rectangles do not intersect.
Practical Data Science using PythonTwo rectangles overlap when the area of their intersection is positive. So, two rectangles that only touch at the corner or edges do not overlap. So, if the input is like R1 = [0,0,2,2], R2 = [1,1,3,3], then the output will be True.
Treat your rectangles as general polygons, and decompose the problem into two steps:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With