API Endpoint Access URL
https://api.pixlab.io/detect
Get Your API Key & Try DETECT Now ↗Description
The Detect API endpoint uses advanced machine learning models to detect, classify, and return bounding-box coordinates for objects inside your images. Developers can use these coordinates to crop subjects, moderate content, or build automated media cataloguing pipelines.
HTTP Methods
GET, POST
HTTP Parameters
Required
| Fields | Type | Description |
|---|---|---|
img |
URL | URL to the input image to gain insight from including objects location, and their potential coordinates in the event of a GET request. If you want to upload an image directly from your app, then submit a multipart/form-data POST request instead. Refer to the POST Request Data section below. |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
POST Request Body
This section details the requirements for using a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-dataapplication/json
Use multipart/form-data to directly upload your image from you app (Refer to The PixLab Github Repository↗ for a working example). If you're using JSON, the media file must already be uploaded. Consider calling store to upload an image before invoking this endpoint.
HTTP Response
application/json
This endpoint always returns a JSON object containing image description data. Response fields include:
| Fields | Type | Description |
|---|---|---|
status |
Integer | HTTP 200 indicates success. Any other code indicates failure. |
objects |
Array | List | An array or list of detected objects, with their name, description, and potential coordinates on the input image or video frame. This data is crucial for further processing and analysis. |
error |
String |
Error description when status != 200.
|
Code Samples
import requests
import json
# Gain image insights using the DETECT API endpoint. Identify and locate objects within images
# pinpointing their coordinates or specific regions.
# Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
img = 'https://pixlab.io/assets/images/nature31.jpg'
key = 'PIXLAB_API_KEY' # Get your API key from https://console.pixlab.io/
req = requests.get('https://api.pixlab.io/detect',params={'img':img,'key':key})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
total = len(reply['objects']) # Total objects detected
print(f"Total Objects Detected: {total}")
for object in reply['objects']:
print(f"Object: {object['name']} - Coordinates: {object['bbox']}")
// Gain image insights using the DETECT API endpoint. Identify and locate objects within images
// pinpointing their coordinates or specific regions.
// https://pixlab.io/endpoints/detect for more info.
// Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
const img = 'https://pixlab.io/assets/images/nature31.jpg';
// Your PixLab key
const key = 'PIXLAB_API_KEY';
fetch(`https://api.pixlab.io/detect?img=${encodeURIComponent(img)}&key=${encodeURIComponent(key)}`)
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
const total = reply.objects.length; // Total Objects
console.log(`Total Detected Objects: ${total}`);
reply.objects.forEach(object => {
console.log(`Object: ${object.name} - Coordinates: ${object.bbox}`);
});
}
})
.catch(error => console.error('Error:', error));
<?php
# Gain image insights using the DETECT API endpoint. Identify and locate objects within images
# pinpointing their coordinates or specific regions.
// Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
$img = 'https://pixlab.io/assets/images/nature31.jpg';
$key = 'PIXLAB_API_KEY';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/detect?img=' . urlencode($img) . '&key=' . urlencode($key));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
$total = count($reply['objects']); # Total number of detected objects
echo "Total Objects: " . $total . "\n";
foreach ($reply['objects'] as $object) {
echo "Object: " . $object['object'] . " - Coordinates: " . $object['bbox'] . "\n";
}
}
require 'net/http'
require 'uri'
require 'json'
# Gain image insights using the DETECT API endpoint. Identify and locate objects within images
# pinpointing their coordinates or specific regions.
# https://pixlab.io/endpoints/detect for more info.
# Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
img = 'https://pixlab.io/assets/images/nature31.jpg'
# Your PixLab key
key = 'PIXLAB_API_KEY'
uri = URI.parse('https://api.pixlab.io/detect')
params = { img: img, key: key }
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
total = reply['objects'].length
puts "Total Detected Objects: #{total}"
reply['objects'].each do |obj|
puts "Object: #{obj['name']} - Coordinates: #{obj['bbox']}"
end
end
Similar API Endpoints
objectimg, nsfw, img-embed, docscan, chat, text-embed, crop, mogrify, facelookup ↗, faceverify ↗, query