Purpose
Call the Tencent Cloud OCR General Text Recognition (High-Precision Edition) API to accurately extract text from images.
Core capabilities:
- Text recognition: High-precision recognition of text content in images, returning the complete recognized text
- PDF support: Supports text recognition for PDF files (single page)
- Single-character information: Optionally returns the position and confidence information of each single character
- Multilingual resume structured recognition: Based on OCR results, performs structured extraction and formatted output for resumes (see
references/resume-parsing.md)
Official documentation:https://cloud.tencent.com/document/api/866/37831
📚 Available resources
References (scenario-based guidance)
references/resume-parsing.md- Multilingual resume structured recognition guide (processing flow, Prompt templates, output formatting templates, formatting rules)
When to use
This skill is triggered when the user raises the following needs:
- Need to extract text content from images or PDFs
- Need to perform text recognition on various documents, images, etc.
- Any scenario involving general text OCR recognition
- Need to recognize and structurally extract resume information from resume images/PDFs (please refer to
references/resume-parsing.mdguide) - Need to recognize and format multilingual resumes for output (please refer to
references/resume-parsing.mdguide)
Environment requirements
- Python 3.6+
- Dependency:
tencentcloud-sdk-python(viapip install tencentcloud-sdk-pythoninstallation) - Environment variables:
TENCENTCLOUD_SECRET_ID: Tencent Cloud API key IDTENCENTCLOUD_SECRET_KEY: Tencent Cloud API key Key
Usage
Run the scripts/main.py script to complete text recognition.
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| ImageBase64 | str | No (choose one of two) | Image Base64 value, no more than 10MB |
| ImageUrl | str | No (choose one of two) | Image URL address, preferred |
| IsPdf | bool | No | Whether to enable PDF recognition, default false |
| PdfPageNumber | int | No | PDF page number to recognize, valid when IsPdf is true, default 1 |
| IsWords | bool | No | Whether to return single-character information, default false |
| UserAgent | str | No | Request source identifier (optional), used to track the call source, uniformly fixed asSkills |
⚠️ UserAgent parameter usage guide
--user-agentThe parameter is optional, uniformly fixed asSkills, no manual passing required. Used to identify the API call source for tracking and statistics:
| Calling framework | --user-agent parameter value | Description |
|---|---|---|
| All frameworks | Skills |
Uniform fixed value, also defaults to this value when not passed |
Implementation Notes:
- via
--user-agentpassed through command-line arguments, the SDK will concatenate them asSDK_PYTHON_x.x.x; Skillsinjected into the request - uniformly fixed to
Skills, and defaults to this value when not passed - this identifier will be recorded in the ES log's
ReqBody.RequestClientfield, which can be used to trace the source
Output Format
Return a JSON format result after successful recognition:
{
"raw_text": "识别到的完整文字内容\n第二行文字\n第三行文字",
"RequestId": "xxx"
}
Return when there is no text:
{
"raw_text": "",
"message": "No text detected in the image.",
"RequestId": "xxx"
}
Usage Example
# 基础调用示例(--user-agent 默认为 Skills,可不传)
python scripts/main.py --image-url "https://example.com/document.jpg"
# 使用 Base64 文件调用
python scripts/main.py --image-base64 "/path/to/document.jpg"
# 识别 PDF 文件中的文字
python scripts/main.py --image-url "https://example.com/doc.pdf" \
--is-pdf true --pdf-page-number 1
# 返回单字信息
python scripts/main.py --image-url "https://example.com/document.jpg" --is-words true
Key Configuration
Step 1: Obtain/Purchase OCR Service
🔗 Tencent Cloud Optical Character Recognition OCR Purchase Page
On the purchase page, select General Text Recognition (High Precision Edition) to complete the purchase.
Step 2: Obtain API Key
🔗 Tencent Cloud API Key Management
Step 3: Set Environment Variables
Linux / macOS:
export TENCENTCLOUD_SECRET_ID="你的SecretId"
export TENCENTCLOUD_SECRET_KEY="你的SecretKey"
Windows (PowerShell):
$env:TENCENTCLOUD_SECRET_ID = "你的SecretId"
$env:TENCENTCLOUD_SECRET_KEY = "你的SecretKey"