Bounding box error


I have this error showing up in my python code!

Traceback (most recent call last):
  File "/home/kl/Documents/AI bball/", line 35, in <module>
    x, y, w, h = result["bbox"]
  File "/usr/local/lib/python3.10/dist-packages/roboflow/util/", line 259, in __getitem__
    return self.json_prediction[key]
KeyError: 'bbox'

The python code looks like this:

Read until video is completed

while cap.isOpened():
    # Capture frame-by-frame
    ret, frame =
    if ret:
        # Apply object detection on the frame
        results = model.predict(frame)

        # Draw the bounding boxes and labels on the frame
        for result in results:
            label = result["class"]
            confidence = result["confidence"]
            x, y, w, h = result["bbox"]
            cv2.rectangle(frame, (int(x), int(y)), (int(x + w), int(y + h)), (0, 255, 0), 2)
            text = f"{label}: {confidence:.2f}"
            cv2.putText(frame, text, (int(x), int(y) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

        # Write the frame into the file 'output.avi'

        # Display the resulting frame
        cv2.imshow('Frame', frame)

        # Press Q on the keyboard to exit
        if cv2.waitKey(25) & 0xFF == ord('q'):

And the data looks like this


The model I am using is here = australia-germany Object Detection Dataset and Pre-Trained Model by Ken Lee

I hope someone can tell me where I have gone wrong and how to move forward with this.



Hi @kenlee_au

I think @Lenny gave a good, correct answer here, but might be hard to understand.

To reiterate, the Python SDK returns something like this:

    "predictions": [
            "x": 189.5,
            "y": 100,
            "width": 163,
            "height": 186,
            "class": "helmet",
            "confidence": 0.544
    "image": {
        "width": 2048,
        "height": 1371

-From our hosted inference docs

The bbox property/key you mentioned isn’t valid. The x,y, width and height should be referenced directly, not nested within a bbox property.

If you’ve used the roboflow.js package before, that might be where some of the confusion comes from. In roboflow.js, the bounding box info is within a property called bbox for each detected prediction object.