> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-ja/application/image-vision/id-card-recognition.md).

# 証明書認識

企業が本人確認、口座開設、受付などの業務を処理する際には、証明書に記載された氏名、身分証番号、住所などの情報を担当者が一件ずつ手入力する必要があることが多く、手間がかかるうえにミスも発生しやすいものです。MaiAgent のマルチモーダル AI アシスタントを利用すれば、ユーザーは証明書の写真をアップロードするだけで、システムが自動的に認識して構造化された JSON データを出力し、後続の業務システムへそのまま連携できます。

従来の OCR ソリューションと比較して、MaiAgent は大規模言語モデルのマルチモーダル能力を組み合わせており、次のような優位性を備えています。

|          | 従来の OCR エンジン               | MaiAgent マルチモーダル AI          |
| -------- | -------------------------- | ---------------------------- |
| レイアウト適応性 | 証明書の種類ごとにテンプレートを設計する必要がある  | 異なる証明書のレイアウトを自動的に理解          |
| 表裏面の処理   | 別々に処理して手動で対応付ける必要がある       | 1 枚の画像で表面と裏面を同時に認識可能         |
| 項目の拡張    | プログラムコードの修正が必要             | JSON Schema を修正するだけで対応可能     |
| 導入コスト    | OCR サービスの自社構築またはライセンス購入が必要 | プラットフォーム上で設定するだけで、プログラム作成は不要 |
| エラー処理    | 元のテキストを返すため、後処理が必要         | AI が意味を理解し、フォーマットを自動修正       |

## 活用シーン <a href="#use-cases" id="use-cases"></a>

* **金融業の口座開設**：顧客が身分証明書をアップロードすると、氏名や証番号などの情報を自動的に抽出して口座開設フォームに入力
* **人事の受付フロー**：新入社員が証明書をアップロードすると、システムが自動的にデータを登録
* **医療機関の受付**：患者が健康保険証や身分証明書をアップロードすると、基本情報を自動入力
* **行政機関の窓口**：来庁者が証明書を提示すると、即座に認識して申請フォームに反映

## ソリューション構成 <a href="#solution-architecture" id="solution-architecture"></a>

```mermaid
graph LR
  使用者 -->|証明書画像をアップロード| AI助理["証明書 OCR 認識アシスタント<br/>（マルチモーダル LLM）"]
  AI助理 -->|認識 + 構造化| JSON輸出["JSON Schema 出力"]

  JSON輸出 --> WebChat["Web Chat でリアルタイム表示"]
  JSON輸出 --> API["API で業務システムに連携"]

  AI助理 -.->|ロール指示| 辨識規則["認識ルール<br/>表裏面の項目対応"]
  AI助理 -.->|出力フォーマット| Schema["JSON Schema<br/>9 個の標準項目"]
```

## 構築手順 <a href="#setup-steps" id="setup-steps"></a>

### Step 1：AI アシスタントの作成 <a href="#step1-create-ai-agent" id="step1-create-ai-agent"></a>

1. 左側メニュー → <mark style="color:blue;">**AI 機能**</mark> → <mark style="color:blue;">**AI アシスタント**</mark>
2. 右上の <mark style="color:blue;">**AI アシスタントを作成**</mark> をクリック
3. 基本設定を入力します：

| 項目           | 入力内容                                |
| ------------ | ----------------------------------- |
| **アシスタント名**  | 証明書 OCR 認識アシスタント                    |
| **大規模言語モデル** | Gemini 3.1 Flash-Lite（マルチモーダル対応が必要） |

<figure><img src="/files/drKbdGeI22wN27131Cud" alt=""><figcaption><p>AI アシスタントの基本設定</p></figcaption></figure>

{% hint style="info" %}
大規模言語モデルを選択する際は、そのモデルが**マルチモーダル**（画像入力）に対応していることを確認してください（例：Gemini シリーズ）。テキスト専用モデルを選んだ場合、画像の内容を認識できません。
{% endhint %}

### Step 2：応答モードと JSON Schema の設定 <a href="#step2-configure-reply-mode-and-json-schema" id="step2-configure-reply-mode-and-json-schema"></a>

<mark style="color:blue;">**応答モード設定**</mark> タブに切り替えます：

| 項目           | 入力内容           |
| ------------ | -------------- |
| **応答モード**    | RAG 問答         |
| **出力フォーマット** | JSON フォーマットで出力 |

<mark style="color:blue;">**JSON フォーマットで出力**</mark> を選択したら、下部の JSON Schema 欄に以下の内容を入力します：

