图像理解
Gemini 可以接收图片并进行问答、截图分析、票据识别、图表理解和多图对比。图像输入通过 contents[].parts 的 inlineData 传入。
支持的图像输入方式
常见方式是把图片转为 base64,并在内容块中声明媒体类型。
json
{
"contents": [
{
"parts": [
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_DATA"
}
},
{
"text": "Analyze the main content of this image"
}
]
}
]
}图片问答
图片问答适合识别画面内容、解释界面状态、读取可见文本、描述图表趋势。
text
First describe what can be determined from the image, then list anything uncertain that may need manual review.截图分析
截图分析适合前端页面检查、报错定位、后台表格解释和流程说明。
建议提示词:
text
Analyze this admin screenshot. Identify the current page, key data, possible abnormal states, and recommended next steps.表格、票据和图表理解
处理票据、表格和图表时,建议要求模型输出结构化摘要,并提醒它不要猜测看不清的内容。
text
Extract merchant name, date, amount, and line items from the image. Use null for unreadable fields and do not guess.多图输入
多图输入适合前后对比、流程图分析、同一订单的多张凭证核对等场景。
json
{
"contents": [
{
"parts": [
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_1"
}
},
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_2"
}
},
{
"text": "Compare the differences between these two images"
}
]
}
]
}图像大小和格式注意事项
- 图片会计入请求体大小和模型输入成本
- 上传前尽量裁剪无关区域
- 截图类图片建议保持文字清晰
- 票据和表格不要过度压缩
- 大图或多图任务要注意接口请求大小限制
视觉任务最佳实践
- 明确告诉模型要提取什么字段
- 要求区分“确定信息”和“无法确认的信息”
- 对金额、时间、证件号等关键字段进行人工或规则复核
- 对图像理解结果进行服务端校验
- 不要让模型单独承担高风险审核决策