Home > Net >  How can I calculate if one box is overlap​ to another in Opencv Python​?
How can I calculate if one box is overlap​ to another in Opencv Python​?

Time:12-27

How can I calculate if one box is overlap​​ to another in Opencv Python​​ ?

This is Shape 1 : [ shape 1 ]

This is Shape 2 : [ shape 2 ]

What I need is know the shape 1 overlap with shape 2 or Not ?

result that i should get :

False : If it not contiguous each other

True : If it not contiguous each other

#I spend 3 day to solve this problem but still cannot find a way to go out hope you can help me :)

CodePudding user response:

Function inputs are 4-element tuple is used.You can improve this code for your problem.

def intersection(a,b):
  x = max(a[0], b[0])
  y = max(a[1], b[1])
  w = min(a[0] a[2], b[0] b[2]) - x
  h = min(a[1] a[3], b[1] b[3]) - y
  if w<0 or h<0: return ()
  return (x, y, w, h)

CodePudding user response:

this is what i found by my self and it really help me out :

https://www.tutorialspoint.com/rectangle-overlap-in-python

for who has problem like me .

  • Related