```json
{
  "type": "object",
  "properties": {
    "document_type": {
      "type": "string",
      "description": "証明書の種類。例：中華民国国民身分証、運転免許証、パスポート、健康保険証、居留証など"
    },
    "name": {
      "type": "string",
      "description": "証明書名義人の氏名（フルネーム）。表面の氏名欄から読み取る"
    },
    "gender": {
      "type": "string",
      "enum": ["男", "女"],
      "description": "性別"
    },
    "date_of_birth": {
      "type": "string",
      "description": "生年月日。民国年フォーマット"
    },
    "military_service": {
      "type": ["string", "null"],
      "description": "兵役区分。例：免役、服役済み、未服役、代替役など。女性または該当欄がない場合は null"
    },
    "place_of_birth": {
      "type": ["string", "null"],
      "description": "出生地。裏面から読み取る"
    },
    "id_number": {
      "type": "string",
      "description": "身分証統一番号。英字 1 文字 + 数字 9 桁"
    },
    "expiry_or_issue_date": {
      "type": ["string", "null"],
      "description": "発行日または有効期限。民国年フォーマット"
    },
    "address": {
      "type": ["string", "null"],
      "description": "完全な住所。裏面の住所欄から読み取り、県市・区・里・鄰・路段・巷弄・号・階を含む"
    }
  },
  "required": [
    "document_type", "name", "gender", "date_of_birth",
    "military_service", "place_of_birth", "id_number",
    "expiry_or_issue_date", "address"
  ]
}
```

<figure><img src="/files/KbA167xrSnVGXOuC6xVH" alt=""><figcaption><p>JSON Schema 出力フォーマットの設定</p></figcaption></figure>

### Step 3：ロール指示の作成 <a href="#step3-write-system-prompt" id="step3-write-system-prompt"></a>

同じタブの <mark style="color:blue;">**ロール指示**</mark> ブロックに、以下の内容を入力します：

```
あなたはプロの証明書 OCR 認識アシスタントです。ユーザーが証明書画像をアップロードしますので、画像内のすべての文字を注意深く認識し、重要な情報を抽出してください。

## 最重要：画像全体のすべての領域を注意深くスキャンする

⚠️ ユーザーは同じ画像内に証明書の表面と裏面を一緒に撮影している（左右に並べる、または上下に並べる）ことがよくあります。あなたは必ず次のとおり処理してください：
1. まず画像全体をスキャンし、画像内に証明書の面がいくつあるか（1 面か 2 面か）を認識する
2. それぞれの領域の文字を個別に認識する
3. 表面と裏面の情報を統合して結果に記入する

画像全体のすべての領域で本当にその情報が見つからない場合を除き、「裏面が提供されていません」や「情報が画像内にありません」と述べることは絶対にしないでください。

## 中華民国国民身分証の項目位置

### 表面（国旗・写真あり）
- 「氏名」：写真の横。これは証明書名義人本人の氏名
- 「生年月日」：民国 XX 年 XX 月 XX 日
- 「性別」：「男」または「女」と表示
- 「統一番号」：下部。英大文字 1 文字 + 数字 9 桁
- 「発行日」：下部左側

### 裏面（父母・配偶者欄あり、背景は通常やや暗い）
- 「父」「母」：父母の氏名（名義人ではない）
- 「配偶者」：配偶者の氏名
- 「兵役区分」：兵役の状態
- 「出生地」：例「臺北市」「新北市」
- 「住所」：完全な戸籍上の住所

## 認識ルール
1. 証明書の種類：外観から判断する
2. 氏名：必ず表面の「氏名」欄から読み取り、裏面の父／母／配偶者と読み違えないこと
3. 性別：表面から読み取る
4. 生年月日：表面から読み取り、民国年フォーマットとする
5. 兵役区分：裏面から読み取る。女性は通常兵役区分がないため null を記入
6. 出生地：裏面から読み取る
7. 身分証番号：表面下部から読み取り、一文字ずつ注意深く認識する
8. 発行日：表面の「発行日」欄から読み取る
9. 住所：裏面の「住所」欄から読み取り、県市・区・里・鄰・路段・巷弄・号・階を完全に含める

## 出力に関する注意事項
- 認識できない項目には null を記入する
- すべての認識結果は画像の内容に忠実でなければならず、推測や捏造をしてはならない
```

<figure><img src="/files/XrTpQcTcGy5EMXQrsUP6" alt=""><figcaption><p>ロール指示の設定</p></figcaption></figure>

<mark style="color:blue;">**保存**</mark> をクリックして、アシスタントの作成を完了します。

### Step 4：認識結果のテスト <a href="#step4-test-recognition" id="step4-test-recognition"></a>

1. アシスタントの <mark style="color:blue;">**テスト対話**</mark> に入る
2. 証明書画像を 1 枚アップロードする（表裏面の両方を含めても可）
3. 「この証明書画像を認識してください」と入力する
4. 返却された JSON 構造と項目の内容が正しいことを確認する

