Skip to content

Bounding Box

Bounding Box tasks identify and locate objects within an image by drawing rectangular bounding boxes around them. The solution returns a list of boxes, each defined by position and dimensions. This is used for CAPTCHAs that ask users to draw rectangles around specific objects.

TypeDescription
BoundingBoxTaskDraw bounding boxes around objects in an image
ParameterTypeRequiredDescription
typestringYesBoundingBoxTask
bodystringYesBase64-encoded image
commentstringNoInstructions (e.g., “Draw boxes around all cars”)
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "BoundingBoxTask",
"body": "iVBORw0KGgoAAAANSUhEUg...",
"comment": "Draw boxes around all cars"
}
}
{
"errorId": 0,
"status": "ready",
"solution": {
"boxes": [
{ "x": 10, "y": 20, "width": 100, "height": 80 },
{ "x": 200, "y": 50, "width": 120, "height": 90 }
]
}
}
{
"boxes": [
{ "x": 10, "y": 20, "width": 100, "height": 80 },
{ "x": 200, "y": 50, "width": 120, "height": 90 }
]
}
FieldTypeDescription
boxesarrayArray of bounding box objects

Each bounding box object contains:

FieldTypeDescription
xintegerHorizontal pixel position of the top-left corner
yintegerVertical pixel position of the top-left corner
widthintegerWidth of the bounding box in pixels
heightintegerHeight of the bounding box in pixels
import requests
import base64
API_KEY = "YOUR_API_KEY"
with open("captcha.png", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
response = requests.post("https://api.ucaptcha.net/createTask", json={
"clientKey": API_KEY,
"task": {
"type": "BoundingBoxTask",
"body": image_data,
"comment": "Draw boxes around all cars"
}
}).json()
if response.get("status") == "ready":
boxes = response["solution"]["boxes"]
for box in boxes:
print(f"Box at ({box['x']}, {box['y']}) size {box['width']}x{box['height']}")
else:
import time
task_id = response["taskId"]
while True:
result = requests.post("https://api.ucaptcha.net/getTaskResult", json={
"clientKey": API_KEY,
"taskId": task_id
}).json()
if result["status"] == "ready":
boxes = result["solution"]["boxes"]
for box in boxes:
print(f"Box at ({box['x']}, {box['y']}) size {box['width']}x{box['height']}")
break
elif result["status"] == "failed":
print("Error:", result.get("errorDescription"))
break
time.sleep(5)
import { readFileSync } from "fs";
const API_KEY = "YOUR_API_KEY";
const imageData = readFileSync("captcha.png").toString("base64");
const response = await fetch("https://api.ucaptcha.net/createTask", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
clientKey: API_KEY,
task: {
type: "BoundingBoxTask",
body: imageData,
comment: "Draw boxes around all cars"
}
})
}).then(r => r.json());
if (response.status === "ready") {
for (const box of response.solution.boxes) {
console.log(`Box at (${box.x}, ${box.y}) size ${box.width}x${box.height}`);
}
} else {
const taskId = response.taskId;
while (true) {
const result = await fetch("https://api.ucaptcha.net/getTaskResult", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ clientKey: API_KEY, taskId })
}).then(r => r.json());
if (result.status === "ready") {
for (const box of result.solution.boxes) {
console.log(`Box at (${box.x}, ${box.y}) size ${box.width}x${box.height}`);
}
break;
} else if (result.status === "failed") {
console.error("Error:", result.errorDescription);
break;
}
await new Promise(r => setTimeout(r, 5000));
}
}
Terminal window
IMAGE_BASE64=$(base64 -w 0 captcha.png)
curl -X POST https://api.ucaptcha.net/createTask \
-H "Content-Type: application/json" \
-d "{
\"clientKey\": \"YOUR_API_KEY\",
\"task\": {
\"type\": \"BoundingBoxTask\",
\"body\": \"$IMAGE_BASE64\",
\"comment\": \"Draw boxes around all cars\"
}
}"
# Poll for result if not immediately ready (replace TASK_ID)
curl -X POST https://api.ucaptcha.net/getTaskResult \
-H "Content-Type: application/json" \
-d '{
"clientKey": "YOUR_API_KEY",
"taskId": "TASK_ID"
}'
  • 2Captcha