> For the complete documentation index, see [llms.txt](https://docs.handl.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.handl.ai/services/document-classification.md).

# Document classification

![](/files/-Mfn8GCY1P2qvxLSNuw6)

The Classifier algorithm finds documents in the image and assigns them a document type.We support a wide array of documents for Eastern Europe, and can train our algorithms to process any custom type of document with a provided dataset (as we did for invoices, tax and covid forms).<br>

### **Algorithm of the API /classify method**

1. The algorithm looks for rectangular shapes on the incoming image that look like documents and cuts them out.
2. The Classifier assigns a class to each cut out area: Passport, Driver’s Licence, and so on. A list of currently supported document types is available at the link.
3. The algorithm evaluates the orientation of the document in space. If necessary, the classifier rotates or mirrors the document.

{% hint style="info" %}
Types of cutout areas that the classifier does not rotate or mirror:

* **other** - document of unknown type;
* **not\_document** - not a document, for example, a photo of a cat;
* **empty** - empty page.
  {% endhint %}

**API specification**

Below is the API specification for the document classification method. For more details on how to compose a classification request, see [Connecting and testing](https://app.gitbook.com/@dbrain/s/ru/~/drafts/-Me1O9_QQdWJ11DEMXxT/v/dbrain-english-documentation/connection).<br>

## classify

<mark style="color:green;">`POST`</mark> `https://latest.handl.io/classify`

#### Query Parameters

| Name                      | Type    | Description                                                                                                                                                                                                                                                                                                                                     |
| ------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| min\_shape                | integer | **>0,  the default value is 256.** The minimum size of the image in pixels on the short side. If smaller, the **low\_image\_weight** parameter in the response will return true. If larger - **false**.                                                                                                                                         |
| min\_filesize             | integer | **>0, the default value is 10240**. Minimal image weight in bytes. If less, the **low\_image\_weight** parameter in the response will return true. If more - **false**.                                                                                                                                                                         |
| max\_exposure\_score      | number  | **>0, default value is 0.4.** Maximum exposure of the image. If the exposure is higher, the **image\_exposure** parameter in the response will return overexposed. If less - **normal**.                                                                                                                                                        |
| min\_exposure\_score      | number  | **>0, the default is 0.05.** The minimum exposure of the image. If the exposure is less, the **image\_exposure** parameter will return underexposed in the response. If higher - **normal**.                                                                                                                                                    |
| max\_blur\_score          | number  | **>0, defaults to 2.** The minimal coefficient of clarity of the image. If less, the **image\_blured** parameter in the response will return true. If more, **false**.                                                                                                                                                                          |
| doc\_type                 | array   | A list of document types to search for in the input file. It is used for deterministic processes, for example, if only the main spread of a passport needs to be found in the document stream, and all other types do not need to be utilized. By default all values of the parameter are selected (all types are available in the classifier). |
| priority                  | integer | **>0, default value is 1.** Priority of an asynchronous task in the queue for processing.                                                                                                                                                                                                                                                       |
| simple\_cropper           | boolean | <p><strong>false (default)</strong> - the simplified algorithm of cutting documents from images is not used.<br><strong>true</strong> - the simplified algorithm of cutting documents from images is used: it is faster, but the result is less accurate. On images with a complex background documents may be cut out less accurately.</p>     |
| async                     | boolean | <p><strong>true</strong> - asynchronous mode of processing requests.<br><strong>false</strong> - synchronous mode of request processing.<br></p>                                                                                                                                                                                                |
| check\_fake\_experimental | boolean | This one is out of date and is not used.                                                                                                                                                                                                                                                                                                        |
| check\_fake               | boolean | <p><strong>true</strong> - the algorithm searches the file metadata for signs of modification via digital editors, the result is returned in a separate field called “fake”.<br><strong>false</strong> - the metadata checking algorithm is disabled.</p>                                                                                       |
| pdf\_raw\_images          | boolean | <p><strong>true -</strong> the algorithm leaves the decision of PDF files’ rasterization to the <strong>auto\_pdf\_raw\_images</strong> parameter.<br><strong>false -</strong> all PDF files will be rasterized, the value of the <strong>auto\_pdf\_raw\_images</strong> parameter will be ignored.</p>                                        |
| auto\_pdf\_raw\_images    | boolean | <p><strong>true</strong> - the algorithm leaves the decision of PDF files’ rasterization to the <strong>auto\_pdf\_raw\_images</strong> parameter.<br><strong>false -</strong> the algorithm will never rasterize PDF.</p>                                                                                                                      |
| dpi                       | integer | **>0, the default value is 300 -** sets the number of pixels per inch for PDF rasterization. We recommend 300. Higher values usually do not increase the quality, but increase the weight of the image.                                                                                                                                         |
| quality                   | integer | **0-100, the default value is 75 -** sets the degree of JPEG compression for PDF rasterization. The recommended value is 75 for balance between the weight of the image and its quality.                                                                                                                                                        |

{% tabs %}
{% tab title="200 The request was successfully processed

The "crop" attribute represents the extracted and correctly oriented image of the found document in binary format\
The "type" attribute specifies the type of the retrieved document." %}

```javascript
The request {
  "detail": [ // technical information
    {
      "loc": [ 
        "string" 
      ],
      "msg": "string",
      "type": "string" 
    }
  ],
  "items": [
    {
      "document": {
        "type": "bank_card", // document type
        "page": 0, // page number of the input file where the document was found
        "rotation": 0, // 4 options of document rotation by 90 degrees x 2 options of mirroring
        "coords": [ // coordinates of the document image in the input file
          [
            0
          ]
        ]
      },
      "crop": "string", // image of document in binary format
      "image_exposure": "normal", // document exposure
      "image_blured": false, // document clarity
      "low_image_resolution": true, // document resolution
      "low_image_weight": true // document image weight
    }
  ],
  "task_id": null, //task's internal id
  "code": null, //error code
  "message": null, // error message within the object
  "errno": null, // error number
  "traceback": null, // error message within the limits of object
  "fake": true, // response at the parameter check_fake = "true"
  "pages_count": 1, // number of pages in the input file
  "docs_count": 1 // number of documents in the input file
} successfully processed.
```

{% endtab %}

{% tab title="422 The request contains invalid input parameters" %}

```javascript
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

{% endtab %}
{% endtabs %}
