1 # Maintainer: Antonio Rojas <arojas@archlinux.org>
2 # Contributor: Ray Rashif <schiv@archlinux.org>
3 # Contributor: Tobias Powalowski <tpowa@archlinux.org>
6 pkgname=(opencv opencv-samples python-opencv opencv-cuda)
9 pkgdesc='Open Source Computer Vision Library'
12 url='https://opencv.org/'
13 depends=(tbb openexr gst-plugins-base libdc1394 cblas lapack libgphoto2 openjpeg2 ffmpeg protobuf)
14 makedepends=(cmake python-numpy python-setuptools mesa eigen hdf5 lapacke qt5-base vtk glew ant java-environment
15 pugixml openmpi cudnn fmt nlohmann-json)
16 optdepends=('opencv-samples: samples'
17 'vtk: for the viz module'
18 'glew: for the viz module'
19 'qt5-base: for the HighGUI module'
20 'hdf5: for the HDF5 module'
21 'opencl-icd-loader: For coding with OpenCL'
22 'java-runtime: Java interface')
23 source=(https://github.com/opencv/opencv/archive/$pkgver/$pkgname-$pkgver.tar.gz
24 https://github.com/opencv/opencv_contrib/archive/$pkgver/opencv_contrib-$pkgver.tar.gz
26 sha256sums=('8df0079cdbe179748a18d44731af62a245a45ebf5085223dc03133954c662973'
27 '42df840cf9055e59d0e22c249cfb19f04743e1bdad113d31b1573d3934d62584'
28 'f35a2d4ea0d6212c7798659e59eda2cb0b5bc858360f7ce9c696c77d3029668e')
31 patch -d $pkgname-$pkgver -p1 < vtk9.patch # Don't require all vtk optdepends
35 export JAVA_HOME="/usr/lib/jvm/default"
36 # cmake's FindLAPACK doesn't add cblas to LAPACK_LIBRARIES, so we need to specify them manually
37 _opts="-DWITH_OPENCL=ON \
43 -DBUILD_PERF_TESTS=OFF \
45 -DBUILD_PROTOBUF=OFF \
46 -DPROTOBUF_UPDATE_FILES=ON \
47 -DINSTALL_C_EXAMPLES=ON \
48 -DINSTALL_PYTHON_EXAMPLES=ON \
49 -DCMAKE_INSTALL_PREFIX=/usr \
50 -DCPU_BASELINE_DISABLE=SSE3 \
51 -DCPU_BASELINE_REQUIRE=SSE2 \
52 -DOPENCV_EXTRA_MODULES_PATH=$srcdir/opencv_contrib-$pkgver/modules \
53 -DOPENCV_SKIP_PYTHON_LOADER=ON \
54 -DLAPACK_LIBRARIES=/usr/lib/liblapack.so;/usr/lib/libblas.so;/usr/lib/libcblas.so \
55 -DLAPACK_CBLAS_H=/usr/include/cblas.h \
56 -DLAPACK_LAPACKE_H=/usr/include/lapacke.h \
57 -DOPENCV_GENERATE_PKGCONFIG=ON \
58 -DOPENCV_ENABLE_NONFREE=ON \
59 -DOPENCV_JNI_INSTALL_PATH=lib \
60 -DOPENCV_GENERATE_SETUPVARS=OFF \
61 -DEIGEN_INCLUDE_PATH=/usr/include/eigen3"
63 cmake -B build -S $pkgname-$pkgver $_opts \
64 -DBUILD_WITH_DEBUG_INFO=ON
67 CFLAGS="${CFLAGS} -fno-lto" CXXFLAGS="${CXXFLAGS} -fno-lto" LDFLAGS="${LDFLAGS} -fno-lto" \
68 cmake -B build-cuda -S $pkgname-$pkgver $_opts \
69 -DBUILD_WITH_DEBUG_INFO=OFF \
72 -DCUDA_ARCH_BIN='52-real;53-real;60-real;61-real;62-real;70-real;72-real;75-real;80-real;86-real;87-real;89-real;90-real;90-virtual' \
73 -DCUDA_ARCH_PTX='90-virtual'
74 cmake --build build-cuda
78 DESTDIR="$pkgdir" cmake --install build
80 # install license file
81 install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
83 # separate samples package
84 mv "$pkgdir"/usr/share/opencv4/samples "$srcdir"
86 # Add java symlinks expected by some binary blobs
87 ln -sr "$pkgdir"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar
88 ln -sr "$pkgdir"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so
90 # Split Python bindings
91 rm -r "$pkgdir"/usr/lib/python3*
94 package_opencv-samples() {
99 mkdir -p "$pkgdir"/usr/share/opencv4
100 mv samples "$pkgdir"/usr/share/opencv4
102 # install license file
103 install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
106 package_python-opencv() {
107 pkgdesc='Python bindings for OpenCV'
108 depends=(python-numpy opencv vtk glew qt5-base hdf5 jsoncpp openmpi pugixml fmt)
111 DESTDIR="$pkgdir" cmake --install build/modules/python3
113 # install license file
114 install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
117 package_opencv-cuda() {
118 pkgdesc+=' (with CUDA support)'
121 provides=(opencv=$pkgver)
124 DESTDIR="$pkgdir" cmake --install build-cuda
126 # install license file
127 install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
130 rm -r "$pkgdir"/usr/share/opencv4/samples
132 # Add java symlinks expected by some binary blobs
133 ln -sr "$pkgdir"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar
134 ln -sr "$pkgdir"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so
136 # Split Python bindings
137 rm -r "$pkgdir"/usr/lib/python3*