# Maintainer (Arch): Ray Rashif # Contributor (Arch): Tobias Powalowski # Contributor (Hyperbola): André Silva # Contributor (Hyperbola): Márcio Silva # Maintainer: Omar Vega Ramos pkgbase=opencv pkgname=(opencv opencv-samples python-opencv) pkgver=4.5.3 pkgrel=1 pkgrel+=.edgar pkgdesc="Free Computer Vision Library, without non-free algorithms, Milky icons and lena images" arch=(x86_64) license=(BSD3) url="https://opencv.org/" depends=(tbb openexr gst-plugins-base libdc1394 cblas lapack libgphoto2 openjpeg2 ffmpeg) depends+=(hicolor-icon-theme) makedepends=(cmake python-numpy python-setuptools mesa eigen hdf5 lapacke qt5-base vtk glew ant java-environment libjpeg-turbo libpng jasper openjpeg libtiff libwebp zlib) optdepends=('opencv-samples: samples' 'gtk3: for the HighGUI module and the Python bindings' 'vtk: for the viz module' 'glew: for the viz module' 'qt5-base: for the HighGUI module and the Python bindings' 'hdf5: for the HDF5 module and the Python bindings' 'opencl-icd-loader: For coding with OpenCL' 'python-numpy: Python bindings' 'java-runtime: Java interface' 'libpng' 'libjpeg-turbo' 'jasper' 'openjpeg' 'libtiff' 'libwebp' 'zlib') source=(https://github.com/opencv/opencv/archive/"${pkgver}"/opencv-"${pkgver}".zip https://github.com/opencv/opencv_contrib/archive/"${pkgver}"/opencv_contrib-"${pkgver}".tar.gz # DownloadADE.cmake ade_v0.1.1f.zip::https://github.com/opencv/ade/archive/v0.1.1f.zip tbb_v2020.2.tar.gz::https://github.com/01org/tbb/archive/v2020.2.tar.gz opencv-lapack-3.10.patch remove_ippcv.patch libre.patch face_landmark_model.patch wechat_qrcode.patch) sha512sums=('31679bc6445f992c8f683b3c9c9b9ea0ae0cf69d21dba848d319a11d765532f8c8836bc8e073b1b6c353742edbf452f87273f6774b3af28db90bf7cc1eae09ca' '5b48e2aedcf8c64fcfe80fad243c455c1bb9bfd10741c5ba03679ef26b28f61767fec632a9a9828a87a90542488354ebbbe8c65845bf2ae55b15a721c147a30a' 'f2994d5e92a2ae05cee6e153943afe151ce734ced6e06dcdb02dee9fed9336a7f1ea69661d9e033f1412fbb5e2a44a6e641662c85be5ba0604d0446abeabe836' 'b9a5d0e814ebd2e69690585bcfb5a545c06f030e193154bef161ac59066044109f8a0305a9ba535c447739da3380c351067db19c38de4bf96ec742b044f39885' 'a13dfa91ee423d2ee5f6344ccb8394f96195538b3d668f97c5fdc3ccd84d5ecd54f80bc6fa45685f319ab0d0c9bb5ad533c0f2d1a20d21f3a5afdd1c0239bfa1' 'b712a563a1ef1a9e9a839f6d86fbf71e38e2a8685811fe0de1028cc90497d3d9b423de7445a1733be370972c0f21b0c24db3af3a91092eba94feffaf71bf0de8' 'd84d91eeb5f09cdd3a4e759651dc52d4bf5e15726628a58e9acd3921dddba2fd15acb066b94395f2ed5dca56129576c38f0ac643c0dfff3bd8c7c0d1d9c288b8' 'e55ae4f2471c0e2208b1ac8425061324cf03ec36b4279f164c090efb6f28efda3c8d3e2a6fb36663b24475bf17dd4f42be6e310d9ad40815be76adbb43974b07' 'ec0bbeefcf9d9175a532beee7b2a5386528b283ba3e298792cd168ebd6618efd554c4090b9e4be0fda7e32211da53b566f1b3fe62af9da1cff63c0a2ff69aa64') noextract=(ade_v0.1.1f.zip tbb_v2020.2.tar.gz) # source=("https://repo.parabola.nu/other/"${pkgname}"-libre/"${pkgname}"-libre-"${pkgver}".zip" # opencv-includedir.patch) # sha256sums=('92de32fbd5c2239cf1b7bd52c07aab8bec76fab1dd51fef5a887f401f75ee2f6' # 'a96e35c9592e655b21a62cfe04e864a10e21535ad900e5de67356b9e9f40ca10') # From UPC: Building And Using Static And Shared "C" # Libraries.html # #+begin_QUOTE # we need that all jump calls ("goto", in assembly speak) # and subroutine calls will use relative addresses, and not # absolute addresses. Thus, we need to use ... ~-fPIC~ or # ~-fpic~ # #+end_QUOTE # # From makepkg.conf # -march (or -mcpu) builds exclusively for an architecture # -mtune optimizes for an architecture, but builds for # whole processor family # # -O3 optimises # # -D-FORTIFY-SOURCE=2 # | https://stackoverflow.com/a/16604146 # |- man 7 feature_test_macros # checks to be performed to detect some buffer overflow # errors when employing various string and memory # manipulation functions ... some conforming programs # might fail # # -fcf-protection # | Info pages for gcc (gnu compiler collection) # intended to protect against such threats as # Return-oriented Programming (ROP), and similarly # call/jmp-oriented programming (COP/JOP) # # -pipe # | Info pages for gcc (controlling the kind of output) # Use pipes rather than temporary files for communication # between the various stages of compilation # # -fno-plt # | Info pages for gcc (code generation conventions) # leads to more efficient code by eliminating PLT stubs and # exposing GOT loads to optimizations # # -fopenmp # | Info pages for gcc (controlling c dialect) # Enable handling of OpenMP directives # I used these for PETSc # safe_flags="-D-FORTIFY-SOURCE=2 -fcf-protection -fno-plt -fstack-clash-protection -Wformat -Werror=format-security" safe_flags="-Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS" safe_flags+=" -fcf-protection -fno-plt" safe_flags+=" -fstack-clash-protection -Wformat" safe_flags+=" -Werror=format-security" generic_flags="-pipe -fno-plt -fPIC -fopenmp" generic_flags+=" -march=native" generic_flags+=" -mtune=native ${safe_flags}" opt_flags="${generic_flags} -O3" generic_flags="${generic_flags} -O2" export COPTFLAGS="${opt_flags}" export CXXOPTFLAGS="$COPTFLAGS" export FOPTFLAGS="$COPTFLAGS" export CPPFLAGS="$generic_flags" export CXXFLAGS="$CPPFLAGS" export CFLAGS="$generic_flags" export FFLAGS="$generic_flags" export FCFLAGS="$generic_flags" export F90FLAGS="$generic_flags" export F77FLAGS="$generic_flags" export CC=mpicc CXX=mpicxx FC=mpifort # # Find the location of the header files of PETSc # # Get the PETSc directory # petsc_incl=$(pkgconf --cflags-only-I PETSc) # export PETSC_DIR=${petsc_incl##-I} [ -f "/etc/profile.d/petsc.sh" ] && source "/etc/profile.d/petsc.sh" export LANG="en_IE.UTF-8" # mksource() { prepare() { # sed "s_/${pkgbase}-pkgver/_/opencv-${pkgver}/_" curl-wget.patch > curl-wget.diff # patch -p1 -i curl-wget.diff # use torsocks to download patch -d "${pkgbase}"-"${pkgver}" -p1 < opencv-lapack-3.10.patch # Fix build with LAPACK 3.10 # Disabled with options in configuration (just in case) patch -d "${pkgname}"-"${pkgver}" -p1 < remove_ippcv.patch # sed -i 's/\(ocv_option(BUILD_PROTOBUF.* \)ON/\1OFF/' "${srcdir}"/""${pkgbase}""-""${pkgver}""/cmake/OpenCVFindProtobuf.cmake sed -i 's/\(BUILD_SHARED_LIBS=\)OFF/\1ON/' "${srcdir}"/""${pkgbase}""-""${pkgver}""/cmake/OpenCVFindIPP.cmake parallel -q sed -i 's_libpng/png.h_libpng16/png.h_' {} ::: $(find "${srcdir}"/""${pkgbase}""-""${pkgver}"" -type f -exec grep -l libpng/png.h \{\} +) cd "${srcdir}/opencv_contrib-${pkgver}" # (Should be avoided with non-free option in configuration) # remove non-free algorithms rm -r modules/xfeatures2d # * remove blobls from modules # rm -r modules/{aruco,cnn_3dobj,dnns_easily_fooled,wechat_qrcode} # (check CMakeDownloadLog.txt) # parallel 'file {} | grep " data" | grep -v "\(image\|text\|JSON\|gzip\)"' ::: $(find modules -type f) # modules/aruco/misc/pattern_generator/README.md: # python MarkerPrinter.py --generate arucoDictBytesList.npz # modules/cnn_3dobj/README.md: # .caffemodel ... you could just use them instead of training with Caffe # ####Image generation for different poses ... horse.ply # modules/dnns_easily_fooled/README.md # modules/dnns_easily_fooled/model/lenet/lenet_iter_10000 rm -fr \ modules/aruco/misc/pattern_generator/arucoDictBytesList.npz \ modules/cnn_3dobj/testdata/cv/3d_triplet_iter_30000.caffemodel \ modules/cnn_3dobj/samples/data/3Dmodel/horse.ply \ modules/dnns_easily_fooled/model/lenet/lenet_iter_10000 # Disable downloaded files (already in sources; look for # ocv_download) patch -p1 -i "${srcdir}"/face_landmark_model.patch patch -p1 -i "${srcdir}"/wechat_qrcode.patch cd "${srcdir}/${pkgbase}-${pkgver}" # remove nonfree Milky icons rm -r modules/highgui/src/files_Qt/Milky patch -p1 -i ../libre.patch # remove nonfree lena.png and lena.jpg images parallel rm -fr {} ::: $(find . -iname '*lena*') cd "${srcdir}" _build_dir="${srcdir}"/"${pkgbase}"-"${pkgver}"/ _ade_dir="${_build_dir}"/.cache/ade [ ! -d "${_ade_dir}" ] && mkdir -p "${_ade_dir}" ln -s "${srcdir}"/ade_v0.1.1f.zip "${_ade_dir}"/b624b995ec9c439cbc2e9e6ee940d3a2-v0.1.1f.zip _tbb_dir="${_build_dir}"/.cache/tbb [ ! -d "${_tbb_dir}" ] && mkdir -p "${_tbb_dir}" ln -s "${srcdir}"/tbb_v2020.2.tar.gz "${_tbb_dir}"/5af6f6c2a24c2043e62e47205e273b1f-v2020.2.tar.gz } # # prepare() { # patch -d "${pkgname}"-"${pkgver}" -p1 < opencv-lapack-3.10.patch # Fix build with LAPACK 3.10 # } build() { export JAVA_HOME="/usr/lib/jvm/default" # SSE only available from Pentium 3 onwards (i686 is way older) # SSE only available x86 hardware and ARM uses NEON case "$CARCH" in i686) extra='-DCPU_BASELINE_DISABLE=SSE,SSE2' ;; x86_64) extra='-DCPU_BASELINE_DISABLE=SSE3 -DCPU_BASELINE_REQUIRE=SSE2' ;; *) extra='' ;; esac # cmake's FindLAPACK doesn't add cblas to LAPACK_LIBRARIES, so we need to specify them manually _pythonpath=`python -c "from sysconfig import get_path; print(get_path('platlib'))"` CONFOPTS=( -DBUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/usr -DOPENCV_JNI_INSTALL_PATH=lib -DENABLE_PROFILING=ON -DOPENCV_ENABLE_MEMORY_SANITIZERS=ON -DENABLE_BUILD_HARDENING=ON -DENABLE_LTO=ON -DBUILD_SHARED=ON -DOPENCV_ENABLE_NONFREE=OFF -DOPENCV_FORCE_3RDPARTY_BUILD=ON -DWITH_IPP=OFF -DBUILD_EXAMPLES=ON -DINSTALL_BIN_EXAMPLES=ON -DINSTALL_TESTS=ON -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_WITH_DEBUG_INFO=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DOPENCV_SKIP_PYTHON_LOADER=ON -DOPENCV_PYTHON3_INSTALL_PATH="${_pythonpath}" -DOpenGL_GL_PREFERENCE=GLVND -DWITH_OPENCL=ON -DWITH_OPENGL=ON -DWITH_QT=ON # Should be in the system (or modify provides) -DWITH_TBB=ON -DBUILD_TBB=OFF -DBUILD_PNG=OFF -DBUILD_JASPER=OFF -DBUILD_JPEG=OFF -DBUILD_OPENJPEG=OFF -DBUILD_OPENEXR=OFF -DBUILD_TIFF=OFF -DBUILD_WEBP=OFF -DBUILD_ZLIB=OFF # BSD,GPL -DBUILD_ITT=ON # Build fails otherwise (OpenCV source is not up-to-date) -DBUILD_PROTOBUF=ON $extra -DOPENCV_EXTRA_MODULES_PATH="${srcdir}/opencv_contrib-${pkgver}/modules" -DEIGEN_INCLUDE_PATH="/usr/include/eigen3" -DLAPACK_LIBRARIES="/usr/lib/liblapack.so;/usr/lib/libblas.so;/usr/lib/libcblas.so" -DLAPACK_CBLAS_H="/usr/include/cblas.h" -DLAPACK_LAPACKE_H="/usr/include/lapacke.h" -DCMAKE_EXE_LINKER_FLAGS="-lcblas -lpng" -DCMAKE_MODULE_LINKER_FLAGS="-lcblas -lpng" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_COMPILER_AR=ar -DCMAKE_CXX_COMPILER_RANLIB=ranlib -DCMAKE_C_COMPILER="${CC}" -DCMAKE_C_COMPILER_AR=ar -DCMAKE_C_COMPILER_RANLIB=ranlib -DCMAKE_CXX_FLAGS="$CPPFLAGS" -DCMAKE_CC_FLAGS="$CFLAGS" -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_GENERATE_SETUPVARS=OFF # --log-level=ERROR --log-level=VERBOSE --log-context ) cmake -B build -S "${pkgname}"-"${pkgver}" "${CONFOPTS[@]}" cmake --build build } package_opencv() { DESTDIR="${pkgdir}" cmake --install build # install license file install -Dm644 "${pkgbase}"-"${pkgver}"/LICENSE -t "${pkgdir}"/usr/share/licenses/"${pkgname}" # separate samples package [ -d "${srcdir}"/samples ] && rm -fr "$srcdir"/samples [ -d "${pkgdir}"/usr/share/opencv4/samples ] && mv "${pkgdir}"/usr/share/opencv4/samples "${srcdir}" # Move binaries, if installed [[ ! -d "${pkgdir}"/usr/bin/opencv ]] && mkdir -p "${pkgdir}"/usr/bin/opencv cmd=' && ' cmd='${cmd} ' cmd='${cmd} || ' for i in $(find "${pkgdir}"/usr/bin/* -type d); do _bin_name="$(basename "${i}")" if [ -d "${srcdir}"/samples/${_bin_name} ]; then mv "${i}"/* "${srcdir}"/samples/${_bin_name}; rm -fr "${i}" else mv "${i}" "${srcdir}"/samples/; fi; done; # Add java symlinks expected by some binary blobs ln -sr "${pkgdir}"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar ln -sr "${pkgdir}"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so # Split Python bindings rm -r "${pkgdir}"/usr/lib/python{3,2}* } package_opencv-samples() { pkgdesc+=" (samples)" depends=("opencv="${pkgver}"") unset optdepends mkdir -p "${pkgdir}"/usr/share/opencv4 cp -r "${srcdir}"/samples "${pkgdir}"/usr/share/opencv4/ # fix permissions chmod 755 "${pkgdir}"/usr/share/opencv4/samples/* # install license file install -Dm644 "${pkgbase}"-"${pkgver}"/LICENSE -t "${pkgdir}"/usr/share/licenses/"${pkgname}" } package_python-opencv() { pkgdesc="Python bindings for OpenCV" depends=(python-numpy opencv vtk glew qt5-base hdf5) unset optdepends DESTDIR="${pkgdir}" cmake --install build/modules/python3 # install license file install -Dm644 "${pkgbase}"-"${pkgver}"/LICENSE -t "${pkgdir}"/usr/share/licenses/"${pkgname}" }