> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# バーコードの認識

> PageAnalysisParams の BarcodeParams を使用して ABBYY FineReader Engine のバーコード認識を調整します — Code 39 / Interleaved 2 of 5 / Codabar / Matrix 2 of 5 のチェックサムと、2D コードを対象としています。

このセクションでは、ABBYY FineReader Engine 12 におけるバーコード認識特有の機能について説明します。バーコード認識の主な事項については、[バーコード認識](/ja/fine-reader/engine/guided-tour/basic-usage-scenarios-implementation/barcode-recognition) シナリオの説明を参照してください。

ほとんどの場合、バーコードが仕様に準拠していれば、デフォルト設定で認識できます。そうでない場合は、特定のパラメーターを指定する必要があります。これらのパラメーターは、[PageAnalysisParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/pageanalysisparams) オブジェクトの [BarcodeParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/barcodeparams) サブオブジェクトで指定します。

<div id="barcodes-with-checksum">
  ## チェックサム付きバーコード
</div>

[Code 39](/ja/fine-reader/engine/specifications/barcode-types#code_39)、[Interleaved 2 of 5](/ja/fine-reader/engine/specifications/barcode-types#interleaved2_5)、[Codabar](/ja/fine-reader/engine/specifications/barcode-types#codabar)、および [Matrix 2 of 5](/ja/fine-reader/engine/specifications/barcode-types#matrix2_5) タイプのバーコードには、チェックサムが含まれる場合があります。チェックサムはエラー検出に使用されます。チェックサムの計算アルゴリズムは規格で定められています。チェックサム付きバーコードを正しく認識するには、BarcodeParams オブジェクトの [HasChecksum](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/barcodeparams#haschecksum) プロパティを TRUE に設定する必要があります。

<Warning>
  規格で定められている場合、認識結果にはバーコードのチェックサムは含まれません。
</Warning>

<div id="pdf417-aztec-data-matrix-qr-code-maxicode-barcodes">
  ## PDF417、Aztec、Data Matrix、QR Code、MaxiCode バーコード
</div>

既定では、ABBYY FineReader Engine は、仕様に準拠したコードページを使用して、[PDF417](/ja/fine-reader/engine/specifications/barcode-types#pdf_417)、[Aztec](/ja/fine-reader/engine/specifications/barcode-types#aztec)、[DataMatrix](/ja/fine-reader/engine/specifications/barcode-types#datamatrix)、[QR Code](/ja/fine-reader/engine/specifications/barcode-types#qrcode)、[MaxiCode](/ja/fine-reader/engine/specifications/barcode-types#maxicode) バーコードを認識します。使用されるコードページは次のとおりです。

* PDF417 の場合 — DOS United States (437) ([CP\_US\_MSDOS](/ja/fine-reader/engine/api-reference/enumerations/codepageenum#cp_us_msdos))
* Aztec、DataMatrix、QR Code、MaxiCode の場合 — ISO Latin 1 (8859-1) ([CP\_Latin\_ISO](/ja/fine-reader/engine/api-reference/enumerations/codepageenum#cp_latin_iso))

これらのバーコードが仕様に準拠していないことがあります。つまり、仕様で定義されているものとは異なるコードページを使用して作成されている場合です。この場合は、BarcodeParams オブジェクトの [CodePage](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/barcodeparams#codepage) プロパティでコードページを手動で指定する必要があります。

<div id="qr-codes-in-structured-append-mode">
  ## Structured Append モードの QR コード
</div>

[QR Codes](/ja/fine-reader/engine/specifications/barcode-types#qrcode) は、structured append 形式で最大 16 個のコードを順番に連結することで、大量のデータをエンコードできます。[BarcodeBlock](/ja/fine-reader/engine/api-reference/layout-related-objects/barcodeblock) オブジェクトでは、QrCodeSequenceId、QrCodeSequenceCount、QrCodeSequenceIndex プロパティを通じて structured append シーケンスに関する特別な情報にアクセスでき、プログラムでこれらを使って認識されたコードを結合できます。

<div id="binary-data-encoded-in-barcodes">
  ## バーコードにエンコードされたバイナリデータ
</div>

[PDF417](/ja/fine-reader/engine/specifications/barcode-types#pdf_417)、[Aztec](/ja/fine-reader/engine/specifications/barcode-types#aztec)、[DataMatrix](/ja/fine-reader/engine/specifications/barcode-types#datamatrix)、[QR Code](/ja/fine-reader/engine/specifications/barcode-types#qrcode) バーコードは、テキストデータとバイナリデータの両方をエンコードできます。ABBYY FineReader Engine では、バイナリデータを含む認識済みのすべてのバーコードデータをテキストとして表します。バイナリデータがテキスト形式でどのように表現されるかは、BarcodeParams オブジェクトの [ContainsBinaryData](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/barcodeparams#containsbinarydata) プロパティの値によって異なります。

<table><thead><tr><th><p><strong>ContainsBinaryData の値</strong></p></th><th><p><strong>バイナリデータの表現方法</strong></p></th></tr></thead><tbody><tr><td><p>FALSE (既定値) </p></td><td><ul><li>バイナリデータを含む各文字では、<strong><a href="/ja/fine-reader/engine/api-reference/text-related-objects/barcodesymbol#isbinarydata">IBarcodeSymbol::IsBinaryData</a></strong> プロパティが TRUE に設定されます。</li><li>バイナリデータとテキストデータは、どちらも Unicode 文字列 (<strong><a href="/ja/fine-reader/engine/api-reference/layout-related-objects/barcodeblock#text">IBarcodeBlock::Text</a></strong>) として表されます。</li><li>データは、<strong><a href="/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/barcodeparams#codepage">IBarcodeParams::CodePage</a></strong> プロパティで指定されたコードページを使用して Unicode 文字列に変換されます。Unicode 文字列からバイナリデータを取得するには、対応するコードページを使用して文字列をデコードする必要があります。</li></ul><Note>バイナリゼロは Unicode 文字列に正しく変換できません。文字列内の対応する文字は「未認識文字」記号 ("^") になり、<a href="/ja/fine-reader/engine/api-reference/text-related-objects/barcodesymbol#isbinaryzero">IBarcodeSymbol::IsBinaryZero</a> プロパティが TRUE に設定されます。</Note></td></tr><tr><td><p>TRUE</p></td><td><ul><li>バイナリデータを含む各文字では、<strong><a href="/ja/fine-reader/engine/api-reference/text-related-objects/barcodesymbol#isbinarydata">IBarcodeSymbol::IsBinaryData</a></strong> プロパティが TRUE に設定されます。</li><li>バイナリデータとテキストデータは、どちらも Unicode 文字列 (<strong><a href="/ja/fine-reader/engine/api-reference/layout-related-objects/barcodeblock#text">IBarcodeBlock::Text</a></strong>) として表されます。</li><li>バイナリデータは、対応する各バイトの16進値の並びとして Unicode 文字列に保存されます。たとえば、文字列 "00FF02" は 0x00、0xFF、0x02 の 3 バイトを表します。</li></ul></td></tr></tbody></table>

<div id="the-recognition-procedure">
  ## 認識手順
</div>

仕様に準拠していないバーコードや、チェックサム付きのバーコードを認識するには、次の操作を行います (BarcodeRecognition\_Accuracy または BarcodeRecognition\_Speed の定義済みプロファイルがすでに読み込まれているものとします) 。

1. [Engine](/ja/fine-reader/engine/api-reference/engine-object-iengine-interface) オブジェクトの [CreateDocumentProcessingParams](/ja/fine-reader/engine/api-reference/engine-object-iengine-interface/creation-methods/createlessobjectgreater-methods) メソッドを使用して、[DocumentProcessingParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/documentprocessingparams) オブジェクトを作成します。
2. BarcodeParams サブオブジェクトで、必要なプロパティの既定値を変更します (DocumentProcessingParams には PageProcessingParams プロパティが含まれ、PageProcessingParams には PageAnalysisParams が含まれ、さらにその中に BarcodeParams が含まれます) 。
3. [FRDocument](/ja/fine-reader/engine/api-reference/document-related-objects/frdocument) オブジェクトの [Process](/ja/fine-reader/engine/api-reference/document-related-objects/frdocument/process-method) メソッドに、入力パラメーターとして DocumentProcessingParams オブジェクトを渡します。
4. 処理に別のメソッドを使用している場合は、入力パラメーターとして [PageAnalysisParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/pageanalysisparams) オブジェクトまたは [PageProcessingParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/pageprocessingparams) オブジェクトが必要になることがあります。その場合も同じ手順で、これらのオブジェクトのいずれかに含まれる BarcodeParams サブオブジェクトの値を変更してください。

<div id="code-samples">
  ### コードサンプル
</div>

<Accordion title="C++ コード">
  ```cpp theme={null}
  // Engine はすでにロードされており、
  // ドキュメントは開かれているものとします
  IEngine* Engine;
  IFRDocument* frDocument;
  HRESULT res; // この変数を使用して、メソッドの呼び出しが成功したかどうかを確認します
  ...
  // DocumentProcessingParams オブジェクトを作成します
  IDocumentProcessingParams* params = 0;
  res = Engine->CreateDocumentProcessingParams( ¶ms );
   
  IPageProcessingParams* pageParams = 0;
  IPageAnalysisParams* analysisParams = 0;
  IBarcodeParams* barcodeParams = 0;
  res = params->get_PageProcessingParams( &pageParams );
  res = pageParams->get_PageAnalysisParams( &analysisParams );
  res = analysisParams->get_BarcodeParams( &barcodeParams );
   
  // 必要なパラメーターを指定します
  res = barcodeParams->set_Type( BT_Code39 );
   
  // バーコードを認識します
  // BarcodeRecognition 定義済みプロファイルはすでにロードされているものとします
  res = frDocument->Process( params );
  ...
  ```
</Accordion>

<Accordion title="C++ (COM) コード">
  ```cpp theme={null}
  FREngine::IEnginePtr Engine;
  FREngine::IFRDocumentPtr frDocument;
  ...
  // DocumentProcessingParams オブジェクトを作成します
  FREngine::IDocumentProcessingParamsPtr params = Engine->CreateDocumentProcessingParams();
  // 必要なパラメーターを指定します
  params->PageProcessingParams->PageAnalysisParams->BarcodeParams->Type = FREngine::BT_Code39;
  // バーコードを認識します。FRDocument オブジェクトはすでに作成されており、
  // BarcodeRecognition 定義済みプロファイルはすでにロードされているものとします
  frDocument->Process( params );
  ...
  ```
</Accordion>

<Accordion title="C# コード">
  ```csharp theme={null}
  FREngine.IEngine engine;
  FREngine.IFRDocument frDocument;
  ...
  // DocumentProcessingParams オブジェクトを作成します
  FREngine.IDocumentProcessingParams dpp = engine.CreateDocumentProcessingParams();
  // 必要なパラメーターを指定します
  dpp.PageProcessingParams.PageAnalysisParams.BarcodeParams.Type = (int)FREngine.BarcodeTypeEnum.BT_Code39;
  // バーコードを認識します。FRDocument オブジェクトはすでに作成されており、
  // BarcodeRecognition 定義済みプロファイルはすでにロードされているものとします
  frDocument.Process( dpp );
  ```
</Accordion>

<div id="tips-for-working-with-barcodes">
  ## バーコードを扱う際のヒント
</div>

バーコード認識の品質は、バーコードの印字品質と、文書のスキャン処理で使用する設定に左右されます。バーコードを適切に認識させるには、次の推奨事項に従ってください。

* バーコードは、ほかの文字と十分な幅の白い余白で区切られている必要があります。
* バーコードのサイズと、それを構成する個々のバーまたはドットの幅は、次の要件を満たしている必要があります。
  * バーコードの高さは、10 ミリメートルを超えるのが理想的です。バーコードのサイズは A4 サイズ未満である必要があります。
  * バーコードの高さは、テキスト 1 行の高さの 2 倍より大きい必要があります。
  * 正方形でないバーコードでは、長さは高さより大きい必要があります。
  * 1D バーコードでは、バーコード内で最も細いバーの幅は、画像上で少なくとも 3～5 ピクセル必要です。
  * 2D バーコードでは、セルの寸法は少なくとも 2x2 ピクセル必要です。推奨サイズは 4x4 ピクセル以上です。また、PDF417 を除くすべての 2D バーコードでは、セルは正方形である必要があります。2D バーコードが引き伸ばされていると、ほとんどの場合、正しく認識されないためです。
* JPEG 圧縮を使用してバーコード画像を圧縮することは推奨しません。バーコードの境界がぼやけるためです。
* バーコードが傾かないようにしてください。つまり、バーコードの角度は水平軸に対して 90 度の倍数である必要があります。
* OCR (Optical Character Recognition) の用途には、グレースケールのスキャン モードが最適です。白黒でスキャンする場合は、明るさの設定を調整してください。バーコードが「かすれている」ように見える、または非常に薄い場合は、画像を暗くするために明るさを下げてください。バーコードが歪んでいる、または一部がくっついている場合は、画像を明るくするために明るさを上げてください。
* バーコードを枠で囲んで印刷することは避けてください。
* バーコードを文字や画像の上に重ねて印刷することは避けてください。

実際には、これらの推奨事項に当てはまらないバーコードでも認識できる場合がありますが、認識品質が低くなることがあります。

<div id="see-also">
  ## 関連項目
</div>

[バーコード認識](/ja/fine-reader/engine/guided-tour/basic-usage-scenarios-implementation/barcode-recognition)

[バーコードの種類](/ja/fine-reader/engine/specifications/barcode-types)
