TrOCR
Use Microsoft's TrOCR for text recognition on a Dedicated Deployment or self-hosted Inference
Code sample
pip install requests opencv-pythonimport base64
import os
import urllib.request
import cv2
import requests
URL = "https://your-deployment.roboflow.cloud"
IMAGE_URL = "https://media.roboflow.com/inference/license_plate_1.jpg"
IMAGE_PATH = "license_plate.jpg"
urllib.request.urlretrieve(IMAGE_URL, IMAGE_PATH)
image = cv2.imread(IMAGE_PATH)
_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")
response = requests.post(
f"{URL}/ocr/trocr",
json={
"api_key": os.getenv("API_KEY"),
"image": {"type": "base64", "value": image_base64},
},
)
print(response.json()["result"])Last updated
Was this helpful?