<figure><img src="/files/MsXOi0422xlpqemeot5s" alt=""><figcaption><p>証明書認識のテスト結果</p></figcaption></figure>

## 使用例 <a href="#usage-examples" id="usage-examples"></a>

身分証の表裏面を含む画像を 1 枚アップロードすると、AI アシスタントが自動的に認識して構造化された JSON を出力します：

```json
{
  "document_type": "中華民國國民身分證",
  "name": "陳筱玲",
  "gender": "女",
  "date_of_birth": "民國57年6月5日",
  "military_service": null,
  "place_of_birth": "臺北市",
  "id_number": "A234567890",
  "expiry_or_issue_date": "民國94年7月1日",
  "address": "臺北市內湖區葫洲里1鄰民權東路六段283巷165弄218號"
}
```

{% hint style="warning" %}
認識の精度は画像の品質に左右されます。撮影時は十分な明るさを確保し、反射を避け、証明書を平らに置いて撮影することをおすすめします。表裏面を同時に撮影する場合は、左右または上下に並べることをおすすめします。
{% endhint %}

## JSON 出力項目の説明 <a href="#json-output-field-reference" id="json-output-field-reference"></a>

| 項目                     | 型           | 取得元 | 説明        |
| ---------------------- | ----------- | --- | --------- |
| `document_type`        | string      | 表面  | 証明書の種類    |
| `name`                 | string      | 表面  | 名義人の氏名    |
| `gender`               | string      | 表面  | 性別（男／女）   |
| `date_of_birth`        | string      | 表面  | 生年月日（民国年） |
| `military_service`     | string/null | 裏面  | 兵役区分      |
| `place_of_birth`       | string/null | 裏面  | 出生地       |
| `id_number`            | string      | 表面  | 身分証統一番号   |
| `expiry_or_issue_date` | string/null | 表面  | 発行日       |
| `address`              | string/null | 裏面  | 完全な住所     |

## API 連携 <a href="#api-integration" id="api-integration"></a>

このアシスタントは MaiAgent API を通じて業務システムに連携でき、証明書認識フローを自動化できます。

### 呼び出しフロー <a href="#call-flow" id="call-flow"></a>

```mermaid
sequenceDiagram
    participant Client as 業務システム
    participant API as MaiAgent API
    participant Bot as OCR 認識アシスタント

    Client->>API: POST /attachments-upload/<br/>証明書画像をアップロード
    API-->>Client: 添付ファイル ID を返す
    Client->>API: POST /chatbots/{id}/completions/<br/>添付ファイル ID を渡す
    API->>Bot: 画像認識
    Bot-->>API: JSON 構造化結果
    API-->>Client: OCR JSON を返す
```

### Step 1：画像をアップロードして添付ファイル ID を取得 <a href="#api-step1-upload-image-get-attachment-id" id="api-step1-upload-image-get-attachment-id"></a>

```bash
curl -X POST \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -F "file=@/path/to/id_card.jpeg" \
  "https://api.maiagent.ai/api/v1/attachments-upload/"
```

返却結果のうち `id`、`type`、`file`、`filename` の各項目を控えておいてください。次のステップで使用します。

### Step 2：アシスタントを呼び出して認識を実行 <a href="#api-step2-call-assistant-for-recognition" id="api-step2-call-assistant-for-recognition"></a>

```bash
curl -X POST \
  -H "Authorization: Api-Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "content": "請辨識這張證件圖片",
      "attachments": [{
        "id": "{Step 1 回傳的 id}",
        "type": "image",
        "file": "{Step 1 回傳的 file URL}",
        "filename": "id_card.jpeg"
      }]
    },
    "isStreaming": false
  }' \
  "https://api.maiagent.ai/api/v1/chatbots/{助理ID}/completions/"
```

### Step 3：返却結果の解析 <a href="#api-step3-parse-response" id="api-step3-parse-response"></a>

返却された `content` 項目が、JSON フォーマットの認識結果です：

**Python**

```python
import json
ocr_result = json.loads(response["content"])
print(ocr_result["name"])             # 陳筱玲
print(ocr_result["id_number"])        # A234567890
print(ocr_result["address"])          # 臺北市內湖區葫洲里1鄰民權東路六段283巷165弄218號
```

**JavaScript**

```javascript
const ocrResult = JSON.parse(response.content);
console.log(ocrResult.name);             // 陳筱玲
console.log(ocrResult.id_number);        // A234567890
console.log(ocrResult.address);          // 臺北市內湖區葫洲里1鄰民權東路六段283巷165弄218號
```

{% hint style="info" %}
完全なサンプルコードは [Playma-Co-Ltd/maiagent-api-examples](https://github.com/Playma-Co-Ltd/maiagent-api-examples) を参照してください。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-ja/application/image-vision/id-card-recognition.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
