2017-01-24 09:25:10 +01:00
|
|
|
{ lib, stdenv, fetchurl, fetchpatch, fetchFromGitHub, cmake, pkgconfig, unzip, zlib
|
|
|
|
|
|
|
|
, enableJPEG ? true, libjpeg
|
|
|
|
, enablePNG ? true, libpng
|
|
|
|
, enableTIFF ? true, libtiff
|
|
|
|
, enableWebP ? true, libwebp
|
2017-04-25 21:44:28 +02:00
|
|
|
, enableEXR ? (!stdenv.isDarwin), openexr, ilmbase
|
2017-01-24 09:25:10 +01:00
|
|
|
, enableJPEG2K ? true, jasper
|
|
|
|
|
|
|
|
, enableIpp ? false
|
2017-09-05 17:11:41 +02:00
|
|
|
, enableContrib ? false, protobuf
|
2017-01-24 09:25:10 +01:00
|
|
|
, enablePython ? false, pythonPackages
|
|
|
|
, enableGtk2 ? false, gtk2
|
|
|
|
, enableGtk3 ? false, gtk3
|
|
|
|
, enableFfmpeg ? false, ffmpeg
|
2016-06-07 16:09:22 +02:00
|
|
|
, enableGStreamer ? false, gst_all_1
|
2017-01-24 09:25:10 +01:00
|
|
|
, enableEigen ? false, eigen
|
2017-06-20 14:59:30 +02:00
|
|
|
, enableOpenblas ? false, openblas
|
2017-01-24 09:25:10 +01:00
|
|
|
, enableCuda ? false, cudatoolkit, gcc5
|
2017-06-28 16:19:01 +02:00
|
|
|
, enableTesseract ? false, tesseract, leptonica
|
2017-04-25 21:44:28 +02:00
|
|
|
, AVFoundation, Cocoa, QTKit
|
2016-06-07 16:09:22 +02:00
|
|
|
}:
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2015-09-11 14:48:33 +02:00
|
|
|
let
|
2017-01-24 09:25:10 +01:00
|
|
|
version = "3.2.0";
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv";
|
|
|
|
rev = version;
|
|
|
|
sha256 = "0f59g0dvhp5xg1xa3r4lp351a7x0k03i77ylgcf69ns3y47qd16p";
|
|
|
|
};
|
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;
|
|
|
|
sha256 = "1lynpbxz1jay3ya5y45zac5v8c6ifgk4ssn8d1chfdk3spi691jj";
|
2015-09-11 14:48:33 +02:00
|
|
|
};
|
|
|
|
|
2017-08-07 00:05:18 +02:00
|
|
|
# This fixes the build on macOS.
|
2017-06-17 19:57:39 +02:00
|
|
|
# See: https://github.com/opencv/opencv_contrib/pull/926
|
|
|
|
contribOSXFix = fetchpatch {
|
|
|
|
url = "https://github.com/opencv/opencv_contrib/commit/abf44fcccfe2f281b7442dac243e37b7f436d961.patch";
|
|
|
|
sha256 = "11dsq8dwh1k6f7zglbc26xwsjw184ggf2531mhf7v77kd72k19fm";
|
|
|
|
};
|
|
|
|
|
2017-06-28 16:19:01 +02:00
|
|
|
# Contrib must be built in order to enable Tesseract support:
|
|
|
|
buildContrib = enableContrib || enableTesseract;
|
|
|
|
|
2017-01-24 09:25:10 +01:00
|
|
|
vggFiles = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d";
|
|
|
|
sha256 = "0r9fam8dplyqqsd3qgpnnfgf9l7lj44di19rxwbm8mxiw0rlcdvy";
|
|
|
|
};
|
|
|
|
|
|
|
|
bootdescFiles = fetchFromGitHub {
|
|
|
|
owner = "opencv";
|
|
|
|
repo = "opencv_3rdparty";
|
|
|
|
rev = "34e4206aef44d50e6bbcd0ab06354b52e7466d26";
|
|
|
|
sha256 = "13yig1xhvgghvxspxmdidss5lqiikpjr0ddm83jsi0k85j92sn62";
|
|
|
|
};
|
2016-06-07 16:09:22 +02:00
|
|
|
|
2017-01-24 09:25:10 +01:00
|
|
|
opencvFlag = name: enabled: "-DWITH_${name}=${if enabled then "ON" else "OFF"}";
|
2015-09-11 14:48:33 +02:00
|
|
|
in
|
2015-09-01 14:53:32 +02:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2016-06-07 16:09:22 +02:00
|
|
|
name = "opencv-${version}";
|
2017-01-24 09:25:10 +01:00
|
|
|
inherit version src;
|
|
|
|
|
|
|
|
postUnpack =
|
2017-06-28 16:19:01 +02:00
|
|
|
(lib.optionalString buildContrib ''
|
2017-01-24 09:25:10 +01:00
|
|
|
cp --no-preserve=mode -r "${contribSrc}/modules" "$NIX_BUILD_TOP/opencv_contrib"
|
|
|
|
|
2017-08-07 00:05:18 +02:00
|
|
|
# This fixes the build on macOS.
|
2017-06-17 19:57:39 +02:00
|
|
|
patch -d "$NIX_BUILD_TOP/opencv_contrib" -p2 < "${contribOSXFix}"
|
|
|
|
|
2017-01-24 09:25:10 +01:00
|
|
|
for name in vgg_generated_48.i \
|
|
|
|
vgg_generated_64.i \
|
|
|
|
vgg_generated_80.i \
|
|
|
|
vgg_generated_120.i; do
|
|
|
|
ln -s "${vggFiles}/$name" "$NIX_BUILD_TOP/opencv_contrib/xfeatures2d/src/$name"
|
|
|
|
done
|
|
|
|
|
|
|
|
for name in boostdesc_bgm.i \
|
|
|
|
boostdesc_bgm_bi.i \
|
|
|
|
boostdesc_bgm_hd.i \
|
|
|
|
boostdesc_binboost_064.i \
|
|
|
|
boostdesc_binboost_128.i \
|
|
|
|
boostdesc_binboost_256.i \
|
|
|
|
boostdesc_lbgm.i; do
|
|
|
|
ln -s "${bootdescFiles}/$name" "$NIX_BUILD_TOP/opencv_contrib/xfeatures2d/src/$name"
|
|
|
|
done
|
|
|
|
'');
|
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 =
|
2017-01-24 09:25:10 +01:00
|
|
|
(let version = "20151201";
|
|
|
|
md5 = "808b791a6eac9ed78d32a7666804320e";
|
|
|
|
sha256 = "1nph0w0pdcxwhdb5lxkb8whpwd9ylvwl97hn0k425amg80z86cs3";
|
|
|
|
rev = "81a676001ca8075ada498583e4166079e5744668";
|
|
|
|
platform = if stdenv.system == "x86_64-linux" || stdenv.system == "i686-linux" then "linux"
|
|
|
|
else throw "ICV is not available for this platform (or not yet supported by this package)";
|
|
|
|
name = "ippicv_${platform}_${version}.tgz";
|
|
|
|
ippicv = fetchurl {
|
|
|
|
url = "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${rev}/ippicv/${name}";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
dir = "3rdparty/ippicv/downloads/${platform}-${md5}";
|
|
|
|
in lib.optionalString enableIpp ''
|
|
|
|
mkdir -p "${dir}"
|
|
|
|
ln -s "${ippicv}" "${dir}/${name}"
|
|
|
|
''
|
|
|
|
) +
|
2017-06-28 16:19:01 +02:00
|
|
|
(lib.optionalString buildContrib ''
|
2017-01-24 09:25:10 +01:00
|
|
|
cmakeFlagsArray+=("-DOPENCV_EXTRA_MODULES_PATH=$NIX_BUILD_TOP/opencv_contrib")
|
|
|
|
'');
|
2015-09-11 14:32:42 +02:00
|
|
|
|
2015-09-01 14:53:32 +02:00
|
|
|
buildInputs =
|
2016-06-07 16:09:22 +02:00
|
|
|
[ zlib ]
|
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
|
|
|
|
++ lib.optional enableJPEG libjpeg
|
|
|
|
++ lib.optional enablePNG libpng
|
|
|
|
++ lib.optional enableTIFF libtiff
|
|
|
|
++ lib.optional enableWebP libwebp
|
|
|
|
++ lib.optionals enableEXR [ openexr ilmbase ]
|
|
|
|
++ lib.optional enableJPEG2K jasper
|
|
|
|
++ lib.optional enableFfmpeg ffmpeg
|
|
|
|
++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base ])
|
|
|
|
++ 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 ]
|
2017-01-24 09:25:10 +01:00
|
|
|
++ lib.optionals enableCuda [ cudatoolkit gcc5 ]
|
2017-09-05 17:11:41 +02:00
|
|
|
++ lib.optional buildContrib protobuf
|
2017-04-25 21:44:28 +02:00
|
|
|
++ lib.optionals stdenv.isDarwin [ AVFoundation Cocoa QTKit ];
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2016-06-07 20:26:33 +02:00
|
|
|
propagatedBuildInputs = lib.optional enablePython pythonPackages.numpy;
|
|
|
|
|
2016-06-07 16:09:22 +02:00
|
|
|
nativeBuildInputs = [ cmake pkgconfig unzip ];
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2016-09-01 18:11:21 +02:00
|
|
|
NIX_CFLAGS_COMPILE = lib.optional enableEXR "-I${ilmbase.dev}/include/OpenEXR";
|
2015-09-01 14:53:32 +02:00
|
|
|
|
2015-09-11 14:48:33 +02:00
|
|
|
cmakeFlags = [
|
2017-06-20 14:59:30 +02:00
|
|
|
"-DWITH_IPP=${if enableIpp then "ON" else "OFF"} -DWITH_OPENMP=ON"
|
2016-06-07 16:09:22 +02:00
|
|
|
(opencvFlag "TIFF" enableTIFF)
|
|
|
|
(opencvFlag "JASPER" enableJPEG2K)
|
|
|
|
(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)
|
2017-01-24 09:25:10 +01:00
|
|
|
] ++ lib.optionals enableCuda [ "-DCUDA_FAST_MATH=ON" ]
|
2017-06-28 16:19:01 +02:00
|
|
|
++ lib.optional buildContrib "-DBUILD_PROTOBUF=off"
|
2017-04-25 21:44:28 +02:00
|
|
|
++ lib.optionals stdenv.isDarwin ["-DWITH_OPENCL=OFF" "-DWITH_LAPACK=OFF"];
|
2015-09-01 22:20:38 +02:00
|
|
|
|
2015-09-01 14:53:32 +02:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
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 = []; };
|
|
|
|
|
2015-09-01 14:53:32 +02:00
|
|
|
meta = {
|
|
|
|
description = "Open Computer Vision Library with more than 500 algorithms";
|
|
|
|
homepage = http://opencv.org/;
|
|
|
|
license = stdenv.lib.licenses.bsd3;
|
2017-05-10 11:10:10 +02:00
|
|
|
maintainers = with stdenv.lib.maintainers; [viric mdaiter];
|
2017-04-25 21:44:28 +02:00
|
|
|
platforms = with stdenv.lib.platforms; linux ++ darwin;
|
2015-09-01 14:53:32 +02:00
|
|
|
};
|
|
|
|
}
|