> For the complete documentation index, see [llms.txt](https://portal-integracao.intelbras.com.br/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://portal-integracao.intelbras.com.br/cameras-and-gravadores/integracao-api-cftvip-e-mibo/cameras-e-gravadores/rec.-facial.md).

# Rec. Facial

Integração de reconhecimento facial via CGI: subscribe FaceDetection/FaceRecognition, payload multipart (texto+JPEG), exemplo em Python e dicas (Digest, reconexão).

### Dicas & Boas Práticas <a href="#dicas-and-boas-praticas" id="dicas-and-boas-praticas"></a>

* Requisições de eventos utilizam **conexão persistente (subscribe to event)**.
* Postman e Insomnia **não mantêm heartbeat contínuo**, portanto **não são suportados**.
* Utilize clientes compatíveis com streaming:
  * `curl` com autenticação Digest
  * Python (`requests` com `stream=True`)
  * Clientes HTTP de baixo nível (ex.: sockets)

***

### Eventos Faciais

* **Assinatura de evento**: `/cgi-bin/eventManager.cgi?action=attach&codes=[FaceDetection]`
* **Resposta esperada (multipart)**:

```powershell
--boundary
Content-Type: text/plain
Content-Length: <length>
Events[0].EventBaseInfo.Code=FaceDetection
Events[0].EventBaseInfo.Action=Start
Events[0].EventBaseInfo.Index=0
...
--boundary
Content-Type: image/jpeg
Content-Length: <tamanho>
<dados binários>
```

* **Assinatura de evento**: `/cgi-bin/eventManager.cgi?action=attach&codes=[FaceRecognition]`
* **Resposta esperada (multipart)**:

```powershell
--boundary
Content-Type: text/plain
Content-Length: <length>
Events[0].EventBaseInfo.Code=FaceRecognition
Events[0].EventBaseInfo.Action=Start
Events[0].EventBaseInfo.Index=0
Events[0].Object.PersonId=1694161112000001
Events[0].Object.GroupId=2023090912345678
...
--boundary
Content-Type: image/jpeg
Content-Length: <tamanho>
<imagem do rosto>
```

***

### Exemplo em Python (Multipart Subscription)

```python
import requests
from requests.auth import HTTPDigestAuth

url = "http://<ip>/cgi-bin/eventManager.cgi?action=attach&codes=[FaceRecognition]"
resp = requests.get(url, auth=HTTPDigestAuth("admin", "senha"), stream=True)
for chunk in resp.iter_lines():
    if chunk:
        print(chunk.decode())
```

***

Notas finais:

* Utilize sempre clientes que suportem **streaming HTTP** para assinatura de eventos.
* Armazene e reutilize `GroupId` e `PersonId` retornados pela API.
* Implemente **reconexão automática** em caso de perda da sessão.
* Trate corretamente respostas **multipart (texto + imagem)**.
* Utilize **HTTP Digest Authentication** para todas as requisições.
* Siga as boas práticas para garantir estabilidade e confiabilidade da integração.

***


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://portal-integracao.intelbras.com.br/cameras-and-gravadores/integracao-api-cftvip-e-mibo/cameras-e-gravadores/rec.-facial.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
