Resolved: Status code 400 when posting multiple lists

Question:

I am working with YOLOv5 framework and I am trying to POST coordinates of a bounding box to an API server. The problem occurs when I am trying to post the coordinates of a bounding box as a list. Essentially I am trying to implement the following structure:
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)
Thanks in advance

Answer:

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
        
Here is my code to get the labels and it’s coordinates. You can use the code to generate a list. There also have another way. https://github.com/ultralytics/yolov5/issues/574

If you have better answer, please add a comment about this, thank you!

If you like this answer, you can give me a coffee by <a href=”https://violencegloss.com/mkw7pgdwwr?key=2a96ade6f3760c7e63343a320febb78e”>click here</a>

Source: Stackoverflow.com