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

# stellarHD OpenCV ガイド

> Python と OpenCV を使用して stellarHD カメラを始めるための基本ガイドです。

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

## 前提条件

アプリケーションを実行する前に、以下がシステムにインストールされていることを確認してください:

* Python(バージョン 3.x)
* OpenCV ライブラリ(`cv2`)

## セットアップ

OpenCV Guides リポジトリをクローンし、このガイド用のフォルダーを開きます:

```bash theme={null}
git clone https://github.com/DeepWaterExploration/opencv-guides.git
cd opencv-guides/1-basic-video-capture/python
```

## サンプルコード

以下の `main.py` スクリプトを使用して、カメラに接続し、映像フィードを表示できます。カメラを設定する際の重要なステップは、解像度を設定する*前に* `MJPG` ピクセル形式を設定する必要があるということです。

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

## 詳細情報

詳細、C++ など他の言語のサンプル、トラブルシューティングについては、GitHub リポジトリを参照してください。

Discovery で録画していますか? 出力された `.dwvo` ファイルを OpenCV で再生・エクスポートする方法をご覧ください。

<Card title="DWVO 録画の読み込み" icon="film" href="/ja/discovery/misc/dwvo-reading" horizontal>
  `.dwvo` 録画を Python で再生・エクスポート・解析します。
</Card>

<Card title="OpenCV ガイドリポジトリ" icon="Github" href="https://github.com/DeepWaterExploration/opencv-guides">
  基本的なビデオキャプチャ、ソフトウェアフレームサンプリング、C++ コードなど。
</Card>
