【OpenCV】JetBrains RiderでNuGetを使いOpenCVの.Netラッパーを導入する【.Net】

OpenCVでちょっとしたプログラムを作りたいけれど、WindowsUbuntuが混ざった別々の4つ位の環境で動かしたい状況で、全部に一々環境構築するのが面倒くさい感じになりました。
クロスプラットフォームで動く.Net/JetBrains Riderを使い、NuGetでOpenCVの.Netラッパーを導入してやれば楽だろうと思い、まずは導入までやってみました。
Ubuntuでの動作はまだ確認していません。

NuGetでOpenCVの.Netラッパーを導入

左下の方にあるNuGetを押します。
f:id:wrongwrongwrongwrong163377:20180511152829p:plain

OpenCVで検索し、テキトーに選んでから右端の緑色の+マークを押します。今回はOpenCvSharp3-AnyCPUを選択していますが、バージョンが高そうだから選んだというだけで各パッケージの内どれが良いかなどは検討していません。
f:id:wrongwrongwrongwrong163377:20180511153213p:plain

本当に導入していいかを聞いてくるので、Yesを押してしばらく待てば完了です。
f:id:wrongwrongwrongwrong163377:20180511153355p:plain

サンプルコード

とりあえずVBでバージョン確認をしているだけです。

Imports OpenCvSharp

Module Module1
    Sub Main()
        
        Console.WriteLine(Cv2.GetBuildInformation())
        
    End Sub
End Module
出力

一応3.4.1が入っているようですね。Cudaなどを考えるとNuGetでは不都合が有るなどの情報も見かけましたが、今の所困っていないので考えないこととします。

C:/Users/wrongwrong/RiderProjects/OpenCV_Test/OpenCV_Test/bin/Debug/OpenCV_Test.exe

General configuration for OpenCV 3.4.1 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            C:/libs/opencv/opencv_contrib_3.4.1/modules
    Version control (extra):     3.4.1

  Platform:
    Timestamp:                   2018-03-07T05:49:06Z
    Host:                        Windows 10.0.16299 AMD64
    CMake:                       3.10.0-rc4
    CMake generator:             Visual Studio 15 2017
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe
    MSVC:                        1913

  CPU/HW features:
    Baseline:                    SSE SSE2
      requested:                 SSE2

  C/C++:
    Built as dynamic libs?:      NO
    C++11:                       YES
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe  (ver 19.13.26128.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast   /arch:SSE /arch:SSE2 /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP8   /MT /O2
/Ob2 /DNDEBUG
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast   /arch:SSE /arch:SSE2 /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP8   /MTd /Zi
 /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast   /arch:SSE /arch:SSE2   /MP8    /MT /O2 /Ob2 /DNDEBUG
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:fast   /arch:SSE /arch:SSE2   /MP8  /MTd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:X86  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:X86  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          comctl32 gdi32 ole32 setupapi ws2_32 vfw32 C:/Projects/VS2015_Tesseract/Release/libtesseract.lib C:/Projects/VS2015_Tesseract/Release/liblept.lib
    3rdparty dependencies:       ittnotify libprotobuf zlib libjpeg libwebp libpng libtiff libjasper IlmImf ippiw ippicv

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo p
lot reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    js python2 python_bindings_generator world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern freetype hdf java matlab ovis python3 sfm viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         YES

  Windows RT support:            NO

  GUI:
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.34)
    TIFF:                        build (ver 42 - 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    Video for Windows:           YES
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (ver 57.107.100)
      avformat:                  YES (ver 57.83.100)
      avutil:                    YES (ver 55.78.100)
      swscale:                   YES (ver 4.8.100)
      avresample:                YES (ver 3.7.0)
    GStreamer:                   NO
    DirectShow:                  YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2017.0.3 [2017.0.3]
           at:                   C:/libs/opencv/3.4.1/mybuild/x86_vc15_contrib/3rdparty/ippicv/ippicv_win
    Intel IPP IW:                sources (2017.0.3)
              at:                C:/libs/opencv/3.4.1/mybuild/x86_vc15_contrib/3rdparty/ippicv/ippiw_win
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                C:/libs/opencv/3.4.1/sources/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            C:/libs/Python27/python.exe

  Matlab:                        NO

  Install to:                    C:/libs/opencv/3.4.1/mybuild/x86_vc15_contrib/install
-----------------------------------------------------------------