Upload a Vision Event Image

Upload a local image for use in vision events. The returned sourceId can be referenced in the images array when creating events.

import roboflow

roboflow.login()

rf = roboflow.Roboflow()
ws = rf.workspace()

# Upload an image
result = ws.upload_vision_event_image("inspection-photo.jpg")
source_id = result["sourceId"]

# You can also provide an optional name and metadata
result = ws.upload_vision_event_image(
    "inspection-photo.jpg",
    name="line-a-check-001",
    metadata={"camera": "cam-1", "shift": "morning"},
)

The sourceId from the response is used in the images array when creating a vision event:

ws.write_vision_event({
    "eventId": "d4e5f6a7-b2c3-4d4e-9f6a-7b8c9d0e1f2a",
    "eventType": "quality_check",
    "useCaseId": "a1b3c8e1",
    "timestamp": "2024-01-15T10:30:00Z",
    "images": [
        {
            "sourceId": source_id,
            "label": "inspection-photo",
            "objectDetections": [
                {"class": "defect", "x": 100, "y": 200, "width": 50, "height": 30, "confidence": 0.95}
            ],
        }
    ],
    "eventData": {"result": "fail"},
})

For supported image formats and metadata constraints, see the REST API reference.

Last updated

Was this helpful?