import os
import dashscope
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
messages = [{
"role": "user",
"content": [{
"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg",
# 输入图像的最小像素阈值。如果图像小于该值,则图像会被放大,直到总像素数大于 min_pixels。
"min_pixels": 32 * 32 * 3,
# 输入图像的最大像素阈值。如果图像大于该值,则图像会被缩小,直到总像素数小于 max_pixels。
"max_pixels": 32 * 32 * 8192,
# 指定是否开启图像自动旋转。
"enable_rotate": False}]
}]
response = dashscope.MultiModalConversation.call(
# 如果未配置环境变量,请将下行替换为您的 API Key:api_key="sk-xxx",
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen-vl-ocr-2025-11-20',
messages=messages,
# 将内置任务设置为高精度识别。
ocr_options={"task": "advanced_recognition"}
)
# 高精度识别任务以纯文本形式返回结果。
print(response["output"]["choices"][0]["message"].content[0]["text"]){
"status_code": 0,
"request_id": "<string>",
"code": "<string>",
"message": "<string>",
"output": {
"text": "<string>",
"finish_reason": "<string>",
"choices": [
{
"finish_reason": "<string>",
"message": {
"role": "assistant",
"content": [
{
"text": "<string>",
"ocr_result": {
"kv_result": {},
"words_info": [
{
"rotate_rect": [
0
],
"location": [
0
],
"text": "<string>"
}
]
}
}
],
"logprobs": {
"content": [
{
"token": "<string>",
"bytes": [
0
],
"logprob": 0,
"top_logprobs": [
{
"token": "<string>",
"bytes": [
0
],
"logprob": 0
}
]
}
]
}
}
}
]
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"total_tokens": 0,
"characters": 0,
"image_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens_details": {
"text_tokens": 0
}
}
}