Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 制作自动注释工具_Python_Yolo - Fatal编程技术网

Python 制作自动注释工具

Python 制作自动注释工具,python,yolo,Python,Yolo,我正在尝试为yolo对象检测制作一个自动注释工具,该工具使用先前训练过的模型来查找检测结果,我设法编写了一些代码,但我有一点卡住了,据我所知,这需要作为yolo的注释格式: 18 0.154167 0.431250 0.091667 0.612500 用我的代码我得到了 0.5576068858305613, 0.5410404056310654, -0.7516528169314066, 0.33822181820869446 我不知道为什么我会在第三个数字处得到-,如果我需要缩短我的浮点

我正在尝试为yolo对象检测制作一个自动注释工具,该工具使用先前训练过的模型来查找检测结果,我设法编写了一些代码,但我有一点卡住了,据我所知,这需要作为yolo的注释格式:

18 0.154167 0.431250 0.091667 0.612500
用我的代码我得到了

0.5576068858305613, 0.5410404056310654, -0.7516528169314066, 0.33822181820869446
我不知道为什么我会在第三个数字处得到
-
,如果我需要缩短我的浮点数, 我会张贴下面的代码,如果有人可以帮助我,完成这个项目后,我会张贴整个代码,如果有人想使用它

def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
上面的代码是转换YOLO格式坐标的函数,用于转换需要传递的大小(w,h)和需要传递的框的大小(x,x+w,y,y+h)


问题是函数中的索引

box[0]=>center x
box[1]=>center y
box[2]=>width of your bbox
box[3]=>height of your bbox
根据文件,yolo标签如下:

<object-class> <x> <y> <width> <height>
def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = box[0]*dw
y = box[1]*dh
w = box[2]*dw
h = box[3]*dh
return (x,y,w,h)

也许这能帮你

   def bounding_box_2_yolo(obj_detections, frame, index):
    yolo_info = []
    for object_det in obj_detections:
        left_x, top_y, right_x, bottom_y = object_det.boxes
        xmin = left_x
        xmax = right_x
        ymin = top_y
        ymax = bottom_y

        xcen = float((xmin + xmax)) / 2 / frame.shape[1]
        ycen = float((ymin + ymax)) / 2 / frame.shape[0]

        w = float((xmax - xmin)) / frame.shape[1]
        h = float((ymax - ymin)) / frame.shape[0]

        yolo_info.append((index, xcen, ycen, w, h))

    return yolo_info
labelimg也有很多你可以使用的东西

你好,阿米尔,你的答案是有效的,但当我从图层中得到输出时,它会显示所有检测结果,但现在我只需要显示我解析的结果,当我尝试在代码中向下转换时,数字是biiger(7.724965194175983,0.7653914836415073,1.0260124042116363,0.9967035996286492)我发布了完整的代码,你能建议我应该在哪里使用你的函数吗,谢谢你好Rafael,我更新了你能从我的代码中建议使用吗
   def bounding_box_2_yolo(obj_detections, frame, index):
    yolo_info = []
    for object_det in obj_detections:
        left_x, top_y, right_x, bottom_y = object_det.boxes
        xmin = left_x
        xmax = right_x
        ymin = top_y
        ymax = bottom_y

        xcen = float((xmin + xmax)) / 2 / frame.shape[1]
        ycen = float((ymin + ymax)) / 2 / frame.shape[0]

        w = float((xmax - xmin)) / frame.shape[1]
        h = float((ymax - ymin)) / frame.shape[0]

        yolo_info.append((index, xcen, ycen, w, h))

    return yolo_info