UNLOCK API
Dibujar contorno

Dibujar contorno

Cómo enviar una tarea de Dibujar contorno a UNLOCK API con createTask o in.php: nombres del tipo de tarea, todos los parámetros, el objeto solution, los campos de proxy y ejemplos de código en 7 lenguajes.
Precio
$0.60 $0.0006 por tarea
Envías
La imagen en base64 y alrededor de qué hay que dibujar
Recibes
Puntos del contorno dibujado

Resumen y precio

Nombres del tipo de tarea

Este tipo tiene un solo nombre.
DrawAroundTask

Objeto de tarea

type
StringObligatorio
Nombre del tipo de tarea. Se reconoce sin importar mayúsculas o minúsculas. DrawAroundTask
body
StringObligatorio
La imagen en base64 (JPG, PNG o GIF), de hasta unos 100 KB. Se permite un prefijo data:.
comment
StringOpcional
Instrucción para el resolvedor, por ejemplo la pregunta que aparece sobre la imagen.

Los campos que no aparecen aquí se pasan al resolvedor tal como se envían.

Solicitud

POST /createTask
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "DrawAroundTask",
    "body": "/9j/4AAQSkZJRgABAQ...",
    "comment": "Draw around the dog"
  }
}

Objeto solution

Se devuelve en solution cuando status es ready.
canvas
Array
Contorno trazado alrededor del objeto, como lista de puntos.
POST /getTaskResult
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "canvas": [
      [
        {
          "x": 10,
          "y": 20
        },
        {
          "x": 60,
          "y": 22
        },
        {
          "x": 58,
          "y": 80
        }
      ]
    ]
  },
  "cost": "0.0006",
  "createTime": 1791640000,
  "endTime": 1791640014,
  "solveCount": 1
}

Ejemplos de código

import time, requests

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

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "DrawAroundTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "comment": "Draw around the dog"
    }
}).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")

Método de formulario in.php

La misma tarea con la solicitud de formulario clásica. res.php devuelve la respuesta como texto.
in.php, res.php
curl -s "https://unlock-api.com/in.php" -d "key=YOUR_API_KEY&method=base64&canvas=1&textinstructions=Draw+around+the+dog&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 de formulario: in.php y res.php