I have an array containing the coordinates of many rectangles as a numpy array from opencv.
rec_arr = [[1404, 677, 73, 73],
[2670, 1062, 115, 115],
[2981, 1077, 114, 114],
[ 691, 1077, 107, 107],
[2251, 1272, 131, 131],
[3035, 1239, 139, 139],
[1050, 1359, 135, 135],
[ 887, 1663, 149, 149]]
this is a representation of 1 rectangle given from the array x, y, w, h
+--------------------> X axis
|
| (X,Y) (X+W, Y)
| +--------------+
| | |
| | |
| | |
| +--------------+
v (X, Y+H) (X+W,Y+H)
Y axis
I want to loop through the array to compare all the rectangles to each other then highlight the rectangles that intersect. this is my attempt:
for (x, y, w, h) in rec_arr:
X1 = x
Y1 = y
W1 = w
H1 = h
for (x, y, w, h) in rec_arr:
X2 = x
Y2 = y
W2 = w
H2 = h
if (X1+W1<X2 or X2+W2<X1 or Y1+H1<Y2 or Y2+H2<Y1):
print 'no intersect'
else:
print 'intersect'
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 0, 255), -1)
I've also attempted using itertools.combinations()
to compare each combination of 2 rectangles in the array with no success. any help would be great!