ocr.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016, 2020 Efraim Flashner <efraim@flashner.co.il>
  4. ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
  5. ;;; Copyright © 2019 Alex Vong <alexvong1995@gmail.com>
  6. ;;; Copyright © 2021 Andy Tai <atai@atai.org>
  7. ;;; Copyright © 2021 Nicolas Goaziou <mail@nicolasgoaziou.fr>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (gnu packages ocr)
  24. #:use-module ((guix licenses) #:prefix license:)
  25. #:use-module (guix packages)
  26. #:use-module (guix download)
  27. #:use-module (guix git-download)
  28. #:use-module (guix build-system cmake)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (guix build-system python)
  31. #:use-module (gnu packages)
  32. #:use-module (gnu packages autotools)
  33. #:use-module (gnu packages backup)
  34. #:use-module (gnu packages check)
  35. #:use-module (gnu packages compression)
  36. #:use-module (gnu packages curl)
  37. #:use-module (gnu packages djvu)
  38. #:use-module (gnu packages docbook)
  39. #:use-module (gnu packages documentation)
  40. #:use-module (gnu packages enchant)
  41. #:use-module (gnu packages gettext)
  42. #:use-module (gnu packages glib)
  43. #:use-module (gnu packages gtk)
  44. #:use-module (gnu packages icu4c)
  45. #:use-module (gnu packages pdf)
  46. #:use-module (gnu packages pkg-config)
  47. #:use-module (gnu packages python)
  48. #:use-module (gnu packages qt)
  49. #:use-module (gnu packages scanner)
  50. #:use-module (gnu packages xml)
  51. #:use-module (gnu packages image))
  52. (define-public ocrad
  53. (package
  54. (name "ocrad")
  55. (version "0.27")
  56. (source (origin
  57. (method url-fetch)
  58. (uri (string-append "mirror://gnu/ocrad/ocrad-"
  59. version ".tar.lz"))
  60. (sha256
  61. (base32
  62. "0divffvcaim89g4pvqs8kslbcxi475bcl3b4ynphf284k9zfdgx9"))))
  63. (build-system gnu-build-system)
  64. (native-inputs `(("lzip" ,lzip)))
  65. (home-page "https://www.gnu.org/software/ocrad/")
  66. (synopsis "Optical character recognition based on feature extraction")
  67. (description
  68. "GNU Ocrad is an optical character recognition program based on a
  69. feature extraction method. It can read images in PBM, PGM or PPM formats and
  70. it produces text in 8-bit or UTF-8 formats.")
  71. (license license:gpl3+)))
  72. (define-public tesseract-ocr
  73. ;; There are useful commits beyond the last official stable release.
  74. (let ((commit "97079fa353557af6df86fd20b5d2e0dff5d8d5df")
  75. (revision "1"))
  76. (package
  77. (name "tesseract-ocr")
  78. (version (git-version "4.1.1" revision commit))
  79. (source
  80. (origin
  81. (method git-fetch)
  82. (uri (git-reference
  83. (url "https://github.com/tesseract-ocr/tesseract")
  84. (commit commit)))
  85. (file-name (git-file-name name version))
  86. (sha256
  87. (base32
  88. "11137a4aaay7qp64vdjd83hz1l089nzi5a0ql0qgk8gn79pyhi98"))))
  89. (build-system gnu-build-system)
  90. (inputs
  91. `(("cairo" ,cairo)
  92. ("icu" ,icu4c)
  93. ("leptonica" ,leptonica)
  94. ("pango" ,pango)
  95. ("python-wrapper" ,python-wrapper)))
  96. (native-inputs
  97. `(("asciidoc" ,asciidoc)
  98. ("autoconf" ,autoconf)
  99. ("automake" ,automake)
  100. ("docbook-xsl" ,docbook-xsl)
  101. ("libarchive" ,libarchive)
  102. ("libcurl" ,curl)
  103. ("libtool" ,libtool)
  104. ("libtiff" ,libtiff)
  105. ("pkg-config" ,pkg-config)
  106. ("xsltproc" ,libxslt)))
  107. (arguments
  108. `(#:configure-flags
  109. (let ((leptonica (assoc-ref %build-inputs "leptonica")))
  110. (list (string-append "LIBLEPT_HEADERSDIR=" leptonica "/include")))
  111. #:tests? #f ; Tests currently result in a segfault
  112. #:phases
  113. (modify-phases %standard-phases
  114. (add-after 'unpack 'fix-docbook
  115. (lambda* (#:key inputs #:allow-other-keys)
  116. ;; Don't attempt to download XSL schema.
  117. (substitute* "doc/Makefile.am"
  118. (("http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl")
  119. (string-append (assoc-ref inputs "docbook-xsl")
  120. "/xml/xsl/docbook-xsl-"
  121. ,(package-version docbook-xsl)
  122. "/manpages/docbook.xsl")))))
  123. (add-after 'install 'build-training
  124. (lambda _
  125. (invoke "make" "training")))
  126. (add-after 'build-training 'install-training
  127. (lambda _
  128. (invoke "make" "training-install"))))))
  129. (home-page "https://github.com/tesseract-ocr/tesseract")
  130. (synopsis "Optical character recognition engine")
  131. (description
  132. "Tesseract is an optical character recognition (OCR) engine with very
  133. high accuracy. It supports many languages, output text formatting, hOCR
  134. positional information and page layout analysis. Several image formats are
  135. supported through the Leptonica library. It can also detect whether text is
  136. monospaced or proportional.")
  137. (license license:asl2.0))))
  138. (define-public gimagereader
  139. (package
  140. (name "gimagereader")
  141. (version "3.3.1")
  142. (source
  143. (origin
  144. (method url-fetch)
  145. (uri (string-append
  146. "https://github.com/manisandro/gImageReader/releases"
  147. "/download/v" version "/"
  148. "gimagereader-" version ".tar.xz"))
  149. (sha256
  150. (base32 "1pghffb55k3wq33nbn9fi0lmjbldpmvqs2msnvss8bxz1k1ck23n"))))
  151. (build-system cmake-build-system)
  152. (arguments
  153. `(#:tests? #f ;no test
  154. #:configure-flags (list "-DENABLE_VERSIONCHECK=0")
  155. #:phases
  156. (modify-phases %standard-phases
  157. (add-after 'unpack 'fix-build
  158. ;; XXX: Prevent compilation error: "incomplete type ‘QUrl’ used in
  159. ;; nested name specifier". Fixed upstream as
  160. ;; 6209e25dab20b233e399ff36fabe4252db0f9e44. It can be removed in
  161. ;; release 3.3.2+.
  162. (lambda _
  163. (with-directory-excursion "qt/src/hocr"
  164. (substitute* '("HOCROdtExporter.cc" "HOCRTextExporter.cc")
  165. (("#include <QMessageBox>\n" all)
  166. (string-append all "#include <QUrl>\n"))))
  167. #t)))))
  168. (native-inputs
  169. `(("gettext" ,gettext-minimal)
  170. ("intltool" ,intltool)
  171. ("pkg-config" ,pkg-config)))
  172. (inputs
  173. `(("enchant" ,enchant)
  174. ("djvulibre" ,djvulibre)
  175. ("leptonica" ,leptonica)
  176. ("podofo" ,podofo)
  177. ("poppler-qt5" ,poppler-qt5)
  178. ("sane-backends" ,sane-backends)
  179. ("qtbase" ,qtbase-5)
  180. ("qtspell" ,qtspell)
  181. ("quazip" ,quazip)
  182. ("tesseract" ,tesseract-ocr)))
  183. (home-page "https://github.com/manisandro/gImageReader")
  184. (synopsis "Qt front-end to tesseract-ocr")
  185. (description
  186. "gImageReader is a Qt front-end to Tesseract optical character
  187. recognition (OCR) software.
  188. gImageReader supports automatic page layout detection but the user can
  189. also manually define and adjust the recognition regions. It is
  190. possible to import images from disk, scanning devices, clipboard and
  191. screenshots. gImageReader also supports multipage PDF documents.
  192. Recognized text is displayed directly next to the image and basic text
  193. editing including search/replace and removing of line breaks is
  194. possible. Spellchecking for the output text is also supported if the
  195. corresponding dictionaries are installed.")
  196. (license license:gpl3+)))
  197. (define-public zinnia
  198. (let* ((commit "581faa8f6f15e4a7b21964be3a5ec36265c80e5b")
  199. (revision "1")
  200. ;; version copied from 'configure.in'
  201. (version (git-version "0.07" revision commit)))
  202. (package
  203. (name "zinnia")
  204. (version version)
  205. (source
  206. (origin
  207. (method git-fetch)
  208. (uri (git-reference
  209. (url "https://github.com/taku910/zinnia")
  210. (commit commit)))
  211. (sha256
  212. (base32
  213. "1izjy5qw6swg0rs2ym2i72zndb90mwrfbd1iv8xbpwckbm4899lg"))
  214. (file-name (git-file-name name version))
  215. (modules '((guix build utils)
  216. (ice-9 ftw)
  217. (srfi srfi-26)))
  218. (snippet ; remove unnecessary files with potentially different license
  219. '(begin
  220. (for-each delete-file-recursively
  221. (scandir "."
  222. (negate (cut member <> '("zinnia"
  223. "." "..")))))
  224. #t))))
  225. (build-system gnu-build-system)
  226. (arguments
  227. `(#:phases
  228. (modify-phases %standard-phases
  229. (replace 'bootstrap
  230. (lambda _
  231. (chdir "zinnia")
  232. (for-each make-file-writable
  233. '("config.log" "config.status"))
  234. #t)))))
  235. (home-page "https://taku910.github.io/zinnia/")
  236. (synopsis "Online hand recognition system with machine learning")
  237. (description
  238. "Zinnia is a simple, customizable and portable online hand recognition
  239. system based on Support Vector Machines. Zinnia simply receives user pen
  240. strokes as a sequence of coordinate data and outputs n-best characters sorted
  241. by SVM confidence. To keep portability, Zinnia doesn't have any rendering
  242. functionality. In addition to recognition, Zinnia provides training module
  243. that allows us to create any hand-written recognition systems with low-cost.")
  244. (license (list license:bsd-3 ; all files except...
  245. (license:non-copyleft ; some autotools related files
  246. "file://zinnia/aclocal.m4")
  247. license:x11 ; 'install-sh'
  248. license:public-domain))))) ; 'install-sh'
  249. ;;; python 2 bindings, license under the same terms as zinnia
  250. (define-public python2-zinnia
  251. (package
  252. (inherit zinnia)
  253. (name "python2-zinnia")
  254. (build-system python-build-system)
  255. (arguments
  256. `(#:python ,python-2 ; CObject API is used, it was removed in Python 3.2
  257. #:tests? #f ; avoid circular dependency on tegaki-zinnia-japanese
  258. #:phases
  259. (modify-phases %standard-phases
  260. (add-after 'unpack 'chdir
  261. (lambda _
  262. (chdir "zinnia/python")
  263. #t)))))
  264. (inputs
  265. `(("zinnia" ,zinnia)))))