diff options
author | Dmitry Kalinkin <dmitry.kalinkin@gmail.com> | 2020-03-22 11:13:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 11:13:53 -0400 |
commit | 54a0e269b390ed436f19cf66a74cc757eac8c84f (patch) | |
tree | e2d5dac3f058d72b5a9d3f775b39435b46a87448 | |
parent | fc316f7b319a40760a4a3a939c4ff840074eac4c (diff) | |
parent | dc1a15e7bd74e8065369839e774f38bac43e4d4a (diff) |
Merge pull request #81922 from mjlbach/opencv_alternative
Enable nvidia-optical-flow-sdk when building opencv4 with cuda
-rw-r--r-- | pkgs/development/libraries/nvidia-optical-flow-sdk/default.nix | 28 | ||||
-rw-r--r-- | pkgs/development/libraries/opencv/4.x.nix | 6 | ||||
-rw-r--r-- | pkgs/development/libraries/opencv/cuda_opt_flow.patch | 26 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 2 |
4 files changed, 60 insertions, 2 deletions
diff --git a/pkgs/development/libraries/nvidia-optical-flow-sdk/default.nix b/pkgs/development/libraries/nvidia-optical-flow-sdk/default.nix new file mode 100644 index 0000000000000..667f3d94e05a3 --- /dev/null +++ b/pkgs/development/libraries/nvidia-optical-flow-sdk/default.nix @@ -0,0 +1,28 @@ +{ stdenv, fetchFromGitHub }: + +stdenv.mkDerivation { + pname = "nvidia-optical-flow-sdk"; + version = "1.0"; + + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "NVIDIAOpticalFlowSDK"; + rev = "79c6cee80a2df9a196f20afd6b598a9810964c32"; + sha256 = "1y6igwv75v1ynqm7j6la3ky0f15mgnj1jyyak82yvhcsx1aax0a1"; + }; + + # # We only need the header files. The library files are + # # in the nvidia_x11 driver. + installPhase = '' + mkdir -p $out/include + cp -R * $out/include + ''; + + meta = with stdenv.lib; { + description = "Nvidia optical flow headers for computing the relative motion of pixels between images"; + homepage = "https://developer.nvidia.com/opticalflow-sdk"; + license = licenses.bsd3; # applies to the header files only + platforms = platforms.all; + }; +} + diff --git a/pkgs/development/libraries/opencv/4.x.nix b/pkgs/development/libraries/opencv/4.x.nix index 9fffd3d94770b..519d4ecd21556 100644 --- a/pkgs/development/libraries/opencv/4.x.nix +++ b/pkgs/development/libraries/opencv/4.x.nix @@ -15,7 +15,7 @@ , enableContrib ? true , enableCuda ? (config.cudaSupport or false) && - stdenv.hostPlatform.isx86_64, cudatoolkit + stdenv.hostPlatform.isx86_64, cudatoolkit, nvidia-optical-flow-sdk , enableUnfree ? false , enableIpp ? false @@ -166,6 +166,7 @@ stdenv.mkDerivation { # Also, work around https://github.com/NixOS/nixpkgs/issues/26304 with # what appears to be some stray headers in dnn/misc/tensorflow # in contrib when generating the Python bindings: + patches = lib.optional enableCuda ./cuda_opt_flow.patch; postPatch = '' sed -i '/Add these standard paths to the search paths for FIND_LIBRARY/,/^\s*$/{d}' CMakeLists.txt sed -i -e 's|if len(decls) == 0:|if len(decls) == 0 or "opencv2/" not in hdr:|' ./modules/python/src2/gen2.py @@ -213,7 +214,7 @@ stdenv.mkDerivation { # tesseract & leptonica. ++ lib.optionals enableTesseract [ tesseract leptonica ] ++ lib.optional enableTbb tbb - ++ lib.optional enableCuda cudatoolkit + ++ lib.optionals enableCuda [ cudatoolkit nvidia-optical-flow-sdk ] ++ lib.optionals stdenv.isDarwin [ bzip2 AVFoundation Cocoa VideoDecodeAcceleration ] ++ lib.optionals enableDocs [ doxygen graphviz-nox ]; @@ -249,6 +250,7 @@ stdenv.mkDerivation { "-DCUDA_FAST_MATH=ON" "-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc" "-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr" + "-DNVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH=${nvidia-optical-flow-sdk}" ] ++ lib.optionals stdenv.isDarwin [ "-DWITH_OPENCL=OFF" "-DWITH_LAPACK=OFF" diff --git a/pkgs/development/libraries/opencv/cuda_opt_flow.patch b/pkgs/development/libraries/opencv/cuda_opt_flow.patch new file mode 100644 index 0000000000000..cb96721fb5308 --- /dev/null +++ b/pkgs/development/libraries/opencv/cuda_opt_flow.patch @@ -0,0 +1,26 @@ +diff --git a/opencv_contrib/cudaoptflow/CMakeLists.txt b/opencv_contrib/cudaoptflow/CMakeLists.txt +index e5b823ab4a..a728060d0b 100644 +--- a/opencv_contrib/cudaoptflow/CMakeLists.txt ++++ b/opencv_contrib/cudaoptflow/CMakeLists.txt +@@ -11,18 +11,6 @@ ocv_define_module(cudaoptflow opencv_video opencv_optflow opencv_cudaarithm open + set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT "79c6cee80a2df9a196f20afd6b598a9810964c32") + set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_MD5 "ca5acedee6cb45d0ec610a6732de5c15") + set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH "${OpenCV_BINARY_DIR}/3rdparty/NVIDIAOpticalFlowSDK_1_0_Headers") +-ocv_download(FILENAME "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT}.zip" +- HASH ${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_MD5} +- URL +- "https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/" +- DESTINATION_DIR "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}" +- STATUS NVIDIA_OPTICAL_FLOW_1_0_HEADERS_DOWNLOAD_SUCCESS +- ID "NVIDIA_OPTICAL_FLOW" +- UNPACK RELATIVE_URL) + +-if(NOT NVIDIA_OPTICAL_FLOW_1_0_HEADERS_DOWNLOAD_SUCCESS) +- message(STATUS "Failed to download NVIDIA_Optical_Flow_1_0 Headers") +-else() +- add_definitions(-DHAVE_NVIDIA_OPTFLOW=1) +- ocv_include_directories(SYSTEM "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}/NVIDIAOpticalFlowSDK-${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT}") +-endif() +\ No newline at end of file ++add_definitions(-DHAVE_NVIDIA_OPTFLOW=1) ++ocv_include_directories(SYSTEM "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}") diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 3d259a3b023e6..e0b411088abbb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13797,6 +13797,8 @@ in nvidia-video-sdk = callPackage ../development/libraries/nvidia-video-sdk { }; + nvidia-optical-flow-sdk = callPackage ../development/libraries/nvidia-optical-flow-sdk { }; + nvtop = callPackage ../tools/system/nvtop { nvidia_x11 = linuxPackages.nvidia_x11.override { libsOnly = true; }; }; |