OCR ImageToText
WARNING
Create the task with the createTask.
This interface does not need to obtain the results separately, will directly return the image recognition results!
The task type
field is as follows
ImageToTextTask
Create Task
Create the task with the createTask.
Task Object Structure
Note that this type of task returns the task execution result directly after createTask, rather than getting it asynchronously through getTaskResult.
Properties | Type | Required | Description |
---|---|---|---|
type | String | Required | ImageToTextTask |
websiteURL | String | Optional | Page source url to improve accuracy |
body | String | Required | base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,) |
images | List[string] | Optional | Only for number module, Support up to 9 base64 encoded images each time |
module | String | Optional | Specifies the module. All supported models are shown in the table below |
score | Float | Optional | 0.8 ~ 1 , Identify the matching degree. If the recognition rate is not within the range, no deduction |
Independent module support
Module | Questions | Samples | Accuracy | LastUpdate |
---|
Example Request
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ImageToTextTask",
"websiteURL": "https://xxxx.com",
// You can choose the module you need to use
// ocr single image model, default common
"module": "common",
// base64 encoded image
"body": "/9j/4AAQSkZJRgABA......"
}
}
If there are only numbers in the picture, it’s recommended that you use the number
module. Example Request:
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ImageToTextTask",
"websiteURL": "https://xxxx.com",
"module": "number",
// Put up to 9 images
"images": [
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA..."
]
}
}
Example Response
{
"errorId": 0,
"errorCode": "",
"errorDescription": "",
"status": "ready",
"solution": {
"text": "44795sds",
// number module:
"answers": ["100", "1330", "147", "248", "303", "439", "752", "752", "752"],
},
"taskId": "..."
}
Use SDK Request
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
# capsolver.api_key = "..."
img_path = os.path.join(Path(__file__).resolve().parent, "queue-it.jpg")
with open(img_path, 'rb') as f:
solution = capsolver.solve({
"type": "ImageToTextTask",
"module": "common",
"body": "/9j/4AAQSkZJRgABA......"
})
print(solution)