UNLOCK API
Khoanh vùng vật thể

Khoanh vùng vật thể

Cách gửi tác vụ Khoanh vùng vật thể tới UNLOCK API bằng createTask hoặc in.php: tên loại tác vụ, mọi tham số, object solution, trường proxy và code mẫu bằng 7 ngôn ngữ.
Giá
$0.60 $0.0006 mỗi tác vụ
Bạn gửi
Ảnh dạng base64 và vật cần khoanh vùng
Bạn nhận
Các hình chữ nhật bao quanh vật thể

Tổng quan và giá

Tên loại tác vụ

Loại này chỉ có một tên.
BoundingBoxTask

Object task

type
StringBắt buộc
Tên loại tác vụ. Không phân biệt chữ hoa, chữ thường. BoundingBoxTask
body
StringBắt buộc
Ảnh dạng base64 (JPG, PNG hoặc GIF), tối đa khoảng 100 KB. Được phép có tiền tố data:.
comment
StringTùy chọn
Hướng dẫn cho người giải, ví dụ câu hỏi hiện phía trên ảnh.

Các trường không có trong danh sách này được chuyển nguyên cho người giải.

Request

POST /createTask
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "BoundingBoxTask",
    "body": "/9j/4AAQSkZJRgABAQ...",
    "comment": "Draw a box around each car"
  }
}

Object solution

Trả về trong solution khi status là ready.
bounding_boxes
Array
Khung bao quanh các vật thể được hỏi, tính bằng pixel.
POST /getTaskResult
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "bounding_boxes": [
      {
        "xMin": 12,
        "yMin": 30,
        "xMax": 140,
        "yMax": 96
      }
    ]
  },
  "cost": "0.0006",
  "createTime": 1791640000,
  "endTime": 1791640014,
  "solveCount": 1
}

Code mẫu

import time, requests

API = "https://unlock-api.com"
KEY = "YOUR_API_KEY"

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "BoundingBoxTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "comment": "Draw a box around each car"
    }
}).json()
if task["errorId"]:
    raise SystemExit(task["errorCode"])

for _ in range(60):   # 60 x 5 s = the 5 minute task limit
    time.sleep(5)
    r = requests.post(f"{API}/getTaskResult", json={"clientKey": KEY, "taskId": task["taskId"]}).json()
    if r["errorId"]:
        raise SystemExit(f"{r['errorCode']}: {r.get('errorDescription', '')}")   # failed tasks are refunded
    if r["status"] == "ready":
        print(r["solution"])
        break
else:
    raise SystemExit("timed out")

Phương thức form in.php

Cùng tác vụ đó với request form kiểu cũ. res.php trả kết quả dạng văn bản.
in.php, res.php
curl -s "https://unlock-api.com/in.php" -d "key=YOUR_API_KEY&method=bounding_box&textinstructions=Draw+a+box+around+each+car&body=BASE64_IMAGE&json=1"
# {"status":1,"request":"1001"}

curl -s "https://unlock-api.com/res.php?key=YOUR_API_KEY&action=get&id=1001&json=1"
# {"status":0,"request":"CAPCHA_NOT_READY"}  then  {"status":1,"request":"ANSWER"}

API form: in.php và res.php