Agentic object detection
import requests
def get_bounding_boxes(api_key, image_path, search_text):
headers = {"Authorization": f"Bearer {api_key}"}
with open(image_path, "rb") as image_file:
files = {"file": image_file}
data = {"prompt": search_text}
response = requests.post(
"https://api.landing.ai/v1/agentic-object-detection",
headers=headers,
files=files,
data=data
)
if response.status_code == 200:
detections = response.json().get("detections", [])
return [detection["box"] for detection in detections] # Returns [x_min, y_min, x_max, y_max] boxes
else:
raise Exception(f"API Error: {response.text}")
# Usage example
api_key = "your_api_key_here"
boxes = get_bounding_boxes(api_key, "sample.jpg", "red shoes")
print(f"Found {len(boxes)} matching objects:")
for box in boxes:
print(f"- Bounding box: {box}")
No comments:
Post a Comment