我已经从 alexeyab darknet repo 训练了 yolov4 来检测车牌中的字符。它正确分割了字符,但边界框是随机顺序的。对于这样的图像,如何从左上角到右下角对边界框进行排序:(这不是实际使用的图像,但由于机密数据,这是尼泊尔车牌样本的 Photoshop 图像)
我试过了:(来自pyimagesearch)
def sort_bbox(bbox, method="left-to-right"):
# initialize the reverse flag and sort index
reverse = False
i = 0
# handle if we need to sort in reverse
if method == "right-to-left" or method == "bottom-to-top":
reverse = True
# handle if we are sorting against the y-coordinate rather than
# the x-coordinate of the bounding box
if method == "top-to-bottom" or method == "bottom-to-top":
i = 1
# construct the list of bounding boxes and sort them from top to
# bottom
boundingBoxes = sorted(bbox, key=lambda b: b[1], reverse=reverse)
# return the list of sorted contours and bounding boxes
return boundingBoxes
但没有对边界框进行排序。它仍然是随机顺序。
我有来自 yolov4 检测的边界框,如下所示: xywh 中的未排序边界框:[[50, 12, 15, 18], [66, 10, 15, 19], [87, 10, 19, 20], [21, 12, 24, 19], [51, 12, 15, 17], [51, 12, 15, 18], [66, 12, 15, 18], [86, 11, 19, 19], [39, 32, 27, 29], [68, 33, 28, 27], [97, 31, 28, 30], [12, 37, 24, 25], [11, 35, 25, 27], [40, 34, 27, 28], [68, 33, 27, 27], [97, 33, 28, 28]]
并从上面的排序代码: [[66, 10, 15, 19], [87, 10, 19, 20], [86, 11, 19, 19], [50, 12, 15, 18], [21, 12, 24, 19], [51, 12, 15, 17], [51, 12, 15, 18], [66, 12, 15, 18], [97, 31, 28, 30], [39, 32, 27, 29], [68, 33, 28, 27], [68, 33, 27, 27], [97, 33, 28, 28], [40, 34, 27, 28], [11, 35, 25, 27], [12, 37, 24, 25]]
我想要的是边界框:बा २ प ८ ८ ८ ८</p>
任何帮助将不胜感激。