2017-10-20 18:36:37 +02:00
|
|
|
{ lib, stdenv
|
2019-06-16 21:59:06 +02:00
|
|
|
, fetchFromGitHub, fetchpatch
|
2021-01-19 07:50:56 +01:00
|
|
|
, cmake, pkg-config, unzip, zlib, pcre, hdf5
|
2019-07-25 11:04:55 +02:00
|
|
|
, glog, boost, gflags, protobuf
|
2017-10-20 18:36:37 +02:00
|
|
|
, config
|
2017-01-24 09:25:10 +01:00
|
|
|
|
|
|
|
, enableJPEG ? true, libjpeg
|
|
|
|
, enablePNG ? true, libpng
|
|
|
|
, enableTIFF ? true, libtiff
|
|
|
|
, enableWebP ? true, libwebp
|
2019-02-03 16:33:15 +01:00
|
|
|
, enableEXR ? !stdenv.isDarwin, openexr, ilmbase
|
2017-10-20 18:36:37 +02:00
|
|
|
, enableEigen ? true, eigen
|
2020-03-31 16:47:18 +02:00
|
|
|
, enableOpenblas ? true, openblas, blas, lapack
|
2018-02-25 20:07:46 +01:00
|
|
|
, enableContrib ? true
|
2017-10-20 18:36:37 +02:00
|
|
|
|
2019-08-07 21:30:58 +02:00
|
|
|
, enableCuda ? (config.cudaSupport or false) &&
|
|
|
|
stdenv.hostPlatform.isx86_64, cudatoolkit
|
2017-01-24 09:25:10 +01:00
|
|
|
|
2017-12-31 13:22:50 +01:00
|
|
|
, enableUnfree ? false
|
2017-01-24 09:25:10 +01:00
|
|
|
, enableIpp ? false
|
2021-03-25 11:18:05 +01:00
|
|
|
, enablePython ? false, pythonPackages ? null
|
2017-01-24 09:25:10 +01:00
|
|
|
, enableGtk2 ? false, gtk2
|
|
|
|
, enableGtk3 ? false, gtk3
|
2017-12-31 01:21:39 +01:00
|
|
|
, enableVtk ? false, vtk
|
2020-06-07 14:39:09 +02:00
|
|
|
, enableFfmpeg ? false, ffmpeg_3
|
2016-06-07 16:09:22 +02:00
|
|
|
, enableGStreamer ? false, gst_all_1
|
2017-06-28 16:19:01 +02:00
|
|
|
, enableTesseract ? false, tesseract, leptonica
|
2018-03-01 15:45:15 +01:00
|
|
|
, enableTbb ? false, tbb
|
2017-12-31 01:21:39 +01:00
|
|
|
, enableOvis ? false, ogre
|
|
|
|
, enableGPhoto2 ? false, libgphoto2
|
|
|
|
, enableDC1394 ? false, libdc1394
|
2017-10-20 18:36:37 +02:00
|
|
|
, enableDocs ? false, doxygen, graphviz-nox
|
|
|
|
|
2019-06-19 20:14:17 +02:00
|
|
|
, AVFoundation, Cocoa, VideoDecodeAcceleration, bzip2
|
2016-06-07 16:09:22 +02:00
|
|
|
}:
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2020-03-31 16:47:18 +02:00
|
|
|
assert blas.implementation == "openblas" && lapack.implementation == "openblas";
|
|
|
|
|
2021-03-25 11:18:05 +01:00
|
|
|
assert enablePython -> pythonPackages != null;
|
|
|
|
|
2015-09-11 14:48:33 +02:00
|
|
|
let
|
2019-11-02 19:21:44 +01:00
|
|
|
version = "3.4.8";
|
2017-01-24 09:25:10 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv";
|
|
|
|
rev = version;
|
2019-11-02 19:21:44 +01:00
|
|
|
sha256 = "1dnz3gfj70lm1gbrk8pz28apinlqi2x6nvd6xcy5hs08505nqnjp";
|
2017-01-24 09:25:10 +01:00
|
|
|
};
|
2015-09-11 14:48:33 +02:00
|
|
|
|
2016-06-07 16:09:22 +02:00
|
|
|
contribSrc = fetchFromGitHub {
|
2017-01-24 09:25:10 +01:00
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_contrib";
|
|
|
|
rev = version;
|
2019-11-02 19:21:44 +01:00
|
|
|
sha256 = "0psaa1yx36n34l09zd1y8jxgf8q4jzxd3vn06fqmzwzy85hcqn8i";
|
2017-06-17 19:57:39 +02:00
|
|
|
};
|
|
|
|
|
2017-06-28 16:19:01 +02:00
|
|
|
# Contrib must be built in order to enable Tesseract support:
|
|
|
|
buildContrib = enableContrib || enableTesseract;
|
|
|
|
|
2018-11-25 11:22:51 +01:00
|
|
|
useSystemProtobuf = ! stdenv.isDarwin;
|
|
|
|
|
2017-10-20 18:36:37 +02:00
|
|
|
# See opencv/3rdparty/ippicv/ippicv.cmake
|
|
|
|
ippicv = {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
2019-07-27 01:46:38 +02:00
|
|
|
rev = "32e315a5b106a7b89dbed51c28f8120a48b368b4";
|
|
|
|
sha256 = "19w9f0r16072s59diqxsr5q6nmwyz9gnxjs49nglzhd66p3ddbkp";
|
2017-10-20 18:36:37 +02:00
|
|
|
} + "/ippicv";
|
2019-07-27 01:46:38 +02:00
|
|
|
files = let name = platform : "ippicv_2019_${platform}_general_20180723.tgz"; in
|
2018-08-20 21:11:29 +02:00
|
|
|
if stdenv.hostPlatform.system == "x86_64-linux" then
|
2019-07-27 01:46:38 +02:00
|
|
|
{ ${name "lnx_intel64"} = "c0bd78adb4156bbf552c1dfe90599607"; }
|
2018-08-20 21:11:29 +02:00
|
|
|
else if stdenv.hostPlatform.system == "i686-linux" then
|
2019-07-27 01:46:38 +02:00
|
|
|
{ ${name "lnx_ia32"} = "4f38432c30bfd6423164b7a24bbc98a0"; }
|
2018-08-20 21:11:29 +02:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-darwin" then
|
2019-07-27 01:46:38 +02:00
|
|
|
{ ${name "mac_intel64"} = "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2"; }
|
2017-10-20 18:36:37 +02:00
|
|
|
else
|
|
|
|
throw "ICV is not available for this platform (or not yet supported by this package)";
|
|
|
|
dst = ".cache/ippicv";
|
2017-01-24 09:25:10 +01:00
|
|
|
};
|
|
|
|
|
2017-10-20 18:36:37 +02:00
|
|
|
# See opencv_contrib/modules/xfeatures2d/cmake/download_vgg.cmake
|
|
|
|
vgg = {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d";
|
|
|
|
sha256 = "0r9fam8dplyqqsd3qgpnnfgf9l7lj44di19rxwbm8mxiw0rlcdvy";
|
|
|
|
};
|
|
|
|
files = {
|
|
|
|
"vgg_generated_48.i" = "e8d0dcd54d1bcfdc29203d011a797179";
|
|
|
|
"vgg_generated_64.i" = "7126a5d9a8884ebca5aea5d63d677225";
|
|
|
|
"vgg_generated_80.i" = "7cd47228edec52b6d82f46511af325c5";
|
|
|
|
"vgg_generated_120.i" = "151805e03568c9f490a5e3a872777b75";
|
|
|
|
};
|
|
|
|
dst = ".cache/xfeatures2d/vgg";
|
|
|
|
};
|
|
|
|
|
|
|
|
# See opencv_contrib/modules/xfeatures2d/cmake/download_boostdesc.cmake
|
|
|
|
boostdesc = {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "34e4206aef44d50e6bbcd0ab06354b52e7466d26";
|
|
|
|
sha256 = "13yig1xhvgghvxspxmdidss5lqiikpjr0ddm83jsi0k85j92sn62";
|
|
|
|
};
|
|
|
|
files = {
|
|
|
|
"boostdesc_bgm.i" = "0ea90e7a8f3f7876d450e4149c97c74f";
|
|
|
|
"boostdesc_bgm_bi.i" = "232c966b13651bd0e46a1497b0852191";
|
|
|
|
"boostdesc_bgm_hd.i" = "324426a24fa56ad9c5b8e3e0b3e5303e";
|
|
|
|
"boostdesc_binboost_064.i" = "202e1b3e9fec871b04da31f7f016679f";
|
|
|
|
"boostdesc_binboost_128.i" = "98ea99d399965c03d555cef3ea502a0b";
|
|
|
|
"boostdesc_binboost_256.i" = "e6dcfa9f647779eb1ce446a8d759b6ea";
|
|
|
|
"boostdesc_lbgm.i" = "0ae0675534aa318d9668f2a179c2a052";
|
|
|
|
};
|
|
|
|
dst = ".cache/xfeatures2d/boostdesc";
|
|
|
|
};
|
|
|
|
|
2017-12-31 01:21:39 +01:00
|
|
|
# See opencv_contrib/modules/face/CMakeLists.txt
|
|
|
|
face = {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "8afa57abc8229d611c4937165d20e2a2d9fc5a12";
|
|
|
|
sha256 = "061lsvqdidq9xa2hwrcvwi9ixflr2c2lfpc8drr159g68zi8bp4v";
|
|
|
|
};
|
|
|
|
files = {
|
|
|
|
"face_landmark_model.dat" = "7505c44ca4eb54b4ab1e4777cb96ac05";
|
|
|
|
};
|
|
|
|
dst = ".cache/data";
|
|
|
|
};
|
|
|
|
|
2017-10-29 22:23:41 +01:00
|
|
|
# See opencv/cmake/OpenCVDownload.cmake
|
2017-10-20 18:36:37 +02:00
|
|
|
installExtraFiles = extra : with lib; ''
|
|
|
|
mkdir -p "${extra.dst}"
|
|
|
|
'' + concatStrings (mapAttrsToList (name : md5 : ''
|
|
|
|
ln -s "${extra.src}/${name}" "${extra.dst}/${md5}-${name}"
|
|
|
|
'') extra.files);
|
|
|
|
|
2017-12-31 13:22:50 +01:00
|
|
|
opencvFlag = name: enabled: "-DWITH_${name}=${printEnabled enabled}";
|
2017-10-20 18:36:37 +02:00
|
|
|
|
2017-12-31 13:22:50 +01:00
|
|
|
printEnabled = enabled : if enabled then "ON" else "OFF";
|
2015-09-11 14:48:33 +02:00
|
|
|
in
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
stdenv.mkDerivation {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "opencv";
|
2017-01-24 09:25:10 +01:00
|
|
|
inherit version src;
|
|
|
|
|
2017-10-20 18:36:37 +02:00
|
|
|
postUnpack = lib.optionalString buildContrib ''
|
|
|
|
cp --no-preserve=mode -r "${contribSrc}/modules" "$NIX_BUILD_TOP/opencv_contrib"
|
|
|
|
'';
|
2017-05-15 22:45:52 +02:00
|
|
|
|
2017-07-27 03:03:51 +02:00
|
|
|
# This prevents cmake from using libraries in impure paths (which
|
|
|
|
# causes build failure on non NixOS)
|
|
|
|
# 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:
|
2017-05-15 22:45:52 +02:00
|
|
|
postPatch = ''
|
|
|
|
sed -i '/Add these standard paths to the search paths for FIND_LIBRARY/,/^\s*$/{d}' CMakeLists.txt
|
2017-07-27 03:03:51 +02:00
|
|
|
sed -i -e 's|if len(decls) == 0:|if len(decls) == 0 or "opencv2/" not in hdr:|' ./modules/python/src2/gen2.py
|
2017-05-15 22:45:52 +02:00
|
|
|
'';
|
|
|
|
|
2016-10-22 18:49:20 +02:00
|
|
|
preConfigure =
|
2018-03-25 14:35:40 +02:00
|
|
|
lib.optionalString enableIpp (installExtraFiles ippicv) + (
|
2017-10-20 18:36:37 +02:00
|
|
|
lib.optionalString buildContrib ''
|
2017-01-24 09:25:10 +01:00
|
|
|
cmakeFlagsArray+=("-DOPENCV_EXTRA_MODULES_PATH=$NIX_BUILD_TOP/opencv_contrib")
|
2017-10-20 18:36:37 +02:00
|
|
|
|
|
|
|
${installExtraFiles vgg}
|
|
|
|
${installExtraFiles boostdesc}
|
2017-12-31 01:21:39 +01:00
|
|
|
${installExtraFiles face}
|
2017-01-24 09:25:10 +01:00
|
|
|
'');
|
2015-09-11 14:32:42 +02:00
|
|
|
|
2018-10-08 19:34:26 +02:00
|
|
|
postConfigure = ''
|
|
|
|
[ -e modules/core/version_string.inc ]
|
|
|
|
echo '"(build info elided)"' > modules/core/version_string.inc
|
|
|
|
'';
|
|
|
|
|
2015-09-01 14:53:32 +02:00
|
|
|
buildInputs =
|
2019-07-25 11:04:55 +02:00
|
|
|
[ zlib pcre hdf5 glog boost gflags ]
|
2018-11-25 11:22:51 +01:00
|
|
|
++ lib.optional useSystemProtobuf protobuf
|
2016-06-07 20:26:33 +02:00
|
|
|
++ lib.optional enablePython pythonPackages.python
|
2016-06-07 16:09:22 +02:00
|
|
|
++ lib.optional enableGtk2 gtk2
|
|
|
|
++ lib.optional enableGtk3 gtk3
|
2017-12-31 01:21:39 +01:00
|
|
|
++ lib.optional enableVtk vtk
|
2016-06-07 16:09:22 +02:00
|
|
|
++ lib.optional enableJPEG libjpeg
|
|
|
|
++ lib.optional enablePNG libpng
|
|
|
|
++ lib.optional enableTIFF libtiff
|
|
|
|
++ lib.optional enableWebP libwebp
|
|
|
|
++ lib.optionals enableEXR [ openexr ilmbase ]
|
2020-06-07 14:39:09 +02:00
|
|
|
++ lib.optional enableFfmpeg ffmpeg_3
|
2018-01-06 02:32:04 +01:00
|
|
|
++ lib.optionals (enableFfmpeg && stdenv.isDarwin)
|
|
|
|
[ VideoDecodeAcceleration bzip2 ]
|
2016-06-07 16:09:22 +02:00
|
|
|
++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base ])
|
2017-12-31 01:21:39 +01:00
|
|
|
++ lib.optional enableOvis ogre
|
|
|
|
++ lib.optional enableGPhoto2 libgphoto2
|
|
|
|
++ lib.optional enableDC1394 libdc1394
|
2016-06-07 16:09:22 +02:00
|
|
|
++ lib.optional enableEigen eigen
|
2017-06-20 14:59:30 +02:00
|
|
|
++ lib.optional enableOpenblas openblas
|
2017-06-28 16:19:01 +02:00
|
|
|
# There is seemingly no compile-time flag for Tesseract. It's
|
|
|
|
# simply enabled automatically if contrib is built, and it detects
|
|
|
|
# tesseract & leptonica.
|
|
|
|
++ lib.optionals enableTesseract [ tesseract leptonica ]
|
2018-03-01 15:45:15 +01:00
|
|
|
++ lib.optional enableTbb tbb
|
2017-10-16 02:34:16 +02:00
|
|
|
++ lib.optional enableCuda cudatoolkit
|
2019-06-19 20:14:17 +02:00
|
|
|
++ lib.optionals stdenv.isDarwin [ bzip2 AVFoundation Cocoa VideoDecodeAcceleration ]
|
2017-10-20 18:36:37 +02:00
|
|
|
++ lib.optionals enableDocs [ doxygen graphviz-nox ];
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2016-06-07 20:26:33 +02:00
|
|
|
propagatedBuildInputs = lib.optional enablePython pythonPackages.numpy;
|
|
|
|
|
2021-01-19 07:50:56 +01:00
|
|
|
nativeBuildInputs = [ cmake pkg-config unzip ];
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2019-10-30 01:40:49 +01:00
|
|
|
NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2018-02-25 18:05:57 +01:00
|
|
|
# Configure can't find the library without this.
|
|
|
|
OpenBLAS_HOME = lib.optionalString enableOpenblas openblas;
|
|
|
|
|
2015-09-11 14:48:33 +02:00
|
|
|
cmakeFlags = [
|
2017-10-20 18:36:37 +02:00
|
|
|
"-DWITH_OPENMP=ON"
|
2018-11-25 11:22:51 +01:00
|
|
|
"-DBUILD_PROTOBUF=${printEnabled (!useSystemProtobuf)}"
|
|
|
|
"-DPROTOBUF_UPDATE_FILES=${printEnabled useSystemProtobuf}"
|
2017-12-31 13:22:50 +01:00
|
|
|
"-DOPENCV_ENABLE_NONFREE=${printEnabled enableUnfree}"
|
2018-02-25 18:04:52 +01:00
|
|
|
"-DBUILD_TESTS=OFF"
|
|
|
|
"-DBUILD_PERF_TESTS=OFF"
|
2018-03-02 12:53:54 +01:00
|
|
|
"-DBUILD_DOCS=${printEnabled enableDocs}"
|
2017-10-20 18:36:37 +02:00
|
|
|
(opencvFlag "IPP" enableIpp)
|
2016-06-07 16:09:22 +02:00
|
|
|
(opencvFlag "TIFF" enableTIFF)
|
|
|
|
(opencvFlag "WEBP" enableWebP)
|
|
|
|
(opencvFlag "JPEG" enableJPEG)
|
|
|
|
(opencvFlag "PNG" enablePNG)
|
|
|
|
(opencvFlag "OPENEXR" enableEXR)
|
2016-11-04 14:18:50 +01:00
|
|
|
(opencvFlag "CUDA" enableCuda)
|
|
|
|
(opencvFlag "CUBLAS" enableCuda)
|
2018-03-01 15:45:15 +01:00
|
|
|
(opencvFlag "TBB" enableTbb)
|
2017-10-16 03:25:18 +02:00
|
|
|
] ++ lib.optionals enableCuda [
|
|
|
|
"-DCUDA_FAST_MATH=ON"
|
2018-02-25 18:06:20 +01:00
|
|
|
"-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
|
|
|
|
"-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr"
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
"-DWITH_OPENCL=OFF"
|
|
|
|
"-DWITH_LAPACK=OFF"
|
2019-06-06 06:59:44 +02:00
|
|
|
"-DBUILD_opencv_videoio=OFF"
|
2018-11-25 11:22:51 +01:00
|
|
|
] ++ lib.optionals enablePython [
|
|
|
|
"-DOPENCV_SKIP_PYTHON_LOADER=ON"
|
2019-07-27 01:46:38 +02:00
|
|
|
] ++ lib.optional enableEigen [
|
|
|
|
# Autodetection broken by https://github.com/opencv/opencv/pull/13337
|
|
|
|
"-DEIGEN_INCLUDE_PATH=${eigen}/include/eigen3"
|
2018-02-25 18:06:20 +01:00
|
|
|
];
|
2015-09-01 22:20:38 +02:00
|
|
|
|
2017-10-20 18:36:37 +02:00
|
|
|
postBuild = lib.optionalString enableDocs ''
|
|
|
|
make doxygen
|
|
|
|
'';
|
|
|
|
|
2018-05-10 12:21:45 +02:00
|
|
|
# By default $out/lib/pkgconfig/opencv.pc looks something like this:
|
|
|
|
#
|
|
|
|
# prefix=/nix/store/10pzq1a8fkh8q4sysj8n6mv0w0nl0miq-opencv-3.4.1
|
|
|
|
# exec_prefix=${prefix}
|
|
|
|
# libdir=${exec_prefix}//nix/store/10pzq1a8fkh8q4sysj8n6mv0w0nl0miq-opencv-3.4.1/lib
|
|
|
|
# ...
|
|
|
|
# Libs: -L${exec_prefix}//nix/store/10pzq1a8fkh8q4sysj8n6mv0w0nl0miq-opencv-3.4.1/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} prefix:
|
|
|
|
postInstall = ''
|
2018-11-25 11:22:51 +01:00
|
|
|
sed -i "s|{exec_prefix}/$out|{exec_prefix}|" \
|
|
|
|
"$out/lib/pkgconfig/opencv.pc"
|
2018-05-10 12:21:45 +02:00
|
|
|
'';
|
|
|
|
|
2016-02-26 18:38:15 +01:00
|
|
|
hardeningDisable = [ "bindnow" "relro" ];
|
2016-02-12 15:15:00 +01:00
|
|
|
|
2016-06-07 16:09:22 +02:00
|
|
|
passthru = lib.optionalAttrs enablePython { pythonPath = []; };
|
|
|
|
|
2021-01-21 18:00:13 +01:00
|
|
|
meta = with lib; {
|
2015-09-01 14:53:32 +02:00
|
|
|
description = "Open Computer Vision Library with more than 500 algorithms";
|
2020-04-01 03:11:51 +02:00
|
|
|
homepage = "https://opencv.org/";
|
2018-07-24 10:50:32 +02:00
|
|
|
license = with licenses; if enableUnfree then unfree else bsd3;
|
2018-07-28 19:25:14 +02:00
|
|
|
maintainers = with maintainers; [mdaiter basvandijk];
|
2018-07-24 10:50:32 +02:00
|
|
|
platforms = with platforms; linux ++ darwin;
|
2015-09-01 14:53:32 +02:00
|
|
|
};
|
|
|
|
}
|