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.
Task Type
Section titled “Task Type”| Type | Description |
|---|---|
BoundingBoxTask | Draw bounding boxes around objects in an image |
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | BoundingBoxTask |
body | string | Yes | Base64-encoded image |
comment | string | No | Instructions (e.g., “Draw boxes around all cars”) |
Create Task
Section titled “Create Task”Request
Section titled “Request”{ "clientKey": "YOUR_API_KEY", "task": { "type": "BoundingBoxTask", "body": "iVBORw0KGgoAAAANSUhEUg...", "comment": "Draw boxes around all cars" }}Response
Section titled “Response”{ "errorId": 0, "status": "ready", "solution": { "boxes": [ { "x": 10, "y": 20, "width": 100, "height": 80 }, { "x": 200, "y": 50, "width": 120, "height": 90 } ] }}Solution Object
Section titled “Solution Object”{ "boxes": [ { "x": 10, "y": 20, "width": 100, "height": 80 }, { "x": 200, "y": 50, "width": 120, "height": 90 } ]}| Field | Type | Description |
|---|---|---|
boxes | array | Array of bounding box objects |
Each bounding box object contains:
| Field | Type | Description |
|---|---|---|
x | integer | Horizontal pixel position of the top-left corner |
y | integer | Vertical pixel position of the top-left corner |
width | integer | Width of the bounding box in pixels |
height | integer | Height of the bounding box in pixels |
Code Examples
Section titled “Code Examples”Python
Section titled “Python”import requestsimport 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)JavaScript
Section titled “JavaScript”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)); }}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" }'Provider Coverage
Section titled “Provider Coverage”- 2Captcha