过帐多个列表时的状态代码400



我正在使用YOLOv5框架,并尝试将边界框的坐标POST到API服务器。当我试图将边界框的坐标发布为列表时,就会出现问题。本质上,我正在尝试实现以下结构:

Boxes: [{x,y,w,h},
{x,y,w,h},
{x,y,w,h},
{x,y,w,h}]

main.py

command = input('Enter command for a snap')
if command == 'n':
for *xyxy, conf, cls in reversed(det):
c1, c2 = (int(xyxy[0]), int(xyxy[1])), (int(xyxy[2]), int(xyxy[3]))
center_point = round((c1[0]+c2[0])/2), round((c1[1]+c2[1])/2)
circle = cv2.circle(im0, center_point,5,(0,255,0),2)
text_coord = cv2.putText(im0,str(center_point), center_point,cv2.FONT_HERSHEY_PLAIN,2,(0,0,255))

# print(x_coord, y_coord, w_coord, h_coord)
# print(center_point)
x_coord = [c1[0]]
y_coord = [c1[1]]
w_coord = [c2[0] - c1[0]]
h_coord = [c2[1] - c1[1]]
boxes = x_coord + y_coord + w_coord + h_coord
data = {
'Boxes': boxes,
}
json_object = json.dumps(data, indent=4)
r = requests.post(
"http://127.0.0.1:8000/snippets/",
data=(json_object),
headers={'Authorization': 'Token 353101b2657b3779199777984c131f33b78656be',
"Content-Type": "application/json"},
)
print(r.status_code)

提前感谢

layer1 = model1(frame)
labels, cord = layer1.xyxyn[0][:, -1], layer1.xyxyn[0][:, :-1]
n = len(labels) 
for i in range(n):
conf = cord[i]   //confidence values
if conf>=0.6:
x_shape, y_shape = frame.shape[1], frame.shape[0]
x1, y1, x2, y2 = int(row[0] * x_shape), int(row[1] * y_shape), int(row[2] * x_shape), int(row[3] * y_shape)
....
//model1.names[int(labels[i])]  return labels names

这是我获取标签和坐标的代码。您可以使用该代码生成列表。还有另一种方法。https://github.com/ultralytics/yolov5/issues/574

相关内容

  • 没有找到相关文章

最新更新