简体   繁体   中英

Opencv Join bounding boxes python

i have a haar detection and it produces me some nearby detections:

[[ 31  85 232 116]
 [141  55  66  33]
 [112  41 104  52]]

each list have the following values: x,y,w,h id like to get the most left top X,Y and the most right bottom x,y of all detections.

i tryed to use min() and max() but ot produces a error. and after that i tryed to use Numpy and i canot make what i need

import numpy as np
l = [10, 22, 8, 8, 11]
print(np.argmax(l))
print(np.argmin(l))

in my problen the list should be the list of lists and i want to get only lesser x,y and higer x,y

x = [ [ 31,85,232,116],
 [141,55,66,33],
 [112,41,104,52]
]

You can use a custom key with the values of first 2 elements to get max and min value. Since you need to draw a bounding box around all boundingboxes, you need to find min of x,y pair and max of x+w,y+h pair

This assumes x,y values are always positive which is fine in a image scenario.

min(x,key=lambda x:(x[0],x[1]))[:2]
max([(e[0]+e[2],e[1]+e[3]) for e in x ])

Out:

[31, 85]
(263, 201)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM