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

# Guia OpenCV do stellarHD

> Um guia básico para começar a usar a câmera stellarHD com Python e OpenCV.

<div style={{ marginTop: '-40px' }} />

## Pré-requisitos

Antes de executar a aplicação, certifique-se de ter o seguinte instalado no seu sistema:

* Python (versão 3.x)
* Biblioteca OpenCV (`cv2`)

## Exemplo de código

Você pode usar o script `main.py` a seguir para conectar-se à câmera e visualizar o feed de vídeo. Um passo essencial ao configurar a câmera é que o formato de pixel `MJPG` deve ser definido *antes* de definir a resolução.

```python theme={null}
import cv2
import time

# -- Camera Parameters --
# Camera Index
CAM_IDX = 0
# resolution
WIDTH = 1600
HEIGHT = 1200

# Hardware supported framerate of the camera. Highest for best results.
FRAMERATE = 60

# used to set the pixel format to MJPEG/MJPG mode.
MJPG = cv2.VideoWriter_fourcc(*'MJPG')

# -- DEVICE SETUP --
stellarHD = cv2.VideoCapture(CAM_IDX)

# set to MJPEG mode, by default idx 0 is YUYV
# MJPG needs to be set, before resolution. Pixel format is always selected first
stellarHD.set(cv2.CAP_PROP_FOURCC, MJPG)

stellarHD.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
stellarHD.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)

# Set framerate
stellarHD.set(cv2.CAP_PROP_FPS, FRAMERATE)

# (Optional) Disable auto exposure
stellarHD.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1)
stellarHD.set(cv2.CAP_PROP_EXPOSURE, 90)

# Error Check
if ((stellarHD == None) or (not stellarHD.isOpened())):
    print('\nError - could not open video device.\n')
    exit(0)

while(True):
    success, frame = stellarHD.read()
    if (success):
        cv2.imshow('stellarHD', frame)
    
    # required for frames to buffer and show properly.
    k = cv2.waitKey(1)

    # press 'q' to quit
    if k == ord('q'):
        break

stellarHD.release()
cv2.destroyAllWindows()
```

## Informações adicionais

Para mais detalhes, exemplos em outras linguagens como C++, ou solução de problemas, consulte nosso repositório no GitHub.

<Card title="Repositório de guias OpenCV" icon="Github" href="https://github.com/DeepWaterExploration/opencv-guides">
  Captura de vídeo básica, amostragem de quadros por software, código C++, etc.
</Card>
