diff options
| author | Cayetano Santos <csantosb@inventati.org> | 2026-02-01 08:55:04 +0100 |
|---|---|---|
| committer | Andreas Enge <andreas@enge.fr> | 2026-02-20 15:17:33 +0100 |
| commit | c6d3a9334d9277aaa8b89a7b22f3cd28db81682b (patch) | |
| tree | e788edd9014c4e6bccba1f7f16d92b8fa3f7e0a5 | |
| parent | 1b17e46a9b7c225a75b623890057d6f5f8ca3e5c (diff) | |
gnu: opencv: Modernize.
* gnu/packages/image-processing.scm (opencv)[sources]: Improve snippet.
[arguments]: Use G-Expressions.
Change-Id: Ib422f378de681a93c869e492fbd6c49a2085bad6
Signed-off-by: Andreas Enge <andreas@enge.fr>
| -rw-r--r-- | gnu/packages/image-processing.scm | 337 |
1 files changed, 165 insertions, 172 deletions
diff --git a/gnu/packages/image-processing.scm b/gnu/packages/image-processing.scm index 5938f3961f9..ac1e314b383 100644 --- a/gnu/packages/image-processing.scm +++ b/gnu/packages/image-processing.scm | |||
| @@ -597,186 +597,179 @@ different data arrays similar to those available in the numdiff software.") | |||
| 597 | (url "https://github.com/opencv/opencv") | 597 | (url "https://github.com/opencv/opencv") |
| 598 | (commit version))) | 598 | (commit version))) |
| 599 | (file-name (git-file-name name version)) | 599 | (file-name (git-file-name name version)) |
| 600 | (modules '((guix build utils))) | ||
| 601 | (snippet | 600 | (snippet |
| 602 | '(begin | 601 | #~(begin |
| 603 | ;; Remove external libraries. Almost all of them are | 602 | (use-modules (guix build utils) |
| 604 | ;; available in Guix. | 603 | (ice-9 ftw) |
| 605 | (with-directory-excursion "3rdparty" | 604 | (srfi srfi-26)) |
| 606 | (for-each delete-file-recursively | 605 | ;; Delete any bundled .jar files. |
| 607 | '("cpufeatures" | 606 | (for-each delete-file (find-files "." "\\.jar$")) |
| 608 | "flatbuffers" | 607 | (define (delete-all-but directory . preserve) |
| 609 | "ffmpeg" | 608 | (with-directory-excursion directory |
| 610 | "include" | 609 | (let* ((pred (negate (cut member <> |
| 611 | "ippicv" | 610 | (cons* "." ".." preserve)))) |
| 612 | "ittnotify" | 611 | (items (scandir "." pred))) |
| 613 | "libjasper" | 612 | (for-each (cut delete-file-recursively <>) items)))) |
| 614 | "libjpeg" | 613 | (delete-all-but "3rdparty" |
| 615 | "libjpeg-turbo" | 614 | "fastcv" ;TODO: Unbundle these |
| 616 | "libpng" | 615 | "libspng" |
| 617 | "libtiff" | 616 | "libtim-vx" |
| 618 | "libwebp" | 617 | "orbbecsdk" |
| 619 | "openexr" | 618 | "quirc" |
| 620 | "openjpeg" | 619 | "zlib-ng"))) |
| 621 | "protobuf" | ||
| 622 | ;;"quirc" | ||
| 623 | "tbb" | ||
| 624 | "zlib"))) | ||
| 625 | |||
| 626 | ;; Delete any bundled .jar files. | ||
| 627 | (for-each delete-file (find-files "." "\\.jar$")))) | ||
| 628 | (sha256 | 620 | (sha256 |
| 629 | (base32 | 621 | (base32 |
| 630 | "1n5qif1ispmdby1cmwf9f8isdx07phyhb19jsmgrw5bk3k23dcyy")))) | 622 | "1n5qif1ispmdby1cmwf9f8isdx07phyhb19jsmgrw5bk3k23dcyy")))) |
| 631 | (build-system cmake-build-system) | 623 | (build-system cmake-build-system) |
| 632 | (arguments | 624 | (arguments |
| 633 | `(#:parallel-tests? #f | 625 | (list |
| 634 | #:configure-flags | 626 | #:parallel-tests? #f |
| 635 | (list "-DWITH_ADE=OFF" ;we don't have a package for ade yet | 627 | #:configure-flags |
| 636 | "-DWITH_IPP=OFF" | 628 | #~(list "-DWITH_ADE=OFF" ;we don't have a package for ade yet |
| 637 | "-DWITH_ITT=OFF" | 629 | "-DWITH_IPP=OFF" |
| 638 | "-DWITH_CAROTENE=OFF" ; only visible on arm/aarch64 | 630 | "-DWITH_ITT=OFF" |
| 639 | "-DENABLE_PRECOMPILED_HEADERS=OFF" | 631 | "-DWITH_CAROTENE=OFF" ; only visible on arm/aarch64 |
| 640 | "-DOPENCV_GENERATE_PKGCONFIG=ON" | 632 | "-DENABLE_PRECOMPILED_HEADERS=OFF" |
| 641 | 633 | "-DOPENCV_GENERATE_PKGCONFIG=ON" | |
| 642 | ;; CPU-Features: | 634 | |
| 643 | ;; See cmake/OpenCVCompilerOptimizations.cmake | 635 | ;; CPU-Features: |
| 644 | ;; (CPU_ALL_OPTIMIZATIONS) for a list of all optimizations | 636 | ;; See cmake/OpenCVCompilerOptimizations.cmake |
| 645 | ;; BASELINE is the minimum optimization all CPUs must support | 637 | ;; (CPU_ALL_OPTIMIZATIONS) for a list of all optimizations |
| 646 | ;; | 638 | ;; BASELINE is the minimum optimization all CPUs must support |
| 647 | ;; DISPATCH is the list of optional dispatches. | 639 | ;; |
| 648 | "-DCPU_BASELINE=SSE2" | 640 | ;; DISPATCH is the list of optional dispatches. |
| 649 | 641 | "-DCPU_BASELINE=SSE2" | |
| 650 | ;; Build Python bindings. | 642 | |
| 651 | "-DBUILD_opencv_python3=ON" | 643 | ;; Build Python bindings. |
| 652 | 644 | "-DBUILD_opencv_python3=ON" | |
| 653 | ,@(match (%current-system) | 645 | |
| 654 | ("x86_64-linux" | 646 | #$@(match (%current-system) |
| 655 | '("-DCPU_DISPATCH=NEON;VFPV3;FP16;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX" | 647 | ("x86_64-linux" |
| 656 | "-DCPU_DISPATCH_REQUIRE=SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2")) | 648 | '("-DCPU_DISPATCH=NEON;VFPV3;FP16;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX" |
| 657 | ("armhf-linux" | 649 | "-DCPU_DISPATCH_REQUIRE=SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2")) |
| 658 | '("-DCPU_BASELINE_DISABLE=NEON")) ; causes build failures | 650 | ("armhf-linux" |
| 659 | ("aarch64-linux" | 651 | '("-DCPU_BASELINE_DISABLE=NEON")) ; causes build failures |
| 660 | '("-DCPU_BASELINE=NEON" | 652 | ("aarch64-linux" |
| 661 | "-DCPU_DISPATCH=NEON;VFPV3;FP16")) | 653 | '("-DCPU_BASELINE=NEON" |
| 662 | (_ '())) | 654 | "-DCPU_DISPATCH=NEON;VFPV3;FP16")) |
| 663 | 655 | (_ '())) | |
| 664 | "-DBUILD_PERF_TESTS=OFF" | 656 | |
| 665 | "-DBUILD_TESTS=ON" | 657 | "-DBUILD_PERF_TESTS=OFF" |
| 666 | 658 | "-DBUILD_TESTS=ON" | |
| 667 | (string-append "-DOPENCV_EXTRA_MODULES_PATH=" (getcwd) | 659 | |
| 668 | "/opencv-contrib/modules") | 660 | (string-append "-DOPENCV_EXTRA_MODULES_PATH=" (getcwd) |
| 669 | 661 | "/opencv-contrib/modules") | |
| 670 | ;;Define test data: | 662 | |
| 671 | (string-append "-DOPENCV_TEST_DATA_PATH=" (getcwd) | 663 | ;;Define test data: |
| 672 | "/opencv-extra/testdata") | 664 | (string-append "-DOPENCV_TEST_DATA_PATH=" (getcwd) |
| 673 | 665 | "/opencv-extra/testdata") | |
| 674 | ;; Is ON by default and would try to rebuild 3rd-party protobuf, | 666 | |
| 675 | ;; which we had removed, which would lead to an error: | 667 | ;; Is ON by default and would try to rebuild 3rd-party protobuf, |
| 676 | "-DBUILD_PROTOBUF=OFF" | 668 | ;; which we had removed, which would lead to an error: |
| 677 | 669 | "-DBUILD_PROTOBUF=OFF" | |
| 678 | ;; OpenCV tries to use flatbuffers in 3rdparty which we removed | 670 | |
| 679 | ;; so for now we don't buildfor flatbuffer support | 671 | ;; OpenCV tries to use flatbuffers in 3rdparty which we removed |
| 680 | ;; TODO: make OpenCV use system flatbuffers which involves | 672 | ;; so for now we don't buildfor flatbuffer support |
| 681 | ;; modifying CMake files | 673 | ;; TODO: make OpenCV use system flatbuffers which involves |
| 682 | "-DWITH_FLATBUFFERS=OFF" | 674 | ;; modifying CMake files |
| 683 | 675 | "-DWITH_FLATBUFFERS=OFF" | |
| 684 | ;; Rebuild protobuf files, because we have a slightly different | 676 | |
| 685 | ;; version than the included one. If we would not update, we | 677 | ;; Rebuild protobuf files, because we have a slightly different |
| 686 | ;; would get a compile error later: | 678 | ;; version than the included one. If we would not update, we |
| 687 | "-DPROTOBUF_UPDATE_FILES=ON" | 679 | ;; would get a compile error later: |
| 688 | 680 | "-DPROTOBUF_UPDATE_FILES=ON" | |
| 689 | ;; For xfeatures2d. | 681 | |
| 690 | "-DOPENCV_SKIP_FEATURES2D_DOWNLOADING=ON") | 682 | ;; For xfeatures2d. |
| 691 | #:phases | 683 | "-DOPENCV_SKIP_FEATURES2D_DOWNLOADING=ON") |
| 692 | (modify-phases %standard-phases | 684 | #:phases |
| 693 | (add-after 'unpack 'disable-broken-tests | 685 | #~(modify-phases %standard-phases |
| 694 | (lambda _ | 686 | (add-after 'unpack 'disable-broken-tests |
| 695 | ;; This test fails with "unknown file: Failure" | 687 | (lambda _ |
| 696 | ;; But I couldn't figure out which file was missing: | 688 | ;; This test fails with "unknown file: Failure" |
| 697 | (substitute* "../opencv-contrib/modules/face/test/test_face_align.cpp" | 689 | ;; But I couldn't figure out which file was missing: |
| 698 | (("\\bcan_detect_landmarks\\b" all) | 690 | (substitute* "../opencv-contrib/modules/face/test/test_face_align.cpp" |
| 699 | (string-append "DISABLED_" all))) | 691 | (("\\bcan_detect_landmarks\\b" all) |
| 700 | 692 | (string-append "DISABLED_" all))) | |
| 701 | ;; This all fails with a comparison between the expected 396 and | 693 | |
| 702 | ;; the actual 440 in file size. | 694 | ;; This all fails with a comparison between the expected 396 and |
| 703 | (substitute* "modules/imgcodecs/test/test_exr.impl.hpp" | 695 | ;; the actual 440 in file size. |
| 704 | (("\\breadWrite_32FC1\\b" all) | 696 | (substitute* "modules/imgcodecs/test/test_exr.impl.hpp" |
| 705 | (string-append "DISABLED_" all))) | 697 | (("\\breadWrite_32FC1\\b" all) |
| 706 | 698 | (string-append "DISABLED_" all))) | |
| 707 | ;; These fail with protobuf parse errors that come from | 699 | |
| 708 | ;; opencv-extra/alldata. | 700 | ;; These fail with protobuf parse errors that come from |
| 709 | (substitute* "modules/dnn/test/test_layers.cpp" | 701 | ;; opencv-extra/alldata. |
| 710 | (("\\b(Accum|DataAugmentation|Resample|Correlation|Interp)\\b" all) | 702 | (substitute* "modules/dnn/test/test_layers.cpp" |
| 711 | (string-append "DISABLED_" all))) | 703 | (("\\b(Accum|DataAugmentation|Resample|Correlation|Interp)\\b" all) |
| 712 | 704 | (string-append "DISABLED_" all))) | |
| 713 | ;; This test fails on x86-64, loosen the bounds. | 705 | |
| 714 | ;; Expected: (max) < (0.1), actual: 0.2 vs 0.1 | 706 | ;; This test fails on x86-64, loosen the bounds. |
| 715 | (substitute* "modules/photo/test/test_hdr.cpp" | 707 | ;; Expected: (max) < (0.1), actual: 0.2 vs 0.1 |
| 708 | (substitute* "modules/photo/test/test_hdr.cpp" | ||
| 716 | (("0\\.1\\)") "0.222)")) | 709 | (("0\\.1\\)") "0.222)")) |
| 717 | 710 | ||
| 718 | ,@(if (target-aarch64?) | 711 | #$@(if (target-aarch64?) |
| 719 | `(;; This test fails on aarch64, loosen the bounds. | 712 | `(;; This test fails on aarch64, loosen the bounds. |
| 720 | ;; Expected: (max) < (0.131), actual: 0.207148 vs 0.131 | 713 | ;; Expected: (max) < (0.131), actual: 0.207148 vs 0.131 |
| 721 | (substitute* "modules/photo/test/test_hdr.cpp" | 714 | (substitute* "modules/photo/test/test_hdr.cpp" |
| 722 | (("0\\.131") "0.222")) | 715 | (("0\\.131") "0.222")) |
| 723 | ;; These tests hang forever on aarch64. | 716 | ;; These tests hang forever on aarch64. |
| 724 | (delete-file-recursively "modules/videoio/test/") | 717 | (delete-file-recursively "modules/videoio/test/") |
| 725 | ;; This test fails on aarch64 due to floating-point precision | 718 | ;; This test fails on aarch64 due to floating-point precision |
| 726 | ;; differences with ARM NEON. | 719 | ;; differences with ARM NEON. |
| 727 | ;; Expected: RMSE <= 0.34, actual: 0.407627 | 720 | ;; Expected: RMSE <= 0.34, actual: 0.407627 |
| 728 | (substitute* "../opencv-contrib/modules/optflow/test/test_OF_accuracy.cpp" | 721 | (substitute* "../opencv-contrib/modules/optflow/test/test_OF_accuracy.cpp" |
| 729 | (("\\bReferenceAccuracy\\b" all) | 722 | (("\\bReferenceAccuracy\\b" all) |
| 730 | (string-append "DISABLED_" all)))) | 723 | (string-append "DISABLED_" all)))) |
| 731 | '()) | 724 | '()) |
| 732 | 725 | ||
| 733 | ,@(if (target-riscv64?) | 726 | #$@(if (target-riscv64?) |
| 734 | `(;; This test fails on riscv64, loosen the bounds. | 727 | `(;; This test fails on riscv64, loosen the bounds. |
| 735 | ;; Expected: (max) < (0.1), actual: 0.220829 vs 0.1 | 728 | ;; Expected: (max) < (0.1), actual: 0.220829 vs 0.1 |
| 736 | (substitute* "modules/photo/test/test_hdr.cpp" | 729 | (substitute* "modules/photo/test/test_hdr.cpp" |
| 737 | (("0\\.1") "0.240")) | 730 | (("0\\.1") "0.240")) |
| 738 | ;; Expected equality of these values: | 731 | ;; Expected equality of these values: |
| 739 | ;; ellipses.size() | 732 | ;; ellipses.size() |
| 740 | ;; Which is: 668 | 733 | ;; Which is: 668 |
| 741 | ;; ellipses_size | 734 | ;; ellipses_size |
| 742 | ;; Which is: 2449 | 735 | ;; Which is: 2449 |
| 743 | (substitute* "../opencv-contrib/modules/ximgproc/test/test_fld.cpp" | 736 | (substitute* "../opencv-contrib/modules/ximgproc/test/test_fld.cpp" |
| 744 | (("\\bManySmallCircles\\b" all) | 737 | (("\\bManySmallCircles\\b" all) |
| 745 | (string-append "DISABLED_" all)))) | 738 | (string-append "DISABLED_" all)))) |
| 746 | '()))) | 739 | '()))) |
| 747 | (add-after 'unpack 'unpack-submodule-sources | 740 | (add-after 'unpack 'unpack-submodule-sources |
| 748 | (lambda* (#:key inputs #:allow-other-keys) | 741 | (lambda* (#:key inputs #:allow-other-keys) |
| 749 | (mkdir "../opencv-extra") | 742 | (mkdir "../opencv-extra") |
| 750 | (mkdir "../opencv-contrib") | 743 | (mkdir "../opencv-contrib") |
| 751 | (copy-recursively (assoc-ref inputs "opencv-extra") | 744 | (copy-recursively (assoc-ref inputs "opencv-extra") |
| 752 | "../opencv-extra") | 745 | "../opencv-extra") |
| 753 | (copy-recursively (assoc-ref inputs "opencv-contrib") | 746 | (copy-recursively (assoc-ref inputs "opencv-contrib") |
| 754 | "../opencv-contrib") | 747 | "../opencv-contrib") |
| 755 | 748 | ||
| 756 | ;; Disable downloads of Boost and VGG descriptors as we include | 749 | ;; Disable downloads of Boost and VGG descriptors as we include |
| 757 | ;; them in native inputs. | 750 | ;; them in native inputs. |
| 758 | (substitute* "../opencv-contrib/modules/xfeatures2d/CMakeLists.txt" | 751 | (substitute* "../opencv-contrib/modules/xfeatures2d/CMakeLists.txt" |
| 759 | (("download_(boost|vgg)_descriptors") "#")) | 752 | (("download_(boost|vgg)_descriptors") "#")) |
| 760 | (copy-recursively (assoc-ref inputs "opencv-3rdparty-boost") | 753 | (copy-recursively (assoc-ref inputs "opencv-3rdparty-boost") |
| 761 | "../downloads/xfeatures2d") | 754 | "../downloads/xfeatures2d") |
| 762 | (for-each make-file-writable | 755 | (for-each make-file-writable |
| 763 | (find-files "../downloads/xfeatures2d" ".")) | 756 | (find-files "../downloads/xfeatures2d" ".")) |
| 764 | (copy-recursively (assoc-ref inputs "opencv-3rdparty-vgg") | 757 | (copy-recursively (assoc-ref inputs "opencv-3rdparty-vgg") |
| 765 | "../downloads/xfeatures2d"))) | 758 | "../downloads/xfeatures2d"))) |
| 766 | (add-after 'build 'do-not-install-3rdparty-file | 759 | (add-after 'build 'do-not-install-3rdparty-file |
| 767 | (lambda _ | 760 | (lambda _ |
| 768 | (substitute* "cmake_install.cmake" | 761 | (substitute* "cmake_install.cmake" |
| 769 | (("file\\(INSTALL .*3rdparty/include/opencl/LICENSE.txt.*") | 762 | (("file\\(INSTALL .*3rdparty/include/opencl/LICENSE.txt.*") |
| 770 | "")))) | 763 | "")))) |
| 771 | (add-before 'check 'start-xserver | 764 | (add-before 'check 'start-xserver |
| 772 | (lambda* (#:key inputs #:allow-other-keys) | 765 | (lambda* (#:key inputs #:allow-other-keys) |
| 773 | (let ((xorg-server (assoc-ref inputs "xorg-server")) | 766 | (let ((xorg-server (assoc-ref inputs "xorg-server")) |
| 774 | (disp ":1")) | 767 | (disp ":1")) |
| 775 | (setenv "HOME" (getcwd)) | 768 | (setenv "HOME" (getcwd)) |
| 776 | (setenv "DISPLAY" disp) | 769 | (setenv "DISPLAY" disp) |
| 777 | ;; There must be a running X server and make check doesn't start one. | 770 | ;; There must be a running X server and make check doesn't start one. |
| 778 | ;; Therefore we must do it. | 771 | ;; Therefore we must do it. |
| 779 | (zero? (system (format #f "~a/bin/Xvfb ~a &" xorg-server disp))))))))) | 772 | (zero? (system (format #f "~a/bin/Xvfb ~a &" xorg-server disp))))))))) |
| 780 | (native-inputs | 773 | (native-inputs |
| 781 | `(("pkg-config" ,pkg-config) | 774 | `(("pkg-config" ,pkg-config) |
| 782 | ("xorg-server" ,xorg-server-for-tests) ;For running the tests | 775 | ("xorg-server" ,xorg-server-for-tests) ;For running the tests |
