VisualStudio2019 + OpenCV4.4.0 + CUDA10.1 + VideoCodecSDK10.0 の環境構築

# VisualStudio2019 + OpenCV4.4.0 + CUDA10.1 + VideoCodecSDK10.0 の環境構築

## 環境構築

### 参考

- <https://qiita.com/Susumu0417/items/c0823f6649d2dddc1679>
- <https://nln.jp/wp/archives/5974>
- <https://takap-tech.com/entry/2021/06/03/215015>

### ダウンロード・インストール

- OpenCV 4.4.0
  - <https://opencv.org/releases/page/3/>
      - Windows
          - opencv-4.4.0-vc14_vc15.exe
              - 解凍
                  - E:/Program/OpenCV/opencv
- opencv_contrib 4.4.0
  - <https://github.com/opencv/opencv_contrib>
      - Tag
          - 4.4.0
      - Code
          - Download ZIP
              - opencv_contrib-4.4.0.zip
                  - 解凍
                      - E:/Program/OpenCV/opencv_contrib-4.4.0
- CUDA Toolkit 10.1 Update 2 Download
  - <https://developer.nvidia.com/cuda-toolkit-archive>
      - <https://developer.nvidia.com/cuda-10.1-download-archive-update2>
          - Windows
          - x86_64
          - 10
          - exe[local]
              - cuda_10.1.243_426.00_win10.exe
- NVIDIA VIDEO CODEC SDK 10.0
  - <https://developer.nvidia.com/video-codec-sdk-archive>
      - <https://developer.nvidia.com/designworks/video_codec_sdk/downloads/v10>
          - Video_Codec_SDK_10.0.26.zip
              - 解凍
                  - E:/Program/OpenCV/Video_Codec_SDK_10.0.26
          - C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1 にコピーする
              - Video_Codec_SDK_10.0.26/Interface/ から v10.1/include/ へ
              - Video_Codec_SDK_10.0.26/Lib/ から v10.1/lib/ へ
- CMake Latest Release (3.22.1)
  - <https://cmake.org/download/>
      - cmake-3.22.1-windows-x86_64.msi
          - Add CMake to the system PATH for all users
              - 環境変数
                  - PATH
                      - C:/Program Files/CMake/bin
- Visual Studio Community 2019

### OpenCV モジュール生成

- CMakeでOpenCVをビルドするソリューションファイルを生成する
  - cmake-gui 起動
      1. ソースコード
          - E:/Program/OpenCV/opencv/sources
      1. ビルドバイナリ
          - E:/Program/OpenCV/build
      1. Configure
          - Visual Studio 16 2019
          - x64
          - Use default native compilers
          - Finish
      1. Check
          - BUILD_EXAMPLES : ON
          - BUILD_PERF_TESTS : OFF
          - BUILD_TESTS : OFF
          - INSTALL_CREATE_DISTRIB : ON
          - OPENCV_ENABLE_NONFREE : ON
          - OPENCV_EXTRA_MODULES_PATH : E:/Program/OpenCV/opencv_contrib-4.4.0/modules
          - WITH_CUDA : ON
          - WITH_OPENGL : ON
      1. Configure
      1. Check
          - WITH_NVCUVID : ON
      1. Configure
      1. Check
          - CUDA_ARCH_BIN : 6.1
              - <https://developer.nvidia.com/cuda-gpus>
                  - Geforce GTX 1070 Ti
          - CUDA_ARCH_PTX : 6.1
          - CUDA_TOOLKIT_ROOT_DIR : C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1
      1. Configure
      1. Generate
- OpenCVをビルドする
  - E:/Program/OpenCV/build/OpenCV.sln
      - エラー
          - E:/Program/OpenCV/opencv_contrib-4.4.0/modules/rgbd/src/dynafu.cpp
              - 'glGenRenderbuffersEXT': 識別子が見つかりませんでした
                  - <https://github.com/opencv/opencv_contrib/issues/2307>
- 再生成
    1. Check
        - BUILD_opencv_rgbd : OFF
    1. Configure
    1. Generate
- OpenCVをビルドする
    1. set PATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin;%PATH%
    1. cd /d E:/Program/OpenCV/build
    1. Debug
        1. MSBuild OpenCV.sln /t:build /p:Configuration=Debug;Platform="x64"
        1. MSBuild INSTALL.vcxproj /t:build /p:Configuration=Debug;Platform="x64"
        1. 60min
    1. Release
        1. MSBuild OpenCV.sln /t:build /p:Configuration=Release;Platform="x64"
        1. MSBuild INSTALL.vcxproj /t:build /p:Configuration=Release;Platform="x64"
        1. 60min
- E:/Program/OpenCV/build/install
  - /include
  - /x64/vc16/bin
  - /x64/vc16/lib