載入中
載入中

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

圖像處理基礎

一張投影片,展示較舊版本的圖像限制和權杖計算公式,旁邊也顯示了 base64 圖像區塊程式碼。

在 Claude 中使用圖像時,您需要了解以下幾項關鍵限制:

  • 單一請求中,所有訊息加總最多可包含 100 張圖像
  • 每張圖像經過 base64 編碼後,大小上限為 10MB
  • 傳送單張圖像時:最大高度/寬度為 8000px
  • 傳送多張圖像時:最大高度/寬度為 2000px
  • 圖像只能以 base64 編碼方式包含
  • 每張圖像根據尺寸計算權杖數:tokens = ⌈width / 28⌉ × ⌈height / 28⌉

若要包含圖像,您需要在使用者訊息中加入圖像區塊,並與文字區塊並列。以下是其結構:

python
import base64

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 則以分析該圖像的文字訊息回覆。

提示技巧

一則使用者訊息,內含 12 顆彈珠的照片及計數問題,Claude 的回覆是 13 顆彈珠,並以紅色叉號標記。

關於 Claude 視覺能力,最重要的理解是:良好的提示技巧絕對至關重要。即使圖像清晰,簡單的提示往往會產生不佳的結果。

舉例來說,若對一張包含 12 顆彈珠的圖像詢問「這張圖片裡有多少顆彈珠?」,可能會得到錯誤的計數結果 13 顆。您可以透過套用與文字提示相同的提示工程技巧,大幅提升準確度:

  • 提供詳細的準則與分析步驟
  • 使用單次或多次範例(one-shot 或 multi-shot)
  • 將複雜任務拆解成較小的步驟

逐步分析

一張彈珠照片與逐步計數提示傳送給 Claude,其回覆「我在這張圖片中數到 12 顆彈珠」是正確的。

與其提出一個簡單的問題,不如向 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 得出正確的 12 顆彈珠計數結果。

單次範例(One-Shot)

一張標示為 11 顆彈珠的範例照片,接著是目標照片;Claude 正確回覆「我在這張圖片中數到 12 顆彈珠」。

您也可以在單一訊息中加入多組圖像-文字配對,採用單次提示(one-shot prompting):

[Image of 11 marbles]
The image above has 11 marbles in it.

[Image of 12 marbles]  
How many marbles are 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
   - 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 points of vulnerability
   - 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 進行系統化分析,產生準確且可行動的火災風險評估結果。在測試一處樹木覆蓋密集的房產時,Claude 正確地將其判定為「3(高風險)」,原因是該建築周圍有顯著的樹木懸垂及相連的樹冠。

關鍵結論是:Claude 的視覺能力雖然強大,但仍需要您投入與處理任何複雜任務時相同程度的細心提示工程。請花時間建立詳細、結構化的提示,而不要僅僅依賴簡單的問題。