AzureKinect の opencv-kinfu-samples をビルドする

これ。

https://github.com/microsoft/Azure-Kinect-Samples/tree/master/opencv-kinfu-samples

を動かすメモ。
vcpkg で 依存する dll 、特に

* opencv_rgbd
* opencv_viz

をビルドする。

# 環境

* Windows10(64bit)
* visualstudio 2019 c++

# vcpkg の feature機能
vcpkgでOpenCVのmoduleをビルドする

`$ vcpkg install opencv4[dnn]`

のようにする。

https://devblogs.microsoft.com/cppblog/vcpkg-introducing-installation-options-with-feature-packages/

opencv4のデフォルトで有効になる feature は、

`dnn, jpeg, opengl, png, tiff, webp` 。

`ports/opencv4/CONTROL` に書いてある。

# 無い feature を追加したい

```
> .\vcpkg.exe search opencv4
opencv4              4.1.1-3          computer vision library
opencv4[nonfree]                      allow nonfree and unredistributable libraries
opencv4[ade]                          graph api
opencv4[contrib]                      opencv_contrib module
opencv4[cuda]                         CUDA support for opencv
opencv4[dnn]                          Enable dnn module
opencv4[eigen]                        Eigen support for opencv
opencv4[ffmpeg]                       ffmpeg support for opencv
opencv4[gdcm]                         GDCM support for opencv
opencv4[ipp]                          Enable Intel Integrated Performance Primitives
opencv4[jasper]                       JPEG 2000 support for opencv
opencv4[jpeg]                         JPEG support for opencv
opencv4[openexr]                      OpenEXR support for opencv
opencv4[opengl]                       opengl support for opencv
opencv4[openmp]                       Enable openmp support for opencv
opencv4[ovis]                         opencv_ovis module
opencv4[png]                          PNG support for opencv
opencv4[qt]                           Qt GUI support for opencv
opencv4[sfm]                          opencv_sfm module
opencv4[tbb]                          Enable Intel Threading Building Blocks
opencv4[tiff]                         TIFF support for opencv
opencv4[vtk]                          vtk support for opencv
opencv4[webp]                         WebP support for opencv
opencv4[halide]                       Halide support for opencv
opencv4[world]                        Compile to a single package support for opencv
```

* rgbd
* viz

vcpkgのパッケージ情報は、ports フォルダにある。
opencv4 を改造する。

```:$VCPKG_DIR/ports/opencv4/CONTROL
# 下記を追加する
Feature: viz
Build-Depends: vtk
Description: viz

Feature: rgbd
Description: rgbd
```

```cmake:$VCPKG_DIR/ports/opencv4/portfile.cmake
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
 "ade"      WITH_ADE
# 省略
 "rgbd"     BUILD_opencv_rgbd
 "viz"      BUILD_opencv_viz
)
```

`$ vcpkg install vtk`
`$ vcpkg install opencv4[nonfree,contrib,vtk,rgbd,viz]`

でビルドすると、

* opencv_rgbd.dll
* opencv_viz.dll

が出現した。

`viz` が `vtk` に依存している様子。

# opencv-kinfu-samples を動かす

Kinect-Azure の KinectFusion サンプル

https://github.com/microsoft/Azure-Kinect-Samples/tree/master/opencv-kinfu-samples

```cmake:雑に改造したopencv-kinfu-samples/CMakeLists.txt
# find_package がよくわからないので、適当に書き替えた。
cmake_minimum_required(VERSION 3.10)
project(kinfu-example)
add_executable(kinfu-example main.cpp)

# find_package(k4a 1.3.0 QUIET)
set(K4A_INCLUDE_DIRS "C:/Program Files/Azure Kinect SDK v1.4.0/sdk/include")
include_directories(${K4A_INCLUDE_DIRS})

# find_package(OpenCV)
set(OpenCV_INCLUDE_DIRS "C:/vcpkg/installed/x64-windows/include")
include_directories(${OpenCV_INCLUDE_DIRS})

target_compile_definitions(kinfu-example PRIVATE
    HAVE_OPENCV
    )

target_link_directories(kinfu-example PRIVATE
    "C:/Program Files/Azure Kinect SDK v1.4.0/sdk/windows-desktop/amd64/release/lib"
    debug
    "C:/vcpkg/installed/x64-windows/debug/lib"
    optimized
    "C:/vcpkg/installed/x64-windows/lib"
    )

target_link_libraries(kinfu-example PRIVATE 
    k4a
    debug
    opencv_rgbdd
    opencv_vizd
    opencv_cored
    opencv_calib3dd
    opencv_imgcodecsd
    opencv_highguid
    optimized
    opencv_rgbd
    opencv_viz
    opencv_core
    opencv_calib3d
    opencv_imgcodecs
    opencv_highgui
    )
```

```json:launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) 起動",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/kinfu-example.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "C:\\Program Files\\Azure Kinect SDK v1.4.0\\tools", // dll以外にもこのフォルダのファイルが実行に必要。コピーしてもよいが移動している
            "environment": [
                {
                    "name": "PATH",
                    "value": "${env:PATH};c:\\vcpkg\\installed\\x64-windows\\debug\\bin;c:\\vcpkg\\installed\\x64-windows\\bin" // とりあえず debug, release 両方
                }
            ],
            "externalConsole": false
        }
    ]
}
```