Riferimento API
Rilevamento del testo
Rileva le etichette di testo in un’immagine prima di modificarle con un’operazione `replace_text`.
Richiesta e risposta#
POST /images/text-detections con {"image": "<file_id>"} e un Idempotency-Key. Ambito richiesto: figures:generate. Gratuito. Risponde in modo sincrono con 200:
{
"id": "c222cd46-d923-4abf-aa28-cdc72ad06623",
"object": "text_detection",
"width": 2048,
"height": 1536,
"texts": [
{ "index": 0, "text": "Nucleus", "corners": [{ "x": 75, "y": 260 }, { "x": 241, "y": 260 }, { "x": 241, "y": 295 }, { "x": 75, "y": 295 }] }
]
}textssegue l’ordine di lettura;cornerscontiene le coordinate in pixel di ogni etichetta nell’immagine.- Ripetere la stessa chiave restituisce lo stesso rilevamento senza eseguirlo nuovamente; la stessa chiave con un’altra immagine restituisce
409 IDEMPOTENCY_CONFLICT. - I rilevamenti condividono con il sito il limite di 20 ogni 15 minuti per account; oltre tale limite la risposta è
429 RATE_LIMITED. - Passa l’
idcon la stessa immagine a una modificareplace_text. Funziona solo per quell’immagine e per il tuo account. - L’immagine è un
file_iddi PNG, JPEG o WebP. Un errore temporaneo del riconoscimento del testo restituisce503 SERVICE_UNAVAILABLEconRetry-After: riprova con la stessa chiave. Un rilevamento eseguito senza risultati restituisce502 TASK_FAILEDconTEXT_DETECTION_FAILED: invialo di nuovo con una nuova chiave.
cURL#
curl -X POST https://scifig.ai/api/v1/images/text-detections \
-H "Authorization: Bearer $SCIFIG_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=25" \
-H "Content-Type: application/json" \
-d '{
"image": "<file_id>"
}'JavaScript#
const response = await fetch('https://scifig.ai/api/v1/images/text-detections', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
Prefer: 'wait=25',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"image": "<file_id>"
}),
});
const result = await response.json();
console.log(response.status, result);Python#
import os
import uuid
import requests
headers = {
"Authorization": f"Bearer {os.environ['SCIFIG_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
"Prefer": "wait=25",
}
response = requests.post(
"https://scifig.ai/api/v1/images/text-detections",
headers=headers,
json={
"image": "<file_id>"
},
timeout=60,
)
print(response.status_code, response.json())