I need to sort boxes array from top left to bottom right, and I am using the solution here How can I sort contours from left to right and top to bottom?. Which works fine. But I have another array which keep the box label, I need to use this label after sorting tmp_box array. So how can sort box_label
or keep the original index of tmp_box
like this How can I save the original index after sorting a list? which I can use to access the box_label
.
box_label = ["box1","box2","box3"]
tmp_box = []
tmp_box.append([100,90,20,30]) #x,y,w,h
tmp_box.append([90,80,25,30]) #x,y,w,h
tmp_box.append([190,180,25,30]) #x,y,w,h
tmp_box_np = np.array(tmp_box)
max_height = np.max(tmp_box_np[::, 3])
nearest = max_height * 1.4
tmp_box.sort(key=lambda r: [int(nearest * round(float(r[1]) / nearest)), r[0]])