> ## 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.

# Guide OpenCV pour stellarHD

> Un guide d'introduction à l'utilisation de la caméra stellarHD avec Python et OpenCV.

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

## Prérequis

Avant d'exécuter l'application, assurez-vous d'avoir installé les éléments suivants sur votre système :

* Python (version 3.x)
* La bibliothèque OpenCV (`cv2`)

## Exemple de code

Vous pouvez utiliser le script `main.py` suivant pour vous connecter à la caméra et visualiser le flux vidéo. Une étape essentielle lors de la configuration de la caméra : le format de pixel `MJPG` doit être défini *avant* la résolution.

```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()
```

## Informations supplémentaires

Pour plus de détails, des exemples dans d'autres langages comme C++, ou du dépannage, veuillez consulter notre dépôt GitHub.

<Card title="Dépôt de guides OpenCV" icon="Github" href="https://github.com/DeepWaterExploration/opencv-guides">
  Capture vidéo de base, échantillonnage logiciel d'images, code C++, etc.
</Card>
