UNLOCK API
Bounding box

Bounding box

Cara menghantar tugas Bounding box ke UNLOCK API dengan createTask atau in.php: nama jenis tugas, setiap parameter, objek solution, medan proxy dan contoh kod dalam 7 bahasa.
Harga
$0.60 $0.0006 setiap tugas
Anda hantar
Imej dalam base64 dan apa yang perlu ditanda
Anda terima
Segi empat di sekeliling objek

Ringkasan dan harga

Nama jenis tugas

Jenis ini ada satu nama.
BoundingBoxTask

Objek task

type
StringWajib
Nama jenis tugas. Dipadankan tanpa mengira huruf besar atau kecil. BoundingBoxTask
body
StringWajib
Imej sebagai base64 (JPG, PNG atau GIF), sehingga kira-kira 100 KB. Awalan data: dibenarkan.
comment
StringPilihan
Arahan untuk penyelesai, contohnya soalan yang dipaparkan di atas imej.

Medan yang tidak disenaraikan di sini dihantar kepada penyelesai seperti yang dihantar.

Permintaan

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

Objek solution

Dipulangkan dalam solution apabila status ialah ready.
bounding_boxes
Array
Kotak di sekeliling objek yang diminta, dalam piksel.
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
}

Contoh kod

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")

Kaedah borang in.php

Tugas yang sama dengan permintaan borang klasik. res.php memulangkan jawapan sebagai teks.
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 borang: in.php dan res.php