gnu: opencv: Update configure flags.
[jackhill/guix/guix.git] / gnu / packages / image-processing.scm
CommitLineData
504c285d
JD
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 John Darrington <jmd@gnu.org>
3;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
fb226b43
JD
4;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
5;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
6;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
11861d2b 7;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
62834314 8;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
e506b5e9 9;;; Copyright © 2018 Lprndn <guix@lprndn.info>
6949f45c 10;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
504c285d
JD
11;;;
12;;; This file is part of GNU Guix.
13;;;
14;;; GNU Guix is free software; you can redistribute it and/or modify it
15;;; under the terms of the GNU General Public License as published by
16;;; the Free Software Foundation; either version 3 of the License, or (at
17;;; your option) any later version.
18;;;
19;;; GNU Guix is distributed in the hope that it will be useful, but
20;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;;; GNU General Public License for more details.
23;;;
24;;; You should have received a copy of the GNU General Public License
25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27(define-module (gnu packages image-processing)
28 #:use-module ((guix licenses) #:prefix license:)
29 #:use-module (guix packages)
30 #:use-module (guix utils)
31 #:use-module (guix download)
cdb2a211 32 #:use-module (guix build-system cmake)
504c285d
JD
33 #:use-module (guix build-system gnu)
34 #:use-module (gnu packages)
cdb2a211 35 #:use-module (gnu packages algebra)
e506b5e9 36 #:use-module (gnu packages bison)
cdb2a211 37 #:use-module (gnu packages boost)
504c285d
JD
38 #:use-module (gnu packages compression)
39 #:use-module (gnu packages documentation)
e506b5e9 40 #:use-module (gnu packages flex)
fb226b43 41 #:use-module (gnu packages fontutils)
5bbd6931 42 #:use-module (gnu packages ghostscript)
fb226b43 43 #:use-module (gnu packages gl)
5bbd6931 44 #:use-module (gnu packages glib)
cdb2a211
JD
45 #:use-module (gnu packages gnome)
46 #:use-module (gnu packages graphics)
47 #:use-module (gnu packages graphviz)
5bbd6931 48 #:use-module (gnu packages gstreamer)
62834314 49 #:use-module (gnu packages gtk)
504c285d 50 #:use-module (gnu packages image)
5bbd6931 51 #:use-module (gnu packages imagemagick)
cdb2a211 52 #:use-module (gnu packages maths)
5bbd6931 53 #:use-module (gnu packages pdf)
cdb2a211 54 #:use-module (gnu packages perl)
62834314 55 #:use-module (gnu packages photo)
cdb2a211 56 #:use-module (gnu packages pkg-config)
62834314 57 #:use-module (gnu packages protobuf)
cdb2a211 58 #:use-module (gnu packages python)
fb226b43 59 #:use-module (gnu packages serialization)
62834314 60 #:use-module (gnu packages video)
fb226b43 61 #:use-module (gnu packages xiph)
cdb2a211 62 #:use-module (gnu packages xml)
98d6cdda 63 #:use-module (gnu packages xorg))
504c285d
JD
64
65;; We use the latest snapshot of this package because the latest release is
66;; from 2011 and has known vulnerabilities that cannot easily be fixed by
67;; applying patches.
68(define-public dcmtk
69 (package
70 (name "dcmtk")
71 (version "3.6.1_20170228")
72 (source (origin
73 (method url-fetch)
74 (uri (string-append "ftp://dicom.offis.de/pub/dicom/offis/"
75 "software/dcmtk/snapshot/dcmtk-"
76 version ".tar.gz"))
77 (sha256
78 (base32
79 "04cwfx8yrscqcd59mxk2fh6314ckayi9cp68iql5a57pf2pg5qld"))))
80 (build-system gnu-build-system)
81 (inputs
82 `(("libtiff" ,libtiff)
83 ("libpng" ,libpng)
84 ("doxygen" ,doxygen)
85 ("zlib" ,zlib)))
86 (native-inputs
87 `(("perl" ,perl)))
88 (home-page "http://dcmtk.org")
89 (synopsis "Libraries and programs implementing parts of the DICOM standard")
90 (description "DCMTK is a collection of libraries and applications
91implementing large parts the DICOM standard. It includes software for
92examining, constructing and converting DICOM image files, handling offline
93media, sending and receiving images over a network connection, as well as
94demonstrative image storage and worklist servers.")
95 (license (license:fsf-free
96 "file://COPYRIGHT"
97 "A union of the Apache 2.0 licence and various non-copyleft
98licences similar to the Modified BSD licence."))))
cdb2a211
JD
99
100(define-public mia
101 (package
102 (name "mia")
11861d2b 103 (version "2.4.6")
cdb2a211
JD
104 (source (origin
105 (method url-fetch)
106 (uri (string-append "mirror://sourceforge/mia/mia/"
107 (version-major+minor version)
108 "/mia-" version ".tar.xz"))
109 (sha256
110 (base32
11861d2b 111 "0j4nd5z7i3v199jh7hqqhwd4g7snchizkc7rhzanpvngqg91m1pb"))))
cdb2a211
JD
112 (build-system cmake-build-system)
113 (arguments
114 `(#:configure-flags
115 (list "-DMIA_CREATE_NIPYPE_INTERFACES=0"
cdb2a211
JD
116 "-DCMAKE_CXX_FLAGS=-fpermissive")))
117 (inputs
118 `(("boost" ,boost)
119 ("dcmtk" ,dcmtk)
120 ("doxygen" ,doxygen)
121 ("eigen" ,eigen)
122 ("fftw" ,fftw)
123 ("fftwf" ,fftwf)
124 ("gsl" ,gsl)
125 ("gts" ,gts)
126 ("hdf5" ,hdf5)
127 ("itpp" ,itpp)
128 ("libjpeg" ,libjpeg)
129 ("libpng" ,libpng)
130 ("libtiff" ,libtiff)
131 ("libxml" ,libxml2)
132 ("libxml++" ,libxml++)
133 ("maxflow" ,maxflow)
134 ("niftilib" ,niftilib)
135 ("nlopt" ,nlopt)
136 ("openexr" ,openexr)
137 ("python-lxml" ,python2-lxml)
138 ("vtk" ,vtk)))
139 (native-inputs
140 `(("pkg-config" ,pkg-config)
141 ("python" ,python-2)))
142 (home-page "http://mia.sourceforge.net")
143 (synopsis "Toolkit for gray scale medical image analysis")
144 (description "MIA provides a combination of command line tools, plug-ins,
145and libraries that make it possible run image processing tasks interactively
146in a command shell and to prototype using the shell's scripting language. It
147is built around a plug-in structure that makes it easy to add functionality
148without compromising the original code base and it makes use of a wide variety
149of external libraries that provide additional functionality.")
150 (license license:gpl3+)))
fb226b43
JD
151
152(define-public vtk
153 (package
154 (name "vtk")
155 (version "7.1.0")
156 (source (origin
157 (method url-fetch)
158 (uri (string-append "http://www.vtk.org/files/release/"
159 (version-major+minor version)
160 "/VTK-" version ".tar.gz"))
161 (sha256
162 (base32
163 "0yj96z58haan77gzilnqp7xpf8hg5jk11a3jx55p2ksd400s0gjz"))))
164 (build-system cmake-build-system)
165 (arguments
166 '(#:build-type "Release" ;Build without '-g' to save space.
167 ;; -DVTK_USE_SYSTEM_NETCDF:BOOL=TRUE requires netcdf_cxx
168 #:configure-flags '("-DVTK_USE_SYSTEM_EXPAT:BOOL=TRUE"
169 "-DVTK_USE_SYSTEM_FREETYPE:BOOL=TRUE"
170 "-DVTK_USE_SYSTEM_HDF5:BOOL=TRUE"
171 "-DVTK_USE_SYSTEM_JPEG:BOOL=TRUE"
172 "-DVTK_USE_SYSTEM_JSONCPP:BOOL=TRUE"
173 "-DVTK_USE_SYSTEM_LIBXML2:BOOL=TRUE"
174 "-DVTK_USE_SYSTEM_OGGTHEORA:BOOL=TRUE"
175 "-DVTK_USE_SYSTEM_PNG:BOOL=TRUE"
176 "-DVTK_USE_SYSTEM_TIFF:BOOL=TRUE"
177 "-DVTK_USE_SYSTEM_ZLIB:BOOL=TRUE")
178 #:tests? #f)) ;XXX: no "test" target
179 (inputs
180 `(("libXt" ,libxt)
6a6db57f 181 ("xorgproto" ,xorgproto)
fb226b43
JD
182 ("libX11" ,libx11)
183 ("libxml2" ,libxml2)
184 ("mesa" ,mesa)
185 ("glu" ,glu)
186 ("expat" ,expat)
187 ("freetype" ,freetype)
188 ("hdf5" ,hdf5)
189 ("jpeg" ,libjpeg)
190 ("jsoncpp" ,jsoncpp)
191 ("libogg" ,libogg)
192 ("libtheora" ,libtheora)
193 ("png" ,libpng)
194 ("tiff" ,libtiff)
195 ("zlib" ,zlib)))
196 (home-page "http://www.vtk.org/")
197 (synopsis "Libraries for 3D computer graphics")
198 (description
199 "The Visualization Toolkit (VTK) is a C++ library for 3D computer graphics,
200image processing and visualization. It supports a wide variety of
201visualization algorithms including: scalar, vector, tensor, texture, and
202volumetric methods; and advanced modeling techniques such as: implicit
203modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay
204triangulation. VTK has an extensive information visualization framework, has
205a suite of 3D interaction widgets, supports parallel processing, and
206integrates with various databases on GUI toolkits such as Qt and Tk.")
207 (license license:bsd-3)))
62834314
BH
208
209(define-public opencv
210 (package
211 (name "opencv")
63856931 212 (version "3.4.3")
62834314
BH
213 (source (origin
214 (method url-fetch)
215 (uri (string-append "https://github.com/opencv/opencv/archive/"
216 version ".zip"))
217 (file-name (string-append name "-" version ".zip"))
218 (sha256
219 (base32
63856931 220 "0pycx1pz8lj794q32mlalyc3ijqxwsyin65r26nh4yc0p71xiirp"))
62834314
BH
221 (modules '((guix build utils)))
222 (snippet
223 '(begin
224 ;; Remove external libraries. We have all available in Guix:
225 (delete-file-recursively "3rdparty")
226
227 ;; Milky icon set is non-free:
228 (delete-file-recursively "modules/highgui/src/files_Qt/Milky")
229
230 ;; Some jars found:
231 (for-each delete-file
232 '("modules/java/test/pure_test/lib/junit-4.11.jar"
233 "samples/java/sbt/sbt/sbt-launch.jar"))))))
234 (build-system cmake-build-system)
235 (arguments
236 `(#:configure-flags
237 (list "-DWITH_IPP=OFF"
238 "-DWITH_ITT=OFF"
6949f45c 239 "-DWITH_CAROTENE=OFF" ; only visible on arm/aarch64
fdeb2def 240 "-DENABLE_PRECOMPILED_HEADERS=OFF"
62834314
BH
241
242 ;; CPU-Features:
243 ;; See cmake/OpenCVCompilerOptimizations.cmake
244 ;; (CPU_ALL_OPTIMIZATIONS) for a list of all optimizations
245 ;; BASELINE is the minimum optimization all CPUs must support
246 ;;
fdeb2def 247 ;; DISPATCH is the list of optional dispatches. We add them all.
62834314
BH
248 "-DCPU_BASELINE=SSE2, NEON"
249
fdeb2def 250 "-DCPU_DISPATCH=NEON;VFPV3;FP16;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX"
6949f45c
EF
251 ,@(if (string-prefix? "x86_64" (or (%current-target-system)
252 (%current-system)))
253 '("-DCPU_DISPATCH_REQUIRE=SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2")
254 '())
62834314
BH
255
256 "-DBUILD_PERF_TESTS=OFF"
6949f45c 257 "-DBUILD_TESTS=ON"
62834314 258
b5baf952 259 (string-append "-DOPENCV_EXTRA_MODULES_PATH=" (getcwd)
62834314
BH
260 "/opencv-contrib/opencv_contrib-" ,version
261 "/modules")
262
263 ;;Define test data:
b5baf952 264 (string-append "-DOPENCV_TEST_DATA_PATH=" (getcwd)
62834314
BH
265 "/opencv-extra/opencv_extra-" ,version
266 "/testdata")
267
268 ;; Is ON by default and would try to rebuild 3rd-party protobuf,
269 ;; which we had removed, which would lead to an error:
270 "-DBUILD_PROTOBUF=OFF"
271
272 ;; Rebuild protobuf files, because we have a slightly different
273 ;; version than the included one. If we would not update, we
274 ;; would get a compile error later:
275 "-DPROTOBUF_UPDATE_FILES=ON"
276
277 ;; xfeatures2d disabled, because it downloads extra binaries from
278 ;; https://github.com/opencv/opencv_3rdparty
279 ;; defined in xfeatures2d/cmake/download_{vgg|bootdesc}.cmake
280 ;; Cmp this bug entry:
281 ;; https://github.com/opencv/opencv_contrib/issues/1131
282 "-DBUILD_opencv_xfeatures2d=OFF")
283 #:phases
284 (modify-phases %standard-phases
285 (add-after 'unpack 'disable-broken-tests
286 (lambda _
287 ;; These tests fails with:
288 ;; vtkXOpenGLRenderWindow (0x723990): Could not find a decent config
289 ;; I think we have no OpenGL support with the Xvfb.
290 (substitute* '("modules/viz/test/test_tutorial3.cpp"
291 "modules/viz/test/test_main.cpp"
292 "modules/viz/test/tests_simple.cpp"
293 "modules/viz/test/test_viz3d.cpp")
294 (("(TEST\\(Viz, )([a-z].*\\).*)" all pre post)
295 (string-append pre "DISABLED_" post)))
296
297 ;; This one fails with "unknown file: Failure"
298 ;; But I couldn't figure out which file was missing:
299 (substitute* (list (string-append
300 "../opencv-contrib/opencv_contrib-"
301 ,version
302 "/modules/face/test/test_face_align.cpp"))
303 (("(TEST\\(CV_Face_FacemarkKazemi, )(can_detect_landmarks\\).*)"
304 all pre post)
305 (string-append pre "DISABLED_" post)))
306
307 ;; Failure reason: Bad accuracy
308 ;; Incorrect count of accurate poses [2nd case]: 90.000000 / 94.000000
309 (substitute* (list (string-append
310 "../opencv-contrib/opencv_contrib-"
311 ,version
312 "/modules/rgbd/test/test_odometry.cpp"))
313 (("(TEST\\(RGBD_Odometry_Rgbd, )(algorithmic\\).*)" all pre post)
314 (string-append pre "DISABLED_" post)))
315 #t))
316
317 ;; Idea copied from ldc.scm (ldc-bootstrap):
318 (add-after 'unpack 'unpack-submodule-sources
319 (lambda* (#:key inputs #:allow-other-keys)
320 (mkdir "../opencv-extra")
321 (mkdir "../opencv-contrib")
322 (let ((unpack (lambda (source target)
323 (with-directory-excursion target
324 (apply invoke "unzip"
325 (list (assoc-ref inputs source)))))))
326 (unpack "opencv-extra" "../opencv-extra")
327 (unpack "opencv-contrib" "../opencv-contrib"))))
328
329 (add-after 'set-paths 'add-ilmbase-include-path
330 (lambda* (#:key inputs #:allow-other-keys)
331 ;; OpenEXR propagates ilmbase, but its include files do not appear
332 ;; in the CPATH, so we need to add "$ilmbase/include/OpenEXR/" to
333 ;; the CPATH to satisfy the dependency on "ImathVec.h".
334 (setenv "CPATH"
335 (string-append (assoc-ref inputs "ilmbase")
336 "/include/OpenEXR"
337 ":" (or (getenv "CPATH") "")))
338 #t))
339 (add-before 'check 'start-xserver
340 (lambda* (#:key inputs #:allow-other-keys)
341 (let ((xorg-server (assoc-ref inputs "xorg-server"))
342 (disp ":1"))
343 (setenv "HOME" (getcwd))
344 (setenv "DISPLAY" disp)
345 ;; There must be a running X server and make check doesn't start one.
346 ;; Therefore we must do it.
347 (zero? (system (format #f "~a/bin/Xvfb ~a &" xorg-server disp)))))))))
348 (native-inputs
349 `(("unzip" ,unzip)
350 ("pkg-config" ,pkg-config)
351 ("xorg-server" ,xorg-server) ; For running the tests
352 ("opencv-extra"
353 ,(origin
354 (method url-fetch)
355 (uri (string-append "https://codeload.github.com/"
356 "opencv/opencv_extra/zip/" version))
357 (file-name (string-append "opencv-extra-" version ".zip"))
358 (sha256
63856931 359 (base32 "0yd1vidzbg6himxyh4yzivywijg8548kfmcn421khabnipm7l74y"))))
62834314
BH
360 ("opencv-contrib"
361 ,(origin
362 (method url-fetch)
363 (uri (string-append "https://codeload.github.com/"
364 "opencv/opencv_contrib/zip/" version))
365 (file-name (string-append "opencv-contrib-" version ".zip"))
366 (sha256
63856931 367 (base32 "0j0ci6ia1qwklp9hq07ypl0vkngj1wrgh6n98n657m5d0pyp4m0g"))))))
62834314
BH
368 (inputs `(("libjpeg" ,libjpeg)
369 ("libpng" ,libpng)
370 ("jasper" ,jasper)
371 ;; ffmpeg 4.0 causes core dumps in tests.
372 ("ffmpeg" ,ffmpeg-3.4)
373 ("libtiff" ,libtiff)
374 ("hdf5" ,hdf5)
375 ("libgphoto2" ,libgphoto2)
376 ("libwebp" ,libwebp)
377 ("zlib" ,zlib)
378 ("gtkglext" ,gtkglext)
379 ("openexr" ,openexr)
380 ("ilmbase" ,ilmbase)
381 ("gtk+" ,gtk+-2)
382 ("python-numpy" ,python-numpy)
383 ("protobuf" ,protobuf)
384 ("vtk" ,vtk)
385 ("python" ,python)))
5834e4b7
BH
386 ;; These three CVEs are not a problem of OpenCV, see:
387 ;; https://github.com/opencv/opencv/issues/10998
388 (properties '((lint-hidden-cve . ("CVE-2018-7712"
389 "CVE-2018-7713"
390 "CVE-2018-7714"))))
62834314
BH
391 (synopsis "Computer vision library")
392 (description "OpenCV is a library aimed at
393real-time computer vision, including several hundred computer
394vision algorithms. It can be used to do things like:
395
396@itemize
397@item image and video input and output
398@item image and video processing
399@item displaying
400@item feature recognition
401@item segmentation
402@item facial recognition
403@item stereo vision
404@item structure from motion
405@item augmented reality
406@item machine learning
407@end itemize\n")
408 (home-page "https://opencv.org/")
409 (license license:bsd-3)))
5bbd6931
L
410
411(define-public vips
412 (package
413 (name "vips")
414 (version "8.7.1")
415 (source (origin
416 (method url-fetch)
417 (uri (string-append
418 "https://github.com/libvips/libvips/releases/download/v"
419 version "/vips-" version ".tar.gz"))
420 (sha256
421 (base32 "1w3b90pdw7nj2p0gb4f96h6zhmga513f968ldfhz1rkhg7y81c0s"))))
422 (build-system gnu-build-system)
423 (native-inputs
424 `(("pkg-config" ,pkg-config)
425 ("gobject-introspection" ,gobject-introspection)))
426 (inputs
427 `(("glib" ,glib)
428 ("libjpeg" ,libjpeg)
429 ("libpng" ,libpng)
430 ("librsvg" ,librsvg)
431 ("libtiff" ,libtiff)
432 ("libexif" ,libexif)
433 ("giflib" ,giflib)
434 ("libgsf" ,libgsf)
435 ("fftw" ,fftw)
436 ("poppler" ,poppler)
437 ("pango" ,pango)
438 ("lcms" ,lcms)
439 ("matio" ,matio)
440 ("libwebp" ,libwebp)
441 ("niftilib" ,niftilib)
442 ("openexr" ,openexr)
443 ("orc" ,orc)
444 ("imagemagick" ,imagemagick)
445 ("libxml2" ,libxml2)
446 ("expat" ,expat)
447 ("hdf5" ,hdf5)))
448 (home-page "https://libvips.github.io/libvips/")
37c1cf89
MB
449 (synopsis "Image processing system")
450 (description
451 "vips is a demand-driven, horizontally threaded image processing library.")
5bbd6931 452 (license license:lgpl2.1+)))
e506b5e9
L
453
454(define-public nip2
455 (package
456 (name "nip2")
457 (version "8.7.0")
458 (source
459 (origin
460 (method url-fetch)
461 (uri (string-append "https://github.com/libvips/nip2/releases/download/v"
462 version "/nip2-" version ".tar.gz" ))
463 (sha256
464 (base32 "08dxfds4n1vxdilxcw01741a2r6fxyhawi656b7f0hy6znnkbsbc"))))
465 (build-system gnu-build-system)
466 (arguments
467 `(#:phases
468 (modify-phases %standard-phases
469 ;; test_conv.ws keep failing so disabling for now
470 (add-after 'unpack 'disable-test-conv
471 (lambda _
472 (delete-file "test/workspaces/test_conv.ws")
473 #t))
474 (add-before 'check 'set-home
475 (lambda _
476 (setenv "HOME" "/tmp") #t)))))
477 (inputs
478 `(("vips" ,vips)
479 ("glib" ,glib)
480 ("libtiff" ,libtiff)
481 ("gtk+-2" ,gtk+-2)
482 ("libxml2" ,libxml2)
483 ("libexif" ,libexif)
484 ("libjpeg" ,libjpeg) ;required by vips.pc
485 ("librsvg" ,librsvg)
486 ("fftw" ,fftw)
487 ("libgsf" ,libgsf)
488 ("imagemagick" ,imagemagick)
489 ("orc" ,orc)
490 ("matio" ,matio)
491 ("lcms" ,lcms)
492 ("libwebp" ,libwebp)
493 ("openexr" ,openexr)
494 ("poppler" ,poppler)
495 ("gsl" ,gsl)))
496 (native-inputs
497 `(("flex" ,flex)
498 ("bison" ,bison)
499 ("pkg-config" ,pkg-config)))
500 (home-page "https://github.com/libvips/nip2")
501 (synopsis "Spreadsheet-like GUI for libvips")
502 (description "This package provide a graphical user interface (GUI) for
503the VIPS image processing library. It's a little like a spreadsheet: you
504create a set of formula connecting your objects together, and on a change nip2
505recalculates.")
506 (license license:gpl2+)))