2021-04-22 02:08:21 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchurl
|
|
|
|
, fetchFromGitHub
|
|
|
|
, cmake
|
|
|
|
, pkg-config
|
|
|
|
, unzip
|
|
|
|
, zlib
|
2024-02-29 20:09:43 +00:00
|
|
|
, pcre2
|
2021-04-22 02:08:21 +00:00
|
|
|
, hdf5
|
|
|
|
, boost
|
2024-02-29 20:09:43 +00:00
|
|
|
, glib
|
2021-04-22 02:08:21 +00:00
|
|
|
, gflags
|
2023-11-16 04:20:00 +00:00
|
|
|
, protobuf_21
|
2020-04-24 23:36:52 +00:00
|
|
|
, config
|
2021-10-17 02:12:59 +00:00
|
|
|
, ocl-icd
|
2022-08-12 12:06:08 +00:00
|
|
|
, buildPackages
|
2023-01-20 10:41:00 +00:00
|
|
|
, qimgv
|
2023-02-16 17:41:37 +00:00
|
|
|
, opencv4
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableJPEG ? true
|
|
|
|
, libjpeg
|
|
|
|
, enablePNG ? true
|
|
|
|
, libpng
|
|
|
|
, enableTIFF ? true
|
|
|
|
, libtiff
|
|
|
|
, enableWebP ? true
|
|
|
|
, libwebp
|
2024-09-26 11:04:55 +00:00
|
|
|
, enableEXR ? !stdenv.hostPlatform.isDarwin
|
2021-04-22 02:08:21 +00:00
|
|
|
, openexr
|
|
|
|
, ilmbase
|
2022-08-12 12:06:08 +00:00
|
|
|
, enableJPEG2000 ? true
|
|
|
|
, openjpeg
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableEigen ? true
|
|
|
|
, eigen
|
2023-02-16 17:41:37 +00:00
|
|
|
, enableBlas ? true
|
|
|
|
, blas
|
2024-09-26 11:04:55 +00:00
|
|
|
, enableVA ? !stdenv.hostPlatform.isDarwin
|
2024-02-29 20:09:43 +00:00
|
|
|
, libva
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableContrib ? true
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
, enableCuda ? config.cudaSupport
|
2023-04-12 12:48:02 +00:00
|
|
|
, enableCublas ? enableCuda
|
|
|
|
, enableCudnn ? false # NOTE: CUDNN has a large impact on closure size so we disable it by default
|
|
|
|
, enableCufft ? enableCuda
|
|
|
|
, cudaPackages ? {}
|
2021-04-22 02:08:21 +00:00
|
|
|
, nvidia-optical-flow-sdk
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
, enableLto ? true
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableUnfree ? false
|
|
|
|
, enableIpp ? false
|
|
|
|
, enablePython ? false
|
|
|
|
, pythonPackages
|
|
|
|
, enableGtk2 ? false
|
|
|
|
, gtk2
|
|
|
|
, enableGtk3 ? false
|
|
|
|
, gtk3
|
|
|
|
, enableVtk ? false
|
2023-02-09 11:40:11 +00:00
|
|
|
, vtk
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableFfmpeg ? true
|
2021-05-20 23:08:51 +00:00
|
|
|
, ffmpeg
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableGStreamer ? true
|
2024-02-29 20:09:43 +00:00
|
|
|
, elfutils
|
2021-04-22 02:08:21 +00:00
|
|
|
, gst_all_1
|
2024-02-29 20:09:43 +00:00
|
|
|
, orc
|
|
|
|
, libunwind
|
|
|
|
, zstd
|
2021-04-22 02:08:21 +00:00
|
|
|
, enableTesseract ? false
|
|
|
|
, tesseract
|
|
|
|
, leptonica
|
|
|
|
, enableTbb ? false
|
|
|
|
, tbb
|
|
|
|
, enableOvis ? false
|
|
|
|
, ogre
|
|
|
|
, enableGPhoto2 ? false
|
|
|
|
, libgphoto2
|
|
|
|
, enableDC1394 ? false
|
|
|
|
, libdc1394
|
|
|
|
, enableDocs ? false
|
|
|
|
, doxygen
|
|
|
|
, graphviz-nox
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
, runAccuracyTests ? true
|
|
|
|
, runPerformanceTests ? false
|
|
|
|
# Modules to enable via BUILD_LIST to build a customized opencv.
|
|
|
|
# An empty lists means this setting is ommited which matches upstreams default.
|
|
|
|
, enabledModules ? [ ]
|
|
|
|
|
2021-04-22 02:08:21 +00:00
|
|
|
, AVFoundation
|
|
|
|
, Cocoa
|
|
|
|
, VideoDecodeAcceleration
|
|
|
|
, CoreMedia
|
|
|
|
, MediaToolbox
|
2023-04-12 12:48:02 +00:00
|
|
|
, Accelerate
|
2021-04-22 02:08:21 +00:00
|
|
|
, bzip2
|
2023-02-16 17:41:37 +00:00
|
|
|
, callPackage
|
2023-11-16 04:20:00 +00:00
|
|
|
}@inputs:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2024-09-26 11:04:55 +00:00
|
|
|
inherit (lib.attrsets) mapAttrsToList optionalAttrs;
|
|
|
|
inherit (lib.lists) last optionals;
|
|
|
|
inherit (lib.meta) getExe;
|
|
|
|
inherit (lib.strings) cmakeBool cmakeFeature cmakeOptionType concatStrings concatStringsSep optionalString;
|
|
|
|
inherit (lib.trivial) flip;
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
version = "4.9.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
# It's necessary to consistently use backendStdenv when building with CUDA
|
|
|
|
# support, otherwise we get libstdc++ errors downstream
|
|
|
|
stdenv = throw "Use effectiveStdenv instead";
|
|
|
|
effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else inputs.stdenv;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
src = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv";
|
|
|
|
rev = version;
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-3qqu4xlRyMbPKHHTIT+iRRGtpFlcv0NU8GNZpgjdi6k=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
contribSrc = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_contrib";
|
|
|
|
rev = version;
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-K74Ghk4uDqj4OWEzDxT2R3ERi+jkAWZszzezRenfuZ8=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
testDataSrc = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_extra";
|
|
|
|
rev = version;
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-pActKi7aN5EOZq2Fpf5mALnZq71c037/R3Q6wJ4uCfQ=";
|
2023-02-16 17:41:37 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Contrib must be built in order to enable Tesseract support:
|
|
|
|
buildContrib = enableContrib || enableTesseract || enableOvis;
|
|
|
|
|
|
|
|
# See opencv/3rdparty/ippicv/ippicv.cmake
|
|
|
|
ippicv = {
|
|
|
|
src = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
2024-02-29 20:09:43 +00:00
|
|
|
rev = "0cc4aa06bf2bef4b05d237c69a5a96b9cd0cb85a";
|
|
|
|
hash = "sha256-/kHivOgCkY9YdcRRaVgytXal3ChE9xFfGAB0CfFO5ec=";
|
2020-04-24 23:36:52 +00:00
|
|
|
} + "/ippicv";
|
2024-02-29 20:09:43 +00:00
|
|
|
files = let name = platform: "ippicv_2021.10.0_${platform}_20230919_general.tgz"; in
|
2023-11-16 04:20:00 +00:00
|
|
|
if effectiveStdenv.hostPlatform.system == "x86_64-linux" then
|
2024-02-29 20:09:43 +00:00
|
|
|
{ ${name "lnx_intel64"} = "606a19b207ebedfe42d59fd916cc4850"; }
|
2023-11-16 04:20:00 +00:00
|
|
|
else if effectiveStdenv.hostPlatform.system == "i686-linux" then
|
2024-02-29 20:09:43 +00:00
|
|
|
{ ${name "lnx_ia32"} = "ea08487b810baad2f68aca87b74a2db9"; }
|
2023-11-16 04:20:00 +00:00
|
|
|
else if effectiveStdenv.hostPlatform.system == "x86_64-darwin" then
|
2024-02-29 20:09:43 +00:00
|
|
|
{ ${name "mac_intel64"} = "14f01c5a4780bfae9dde9b0aaf5e56fc"; }
|
2020-04-24 23:36:52 +00:00
|
|
|
else
|
2021-04-22 02:08:21 +00:00
|
|
|
throw "ICV is not available for this platform (or not yet supported by this package)";
|
2020-04-24 23:36:52 +00:00
|
|
|
dst = ".cache/ippicv";
|
|
|
|
};
|
|
|
|
|
|
|
|
# See opencv_contrib/modules/xfeatures2d/cmake/download_vgg.cmake
|
|
|
|
vgg = {
|
|
|
|
src = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-fjdGM+CxV1QX7zmF2AiR9NDknrP2PjyaxtjT21BVLmU=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
files = {
|
2021-04-22 02:08:21 +00:00
|
|
|
"vgg_generated_48.i" = "e8d0dcd54d1bcfdc29203d011a797179";
|
|
|
|
"vgg_generated_64.i" = "7126a5d9a8884ebca5aea5d63d677225";
|
|
|
|
"vgg_generated_80.i" = "7cd47228edec52b6d82f46511af325c5";
|
2020-04-24 23:36:52 +00:00
|
|
|
"vgg_generated_120.i" = "151805e03568c9f490a5e3a872777b75";
|
|
|
|
};
|
|
|
|
dst = ".cache/xfeatures2d/vgg";
|
|
|
|
};
|
|
|
|
|
|
|
|
# See opencv_contrib/modules/xfeatures2d/cmake/download_boostdesc.cmake
|
|
|
|
boostdesc = {
|
|
|
|
src = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "34e4206aef44d50e6bbcd0ab06354b52e7466d26";
|
2020-04-24 23:36:52 +00:00
|
|
|
sha256 = "13yig1xhvgghvxspxmdidss5lqiikpjr0ddm83jsi0k85j92sn62";
|
|
|
|
};
|
|
|
|
files = {
|
2021-04-22 02:08:21 +00:00
|
|
|
"boostdesc_bgm.i" = "0ea90e7a8f3f7876d450e4149c97c74f";
|
|
|
|
"boostdesc_bgm_bi.i" = "232c966b13651bd0e46a1497b0852191";
|
|
|
|
"boostdesc_bgm_hd.i" = "324426a24fa56ad9c5b8e3e0b3e5303e";
|
2020-04-24 23:36:52 +00:00
|
|
|
"boostdesc_binboost_064.i" = "202e1b3e9fec871b04da31f7f016679f";
|
|
|
|
"boostdesc_binboost_128.i" = "98ea99d399965c03d555cef3ea502a0b";
|
|
|
|
"boostdesc_binboost_256.i" = "e6dcfa9f647779eb1ce446a8d759b6ea";
|
2021-04-22 02:08:21 +00:00
|
|
|
"boostdesc_lbgm.i" = "0ae0675534aa318d9668f2a179c2a052";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
dst = ".cache/xfeatures2d/boostdesc";
|
|
|
|
};
|
|
|
|
|
|
|
|
# See opencv_contrib/modules/face/CMakeLists.txt
|
|
|
|
face = {
|
|
|
|
src = fetchFromGitHub {
|
2021-04-22 02:08:21 +00:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "8afa57abc8229d611c4937165d20e2a2d9fc5a12";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-m9yF4kfmpRJybohdRwUTmboeU+SbZQ6F6gm32PDWNBg=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
files = {
|
|
|
|
"face_landmark_model.dat" = "7505c44ca4eb54b4ab1e4777cb96ac05";
|
|
|
|
};
|
|
|
|
dst = ".cache/data";
|
|
|
|
};
|
|
|
|
|
|
|
|
# See opencv/modules/gapi/cmake/DownloadADE.cmake
|
|
|
|
ade = rec {
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://github.com/opencv/ade/archive/${name}";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-WG/GudVpkO10kOJhoKXFMj672kggvyRYCIpezal3wcE=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
name = "v0.1.2d.zip";
|
|
|
|
md5 = "dbb095a8bf3008e91edbbf45d8d34885";
|
2020-04-24 23:36:52 +00:00
|
|
|
dst = ".cache/ade";
|
|
|
|
};
|
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
# See opencv_contrib/modules/wechat_qrcode/CMakeLists.txt
|
2021-04-22 02:08:21 +00:00
|
|
|
wechat_qrcode = {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "a8b69ccc738421293254aec5ddb38bd523503252";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-/n6zHwf0Rdc4v9o4rmETzow/HTv+81DnHP+nL56XiTY=";
|
2021-04-22 02:08:21 +00:00
|
|
|
};
|
|
|
|
files = {
|
|
|
|
"detect.caffemodel" = "238e2b2d6f3c18d6c3a30de0c31e23cf";
|
|
|
|
"detect.prototxt" = "6fb4976b32695f9f5c6305c19f12537d";
|
|
|
|
"sr.caffemodel" = "cbfcd60361a73beb8c583eea7e8e6664";
|
|
|
|
"sr.prototxt" = "69db99927a70df953b471daaba03fbef";
|
|
|
|
};
|
|
|
|
dst = ".cache/wechat_qrcode";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# See opencv/cmake/OpenCVDownload.cmake
|
2024-09-26 11:04:55 +00:00
|
|
|
installExtraFiles = {dst, files, src, ...}: ''
|
|
|
|
mkdir -p "${dst}"
|
|
|
|
'' + concatStrings (flip mapAttrsToList files (name: md5: ''
|
|
|
|
ln -s "${src}/${name}" "${dst}/${md5}-${name}"
|
2020-04-24 23:36:52 +00:00
|
|
|
''));
|
2024-09-26 11:04:55 +00:00
|
|
|
installExtraFile = {dst, md5, name, src, ...}: ''
|
|
|
|
mkdir -p "${dst}"
|
|
|
|
ln -s "${src}" "${dst}/${md5}-${name}"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
withOpenblas = (enableBlas && blas.provider.pname == "openblas");
|
|
|
|
#multithreaded openblas conflicts with opencv multithreading, which manifest itself in hung tests
|
2024-02-29 20:09:43 +00:00
|
|
|
#https://github.com/OpenMathLib/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
|
2023-02-16 17:41:37 +00:00
|
|
|
openblas_ = blas.provider.override { singleThreaded = true; };
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
inherit (cudaPackages) cudaFlags;
|
|
|
|
inherit (cudaFlags) cmakeCudaArchitecturesString cudaCapabilities;
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
effectiveStdenv.mkDerivation {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "opencv";
|
|
|
|
inherit version src;
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
outputs = [
|
|
|
|
"out"
|
2024-01-02 11:29:13 +00:00
|
|
|
"cxxdev"
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals (runAccuracyTests || runPerformanceTests) [
|
2023-02-16 17:41:37 +00:00
|
|
|
"package_tests"
|
|
|
|
];
|
2024-01-02 11:29:13 +00:00
|
|
|
cudaPropagateToOutput = "cxxdev";
|
2023-02-16 17:41:37 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
postUnpack = optionalString buildContrib ''
|
2020-04-24 23:36:52 +00:00
|
|
|
cp --no-preserve=mode -r "${contribSrc}/modules" "$NIX_BUILD_TOP/source/opencv_contrib"
|
|
|
|
'';
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
# Ensures that we use the system OpenEXR rather than the vendored copy of the source included with OpenCV.
|
2020-05-15 21:57:56 +00:00
|
|
|
patches = [
|
|
|
|
./cmake-don-t-use-OpenCVFindOpenEXR.patch
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCuda [
|
|
|
|
./cuda_opt_flow.patch
|
|
|
|
];
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
# This prevents cmake from using libraries in impure paths (which
|
|
|
|
# causes build failure on non NixOS)
|
2020-04-24 23:36:52 +00:00
|
|
|
postPatch = ''
|
|
|
|
sed -i '/Add these standard paths to the search paths for FIND_LIBRARY/,/^\s*$/{d}' CMakeLists.txt
|
|
|
|
'';
|
|
|
|
|
|
|
|
preConfigure =
|
|
|
|
installExtraFile ade +
|
2024-09-26 11:04:55 +00:00
|
|
|
optionalString enableIpp (installExtraFiles ippicv) + (
|
|
|
|
optionalString buildContrib ''
|
2021-04-22 02:08:21 +00:00
|
|
|
cmakeFlagsArray+=("-DOPENCV_EXTRA_MODULES_PATH=$NIX_BUILD_TOP/source/opencv_contrib")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-22 02:08:21 +00:00
|
|
|
${installExtraFiles vgg}
|
|
|
|
${installExtraFiles boostdesc}
|
|
|
|
${installExtraFiles face}
|
|
|
|
${installExtraFiles wechat_qrcode}
|
|
|
|
''
|
|
|
|
);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postConfigure = ''
|
|
|
|
[ -e modules/core/version_string.inc ]
|
|
|
|
echo '"(build info elided)"' > modules/core/version_string.inc
|
|
|
|
'';
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
buildInputs = [
|
|
|
|
boost
|
|
|
|
gflags
|
|
|
|
glib
|
|
|
|
pcre2
|
|
|
|
protobuf_21
|
|
|
|
zlib
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enablePython [
|
2024-02-29 20:09:43 +00:00
|
|
|
pythonPackages.python
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals (effectiveStdenv.buildPlatform == effectiveStdenv.hostPlatform) [
|
2024-02-29 20:09:43 +00:00
|
|
|
hdf5
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableGtk2 [
|
2024-02-29 20:09:43 +00:00
|
|
|
gtk2
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableGtk3 [
|
2024-02-29 20:09:43 +00:00
|
|
|
gtk3
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableVtk [
|
2024-02-29 20:09:43 +00:00
|
|
|
vtk
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableJPEG [
|
2024-02-29 20:09:43 +00:00
|
|
|
libjpeg
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enablePNG [
|
2024-02-29 20:09:43 +00:00
|
|
|
libpng
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableTIFF [
|
2024-02-29 20:09:43 +00:00
|
|
|
libtiff
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableWebP [
|
2024-02-29 20:09:43 +00:00
|
|
|
libwebp
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableEXR [
|
2024-02-29 20:09:43 +00:00
|
|
|
openexr
|
|
|
|
ilmbase
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableJPEG2000 [
|
2024-02-29 20:09:43 +00:00
|
|
|
openjpeg
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableFfmpeg [
|
2024-02-29 20:09:43 +00:00
|
|
|
ffmpeg
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals (enableFfmpeg && effectiveStdenv.hostPlatform.isDarwin) [
|
2024-02-29 20:09:43 +00:00
|
|
|
bzip2
|
|
|
|
VideoDecodeAcceleration
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals (enableGStreamer && effectiveStdenv.hostPlatform.isLinux) [
|
2024-02-29 20:09:43 +00:00
|
|
|
elfutils
|
2024-09-19 14:19:46 +00:00
|
|
|
gst_all_1.gst-plugins-base
|
|
|
|
gst_all_1.gst-plugins-good
|
|
|
|
gst_all_1.gstreamer
|
2024-02-29 20:09:43 +00:00
|
|
|
libunwind
|
|
|
|
orc
|
|
|
|
zstd
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableOvis [
|
2024-02-29 20:09:43 +00:00
|
|
|
ogre
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableGPhoto2 [
|
2024-02-29 20:09:43 +00:00
|
|
|
libgphoto2
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableDC1394 [
|
2024-02-29 20:09:43 +00:00
|
|
|
libdc1394
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableEigen [
|
2024-02-29 20:09:43 +00:00
|
|
|
eigen
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableVA [
|
2024-02-29 20:09:43 +00:00
|
|
|
libva
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableBlas [
|
2024-02-29 20:09:43 +00:00
|
|
|
blas.provider
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableTesseract [
|
2020-04-24 23:36:52 +00:00
|
|
|
# There is seemingly no compile-time flag for Tesseract. It's
|
|
|
|
# simply enabled automatically if contrib is built, and it detects
|
|
|
|
# tesseract & leptonica.
|
2024-02-29 20:09:43 +00:00
|
|
|
tesseract
|
|
|
|
leptonica
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableTbb [
|
2024-02-29 20:09:43 +00:00
|
|
|
tbb
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals effectiveStdenv.hostPlatform.isDarwin [
|
2024-02-29 20:09:43 +00:00
|
|
|
bzip2
|
|
|
|
AVFoundation
|
|
|
|
Cocoa
|
|
|
|
VideoDecodeAcceleration
|
|
|
|
CoreMedia
|
|
|
|
MediaToolbox
|
|
|
|
Accelerate
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableDocs [
|
2024-02-29 20:09:43 +00:00
|
|
|
doxygen
|
|
|
|
graphviz-nox
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCuda [
|
2024-09-19 14:19:46 +00:00
|
|
|
cudaPackages.cuda_cudart
|
|
|
|
cudaPackages.cuda_cccl # <thrust/*>
|
|
|
|
cudaPackages.libnpp # npp.h
|
2024-02-29 20:09:43 +00:00
|
|
|
nvidia-optical-flow-sdk
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCublas [
|
2024-02-29 20:09:43 +00:00
|
|
|
# May start using the default $out instead once
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/271792
|
|
|
|
# has been addressed
|
2024-09-19 14:19:46 +00:00
|
|
|
cudaPackages.libcublas # cublas_v2.h
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCudnn [
|
2024-09-19 14:19:46 +00:00
|
|
|
cudaPackages.cudnn # cudnn.h
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCufft [
|
2024-09-19 14:19:46 +00:00
|
|
|
cudaPackages.libcufft # cufft.h
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
propagatedBuildInputs = optionals enablePython [ pythonPackages.numpy ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
pkg-config
|
|
|
|
unzip
|
|
|
|
] ++ optionals enablePython [
|
2022-01-13 20:06:32 +00:00
|
|
|
pythonPackages.pip
|
|
|
|
pythonPackages.wheel
|
|
|
|
pythonPackages.setuptools
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCuda [
|
2023-11-16 04:20:00 +00:00
|
|
|
cudaPackages.cuda_nvcc
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Configure can't find the library without this.
|
2024-09-26 11:04:55 +00:00
|
|
|
OpenBLAS_HOME = optionalString withOpenblas openblas_.dev;
|
|
|
|
OpenBLAS = optionalString withOpenblas openblas_;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
cmakeFlags = [
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeBool "OPENCV_GENERATE_PKGCONFIG" true)
|
|
|
|
(cmakeBool "WITH_OPENMP" true)
|
|
|
|
(cmakeBool "BUILD_PROTOBUF" false)
|
|
|
|
(cmakeOptionType "path" "Protobuf_PROTOC_EXECUTABLE" (getExe buildPackages.protobuf_21))
|
|
|
|
(cmakeBool "PROTOBUF_UPDATE_FILES" true)
|
|
|
|
(cmakeBool "OPENCV_ENABLE_NONFREE" enableUnfree)
|
|
|
|
(cmakeBool "BUILD_TESTS" runAccuracyTests)
|
|
|
|
(cmakeBool "BUILD_PERF_TESTS" runPerformanceTests)
|
|
|
|
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
|
|
|
|
(cmakeBool "BUILD_DOCS" enableDocs)
|
2022-08-12 12:06:08 +00:00
|
|
|
# "OpenCV disables pkg-config to avoid using of host libraries. Consider using PKG_CONFIG_LIBDIR to specify target SYSROOT"
|
|
|
|
# but we have proper separation of build and host libs :), fixes cross
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeBool "OPENCV_ENABLE_PKG_CONFIG" true)
|
|
|
|
(cmakeBool "WITH_IPP" enableIpp)
|
|
|
|
(cmakeBool "WITH_TIFF" enableTIFF)
|
|
|
|
(cmakeBool "WITH_WEBP" enableWebP)
|
|
|
|
(cmakeBool "WITH_JPEG" enableJPEG)
|
|
|
|
(cmakeBool "WITH_PNG" enablePNG)
|
|
|
|
(cmakeBool "WITH_OPENEXR" enableEXR)
|
|
|
|
(cmakeBool "WITH_OPENJPEG" enableJPEG2000)
|
|
|
|
(cmakeBool "WITH_JASPER" false) # OpenCV falls back to a vendored copy of Jasper when OpenJPEG is disabled
|
|
|
|
(cmakeBool "WITH_TBB" enableTbb)
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
# CUDA options
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeBool "WITH_CUDA" enableCuda)
|
|
|
|
(cmakeBool "WITH_CUBLAS" enableCublas)
|
|
|
|
(cmakeBool "WITH_CUDNN" enableCudnn)
|
|
|
|
(cmakeBool "WITH_CUFFT" enableCufft)
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
# LTO options
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeBool "ENABLE_LTO" enableLto)
|
|
|
|
(cmakeBool "ENABLE_THIN_LTO" (
|
2023-04-12 12:48:02 +00:00
|
|
|
enableLto && (
|
2023-11-16 04:20:00 +00:00
|
|
|
# Only clang supports thin LTO, so we must either be using clang through the effectiveStdenv,
|
|
|
|
effectiveStdenv.cc.isClang ||
|
|
|
|
# or through the backend effectiveStdenv.
|
|
|
|
(enableCuda && effectiveStdenv.cc.isClang)
|
2023-04-12 12:48:02 +00:00
|
|
|
)
|
|
|
|
))
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals enableCuda [
|
|
|
|
(cmakeBool "CUDA_FAST_MATH" true)
|
|
|
|
(cmakeFeature "CUDA_NVCC_FLAGS" "--expt-relaxed-constexpr")
|
2023-03-08 16:32:21 +00:00
|
|
|
|
|
|
|
# OpenCV respects at least three variables:
|
|
|
|
# -DCUDA_GENERATION takes a single arch name, e.g. Volta
|
|
|
|
# -DCUDA_ARCH_BIN takes a semi-colon separated list of real arches, e.g. "8.0;8.6"
|
|
|
|
# -DCUDA_ARCH_PTX takes the virtual arch, e.g. "8.6"
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeFeature "CUDA_ARCH_BIN" cmakeCudaArchitecturesString)
|
|
|
|
(cmakeFeature "CUDA_ARCH_PTX" (last cudaCapabilities))
|
2023-03-08 16:32:21 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeOptionType "path" "NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH" nvidia-optical-flow-sdk.outPath)
|
|
|
|
] ++ optionals effectiveStdenv.hostPlatform.isDarwin [
|
|
|
|
(cmakeBool "WITH_OPENCL" false)
|
|
|
|
(cmakeBool "WITH_LAPACK" false)
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
# Disable unnecessary vendoring that's enabled by default only for Darwin.
|
|
|
|
# Note that the opencvFlag feature flags listed above still take
|
|
|
|
# precedence, so we can safely list everything here.
|
2024-09-26 11:04:55 +00:00
|
|
|
(cmakeBool "BUILD_ZLIB" false)
|
|
|
|
(cmakeBool "BUILD_TIFF" false)
|
|
|
|
(cmakeBool "BUILD_OPENJPEG" false)
|
|
|
|
(cmakeBool "BUILD_JASPER" false)
|
|
|
|
(cmakeBool "BUILD_JPEG" false)
|
|
|
|
(cmakeBool "BUILD_PNG" false)
|
|
|
|
(cmakeBool "BUILD_WEBP" false)
|
|
|
|
] ++ optionals (!effectiveStdenv.hostPlatform.isDarwin) [
|
|
|
|
(cmakeOptionType "path" "OPENCL_LIBRARY" "${ocl-icd}/lib/libOpenCL.so")
|
|
|
|
] ++ optionals enablePython [
|
2024-10-09 16:51:18 +00:00
|
|
|
(cmakeOptionType "path" "OPENCV_PYTHON_INSTALL_PATH" pythonPackages.python.sitePackages)
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ optionals (enabledModules != [ ]) [
|
|
|
|
(cmakeFeature "BUILD_LIST" (concatStringsSep "," enabledModules))
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
postBuild = optionalString enableDocs ''
|
2020-04-24 23:36:52 +00:00
|
|
|
make doxygen
|
|
|
|
'';
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
preInstall =
|
2024-09-26 11:04:55 +00:00
|
|
|
optionalString (runAccuracyTests || runPerformanceTests) ''
|
|
|
|
mkdir $package_tests
|
|
|
|
cp -R $src/samples $package_tests/
|
|
|
|
'' + optionalString runAccuracyTests ''
|
|
|
|
mv ./bin/*test* $package_tests/
|
|
|
|
'' + optionalString runPerformanceTests ''
|
|
|
|
mv ./bin/*perf* $package_tests/
|
|
|
|
'';
|
2023-02-16 17:41:37 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# By default $out/lib/pkgconfig/opencv4.pc looks something like this:
|
|
|
|
#
|
|
|
|
# prefix=/nix/store/g0wnfyjjh4rikkvp22cpkh41naa43i4i-opencv-4.0.0
|
|
|
|
# exec_prefix=${prefix}
|
|
|
|
# libdir=${exec_prefix}//nix/store/g0wnfyjjh4rikkvp22cpkh41naa43i4i-opencv-4.0.0/lib
|
|
|
|
# includedir_old=${prefix}//nix/store/g0wnfyjjh4rikkvp22cpkh41naa43i4i-opencv-4.0.0/include/opencv4/opencv
|
|
|
|
# includedir_new=${prefix}//nix/store/g0wnfyjjh4rikkvp22cpkh41naa43i4i-opencv-4.0.0/include/opencv4
|
|
|
|
# ...
|
|
|
|
# Libs: -L${exec_prefix}//nix/store/g0wnfyjjh4rikkvp22cpkh41naa43i4i-opencv-4.0.0/lib ...
|
|
|
|
# Note that ${exec_prefix} is set to $out but that $out is also appended to
|
|
|
|
# ${exec_prefix}. This causes linker errors in downstream packages so we strip
|
|
|
|
# of $out after the ${exec_prefix} and ${prefix} prefixes:
|
|
|
|
postInstall = ''
|
|
|
|
sed -i "s|{exec_prefix}/$out|{exec_prefix}|;s|{prefix}/$out|{prefix}|" \
|
|
|
|
"$out/lib/pkgconfig/opencv4.pc"
|
2024-01-02 11:29:13 +00:00
|
|
|
mkdir "$cxxdev"
|
|
|
|
''
|
|
|
|
# fix deps not progagating from opencv4.cxxdev if cuda is disabled
|
|
|
|
# see https://github.com/NixOS/nixpkgs/issues/276691
|
2024-09-26 11:04:55 +00:00
|
|
|
+ optionalString (!enableCuda) ''
|
2024-01-02 11:29:13 +00:00
|
|
|
mkdir -p "$cxxdev/nix-support"
|
|
|
|
echo "''${!outputDev}" >> "$cxxdev/nix-support/propagated-build-inputs"
|
2022-01-13 20:06:32 +00:00
|
|
|
''
|
2024-09-26 11:04:55 +00:00
|
|
|
# remove the requirement that the exact same version of CUDA is used in packages
|
|
|
|
# consuming OpenCV's CMakes files
|
|
|
|
+ optionalString enableCuda ''
|
|
|
|
substituteInPlace "$out/lib/cmake/opencv4/OpenCVConfig.cmake" \
|
|
|
|
--replace-fail \
|
|
|
|
'find_host_package(CUDA ''${OpenCV_CUDA_VERSION} EXACT REQUIRED)' \
|
|
|
|
'find_host_package(CUDA REQUIRED)' \
|
|
|
|
--replace-fail \
|
|
|
|
'message(FATAL_ERROR "OpenCV static library was compiled with CUDA' \
|
|
|
|
'message("OpenCV static library was compiled with CUDA'
|
|
|
|
''
|
2022-01-13 20:06:32 +00:00
|
|
|
# install python distribution information, so other packages can `import opencv`
|
2024-09-26 11:04:55 +00:00
|
|
|
+ optionalString enablePython ''
|
2022-01-13 20:06:32 +00:00
|
|
|
pushd $NIX_BUILD_TOP/$sourceRoot/modules/python/package
|
|
|
|
python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
|
|
|
|
|
|
|
|
pushd dist
|
|
|
|
python -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache
|
|
|
|
|
|
|
|
popd
|
|
|
|
popd
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
passthru = {
|
2024-01-02 11:29:13 +00:00
|
|
|
cudaSupport = enableCuda;
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
tests = {
|
|
|
|
inherit (gst_all_1) gst-plugins-bad;
|
2023-02-16 17:41:37 +00:00
|
|
|
}
|
2024-09-26 11:04:55 +00:00
|
|
|
// optionalAttrs (!effectiveStdenv.hostPlatform.isDarwin) { inherit qimgv; }
|
|
|
|
// optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; }
|
|
|
|
// optionalAttrs (effectiveStdenv.buildPlatform != "x86_64-darwin") {
|
2023-02-16 17:41:37 +00:00
|
|
|
opencv4-tests = callPackage ./tests.nix {
|
|
|
|
inherit enableGStreamer enableGtk2 enableGtk3 runAccuracyTests runPerformanceTests testDataSrc;
|
|
|
|
inherit opencv4;
|
|
|
|
};
|
2023-11-16 04:20:00 +00:00
|
|
|
}
|
2024-09-26 11:04:55 +00:00
|
|
|
// optionalAttrs (enableCuda) {
|
2023-11-16 04:20:00 +00:00
|
|
|
no-libstdcxx-errors = callPackage ./libstdcxx-test.nix { attrName = "opencv4"; };
|
|
|
|
};
|
2024-09-26 11:04:55 +00:00
|
|
|
} // optionalAttrs enablePython { pythonPath = [ ]; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
meta = {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Open Computer Vision Library with more than 500 algorithms";
|
|
|
|
homepage = "https://opencv.org/";
|
2024-09-19 14:19:46 +00:00
|
|
|
license = if enableUnfree then lib.licenses.unfree else lib.licenses.bsd3;
|
|
|
|
maintainers = with lib.maintainers; [ basvandijk ];
|
|
|
|
platforms = with lib.platforms; linux ++ darwin;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|