Pattern Matching 是什麼?
Pattern Matching(圖樣比對 / 圖樣匹配)是工業視覺最基礎也最重要的技術:給定一個「標準樣本」,在「檢測影像」中找出該樣本的位置與角度。
幾乎所有工業視覺檢測流程都從 Pattern Matching 開始:
- 找到工件位置 — Pattern Matching 定位
- 以工件為參考 — 後續工具(量測、OCR、條碼讀取)才能對齊
- 執行檢測
如果 Pattern Matching 失敗,後續所有檢測都失敗。
Pattern Matching 演算法演進
| 世代 | 演算法 | 原理 | 缺點 |
|---|---|---|---|
| 第 1 代(1980s) | NCC(Normalized Cross Correlation) | 像素灰階值比對 | 對光照敏感、不抗旋轉 |
| 第 1 代 | SAD(Sum of Absolute Differences) | 像素差值總和 | 同 NCC |
| 第 2 代(1990s) | 基於邊緣 | 邊緣像素比對 | 部分抗旋轉但精度有限 |
| 第 3 代(2000s+) | 幾何 Pattern Matching | 幾何邊緣特徵比對 | 抗旋轉、抗縮放、抗光照 |
Cognex PatMax 為第 3 代幾何 Pattern Matching 的代表演算法(1990 年代後期推出),達到 sub-pixel 精度。
傳統 NCC vs 現代幾何 Pattern Matching
| 比較 | NCC(像素灰階) | PatMax(幾何邊緣) |
|---|---|---|
| 比對方式 | 像素灰階差值 | 幾何邊緣特徵 |
| 精度 | ±1 pixel | ±0.05 pixel(sub-pixel) |
| 旋轉容忍 | 0°(需多樣本) | 360° 任意角度 |
| 縮放容忍 | 固定 | ±50% |
| 光照變化 | 敏感 | 抗光照 |
| 部分遮擋 | 失敗 | 可容忍部分遮擋 |
| 計算速度 | 快 | 略慢但夠用(毫秒級) |
Pattern Matching 5 大應用
1. 機械手臂視覺引導
- Pattern Matching 找到工件位置(X, Y, θ)→ 告訴機械手臂去取放
- 要求:sub-pixel 精度(PatMax 必選)
2. SMT 對位
- 印刷電路板上的 fiducial mark 定位
- 要求:±0.05 mm 精度
3. 半導體 Wafer / IC 載板定位
- Wafer notch 定位、IC 載板對齊
- 要求:超高精度(PatMax / PatMax AlignPlus)
4. 組裝對位
- 螺絲孔對位、零件嵌入位置確認
- 要求:抗旋轉、抗縮放
5. 條碼 / OCR 預定位
- Pattern Matching 先找條碼 / 字元區域 → 再讀取
- 要求:穩定快速
Pattern Matching vs AI 深度學習(ViDi Locate)
| 場景 | Pattern Matching(規則式) | ViDi Locate(AI) |
|---|---|---|
| 形狀明確物件 | ✅ 最佳 | overkill |
| 變異大物件 | ❌ 失敗 | ✅ 最佳 |
| 訓練樣本 | 1 張即可 | 30-300 張 |
| 計算速度 | 毫秒級 | 50-200 ms |
| 部署簡易度 | 高 | 中 |
多數工業應用(85%)用 Pattern Matching(PatMax)即可。變異大物件才用 ViDi Locate。
哪些 Cognex 工具支援 Pattern Matching?
Cognex 各層級 Pattern Matching 工具:
- PatMax — 幾何邊緣比對、sub-pixel 精度(1990 年代後期推出)
- PatMax AlignPlus — PatMax 升級版(速度 ×2-3)
- PatMax RedLine — 高速優化版本
- Symmetry Tool — 對稱形狀專用
- Edge Tools — 邊緣比對(簡單應用)
In-Sight 智慧相機與 VisionPro 軟體都內建這些工具。
工程師常見問題
Q1:Pattern Matching 訓練要多少樣本?
A:傳統 Pattern Matching(PatMax)只需要 1 張標準樣本。AI 深度學習版(ViDi Locate)需要 30-300 張。
Q2:Pattern Matching 對哪些情況失敗?
A:
- 物件形狀完全變異(如皮革紋路、自然物件)→ 改用 ViDi Locate
- 物件嚴重遮擋(> 70%)→ 補光或改視角
- 光照變化極端 → 用 PatMax(抗光照變化)
Q3:Pattern Matching 速度多快?
A:實際速度受影像大小、圖樣複雜度與機型運算能力影響,通常為毫秒級;PatMax AlignPlus 較 PatMax 有明顯速度提升。具體 FPS 請以您的應用實測為準。
Q4:為何 sub-pixel 精度重要?
A:機械手臂視覺引導需要 ±0.05mm 精度。如果像素相當於 0.1mm,pixel 精度(±1 pixel)只有 ±0.1mm,sub-pixel(±0.05 pixel)才能達 ±0.005mm 精度。
想用 Pattern Matching 解決定位問題?
VSK 提供完整選型服務:
- PatMax vs AlignPlus vs ViDi Locate — VSK 依您場景建議
- 燈光鏡頭設計 — 影響 Pattern Matching 成敗的關鍵
- 訓練樣本協助 — 教您拍出最佳 Pattern Matching 樣本
請提供 OK / NG 樣品照片,VSK 評估後會盡快與您聯繫。
