OCR: Eastóscadh Téacs
Ar an leathanach seo
Téacs a Léamh in Íomhánna
Is é OCR (Aitheantas Carachtar Optúil) ceann de na cásanna úsáide is cumhachtaí do Grok Vision. Murab ionann agus uirlisí traidisiúnta nach n-eastóscaann ach carachtair, tuigeann Grok comhthéacs an téacs san íomhá, a leagan amach, agus a bhrí.
OCR Clasaiceach vs. OCR Ilmhóideach
Bíonn uirlisí OCR traidisiúnta (Tesseract, Google Vision OCR, AWS Textract) ar fheabhs ag eastóscadh amh carachtar. Cuireann Grok toise bhreise leis: tuigeann sé cad a chiallaíonn an téacs laistigh de chomhthéacs na híomhá.
Mar shampla, agus tú ag próiseáil sonraisc scanta, eastóscaíonn uirlis OCR chlasaiceach gach carachtar. Is féidir le Grok freisin:
- Réimsí a aithint (uimhir an tsocraisc, dáta, méid iomlán)
- Sonraí a struchtúrú i bhformáid inúsáidte
- Earráidí OCR a cheartú ag baint úsáide as comhthéacs
- Táblaí agus leagan amach casta a léirmhíniú
Eastóscadh Bunúsach
Chun téacs infheicthe a eastóscadh go simplí:
response = client.responses.create(
model="grok-4.5",
input=[
{
"type": "input_image",
"image_url": url_document,
"detail": "high" # Essential for OCR
},
{
"type": "input_text",
"text": "Extract all visible text in this image. Preserve the layout as much as possible."
}
],
store=False
)
Tá an paraiméadar detail: "high" riachtanach le haghaidh OCR. Sa mhód low, d’fhéadfadh an múnla téacs mín a mhíthuiscint nó carachtair áirithe a míléamh.
Eastóscadh Doiciméad Struchtúrtha
Le haghaidh doiciméad gairmiúil, iarr eastóscadh struchtúrtha:
def extraire_facture(image_url):
prompt = """This image is an invoice. Extract the following
information in JSON:
- "invoice_number": the invoice number
- "date": the issue date
- "issuer": name and address of the issuer
- "recipient": name and address of the recipient
- "lines": table with columns [description, quantity, unit_price, total]
- "subtotal": amount excluding tax
- "vat": VAT amount
- "total_incl_tax": amount including tax
If a field is not visible, indicate null."""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Eastóscadh Cárta Gnó
def extraire_carte_visite(image_url):
prompt = """Extract the information from this business card in JSON:
- "name": full name
- "title": job title/position
- "company": company name
- "email": email address
- "phone": phone number(s)
- "address": postal address
- "website": website URL
- "social_media": links to social media profiles"""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Próiseáil Scáileáin
Is cás úsáide den scoth iad scáileáin toisc go mbíonn téacs iontu go minic i leagan amach casta (roghchláir, barraí taobh, preabfhuinneoga):
def analyser_screenshot(image_url):
prompt = """Analyze this screenshot and identify:
1. The application or website displayed
2. The visible page or section
3. The main interface elements (buttons, menus, forms)
4. Any important text displayed
5. Any error messages or notifications"""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Próiseáil Bhaisc Doiciméad
Chun toirt mhór doiciméad a phróiseáil, comhcheangail OCR Grok le píblíne próiseála:
import json
async def pipeline_ocr(documents):
resultats = []
for doc in documents:
# 1. Validate the image
if not valider_image(doc["chemin"]):
resultats.append({"fichier": doc["chemin"], "erreur": "Invalid image"})
continue
# 2. Encode to base64
image_url = encoder_base64(doc["chemin"])
# 3. Extract with Grok
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": doc["prompt"]}
],
store=False
)
# 4. Parse the result
try:
data = json.loads(response.output_text)
resultats.append({"fichier": doc["chemin"], "data": data})
except json.JSONDecodeError:
resultats.append({"fichier": doc["chemin"], "texte_brut": response.output_text})
return resultats
Teorainneacha OCR Grok
- Téacs lámhscríofa: oibríonn an t-aithint go maith do scríbhneoireacht inléite, ach d’fhéadfadh sé teipthe ar scríbhneoireacht chursach nó neamh-inléite
- Teangacha neamh-Laidineacha: athraíonn an chruinneas ag brath ar an teanga agus ar an gcló a úsáidtear
- Íomhánna ísealcháilíochta: déanann scanadh ísealtaighde nó grianghraif doiléir dochar do na torthaí
- Téacs an-bheag: fiú sa mhód
high, d’fhéadfadh téacs atá níos lú ná 8 picteilín ar airde a bheith míléite
Príomhphointí
- Bain úsáid i gcónaí as
detail: "high"do thascanna OCR - Iarr eastóscadh struchtúrtha (JSON) chun na sonraí a úsáid go huathoibríoch
- Téann Grok thar OCR amh: tuigeann sé comhthéacs agus leagan amach
- Bain úsáid as
store: falsele haghaidh doiciméad íogair (sonraisce, cártaí gnó) - Bailíochtaigh agus réamhphróiseáil íomhánna chun cáilíocht an eastóscadh a uasmhéadú