Claude 的視覺能力讓您可以在訊息中包含圖片,並要求 Claude 以各種方式進行分析。您可以要求 Claude 描述圖片中的內容、比較多張圖片、計算物件數量,或執行複雜的視覺分析任務。
圖片處理基礎

在處理圖片時,有幾個重要的限制需要牢記:
- 單次請求中所有訊息最多可包含 600 張圖片(上下文視窗為 200K token 的模型最多 100 張)
- 每張圖片最大為 10MB(以 base64 編碼後的大小計算)
- 傳送單張圖片時:最大高度/寬度為 8000px
- 傳送多張圖片時:最大高度/寬度為 2000px
- 圖片可以以 base64 編碼或圖片 URL 的形式包含
- 每張圖片根據其尺寸計算為 token 數:
tokens = ⌈width / 28⌉ × ⌈height / 28⌉
要將圖片傳送給 Claude,您需要在使用者訊息中包含一個圖片區塊,並與文字區塊並列。以下是其結構:
python
with open("image.png", "rb") as f:
image_bytes = base64.standard_b64encode(f.read()).decode("utf-8")
add_user_message(messages, [
# 圖片區塊
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_bytes,
}
},
# 文字區塊
{
"type": "text",
"text": "What do you see in this image?"
}
])訊息流程

對話的運作方式與純文字互動完全相同。您的伺服器會傳送一則包含圖片和文字區塊的使用者訊息給 Claude,而 Claude 會以包含其分析結果的文字區塊作為回應。
提示技巧

要在圖片方面獲得良好結果的關鍵,在於應用與文字相同的提示工程技巧。簡單的提示通常會導致不佳的結果。例如,詢問「這張圖片中有多少顆彈珠?」可能會得到不正確的計數。
您可以透過以下方式大幅提升 Claude 的準確度:
- 提供詳細的指引和分析步驟
- 使用單樣本(one-shot)或多樣本(multi-shot)範例
- 將複雜任務拆解為較小的步驟
逐步分析

與提出簡單問題不同,為 Claude 提供一套方法論:
Analyze this image of marbles and determine the exact count using this methodology:
1. Begin by identifying each unique marble one at a time. Assign each a number as you identify it.
2. Verify your result by counting with a different method. Start from the bottom-left corner and work row by row, from left to right.
What is the exact, verified number of marbles in this image?單樣本範例

您也可以透過在訊息中提供範例來提升準確度。包含一張已知數量的圖片,說明正確答案,然後再詢問您的目標圖片。這能為 Claude 提供一個參考點,了解您想要的分析類型。
實際案例:火災風險評估

以下是一個實際應用:為住宅保險自動化火災風險評估。保險公司無需派遣檢查員前往每個物業,而是可以使用衛星影像和 Claude 的分析。
該系統分析衛星影像以識別:
- 住宅附近密集、緊密排列的樹木
- 緊急服務難以進入的通道
- 懸垂在住宅上方的樹枝
與「提供火災風險評分」這類簡單提示不同,結構良好的提示會將分析拆解為具體步驟:
Analyze the attached satellite image of a property with these specific steps:
1. Residence identification: Locate the primary residence on the property by looking for:
- The largest roofed structure
- Typical residential features (driveway connection, regular geometry)
- Distinction from other structures (garages, sheds, pools)
2. Tree overhang analysis: Examine all trees near the primary residence:
- Identify any trees whose canopy extends directly over any portion of the roof
- Estimate the percentage of roof covered by overhanging branches (0-25%, 25-50%, 50-75%, 75%+)
- Note particularly dense areas of overhang
3. Fire risk assessment: For any overhanging trees, evaluate:
- Potential wildfire vulnerability (ember catch points, continuous fuel paths to structure)
- Proximity to chimneys, vents, or other roof openings if visible
- Areas where branches create a "bridge" between wildland vegetation and the structure
4. Defensible space identification: Assess the property's overall vegetative structure:
- Identify if trees connect to form a continuous canopy over or near the home
- Note any obvious fuel ladders (vegetation that can carry fire from ground to tree to roof)
5. Fire risk rating: Based on your analysis, assign a Fire Risk Rating from 1-4:
- Rating 1 (Low Risk): No tree branches overhanging the roof, good defensible space around the home
- Rating 2 (Moderate Risk): Minimal overhang (<25% of roof), some separation between tree canopies
- Rating 3 (High Risk): Significant overhang (25-50% of roof), connected tree canopies, multiple vulnerability points
- Rating 4 (Severe Risk): Extensive overhang (>50% of roof), dense vegetation against structure
For each item above (1-5), write one sentence summarizing your findings, with your final response being the numerical rating.這個詳細的提示引導 Claude 進行系統性分析,相較於簡單的請求,能產生更準確且更有用的評估結果。
請記住:適用於文字的相同提示技巧也適用於圖片。如果您想要獲得可靠的結果,請投入時間精心設計詳細、結構化的提示,而不是依賴簡單的問題。