source: project/release/4/leptonica/examples/test-components.scm @ 20747

Last change on this file since 20747 was 20747, checked in by petercrlane, 11 years ago

version 0.2

File size: 1.4 KB
Line 
1;; this example reads a black-and-white scanned document and extracts the
2;; components which are roughly letter-sized
3
4(require-extension format)
5(require-extension leptonica)
6(require-extension srfi-42)
7
8(define original-pix (pix-read "feyn.tif"))
9(format #t "Size of original ~d x ~d, colour depth ~d bpp~&"
10        (pix-get-width original-pix)
11        (pix-get-height original-pix)
12        (pix-get-depth original-pix))
13
14(format #t "Image contains ~d components (by 8) and ~d (by 4)~&"
15        (pix-count-conn-comp original-pix 8)
16        (pix-count-conn-comp original-pix 4))
17
18(format #t "Analysing by 8-wise connectivity~&")
19
20(let-values 
21  (((boxes images) (pix-conn-comp-pixa original-pix 8)))
22  (when (eq? #f boxes) (error "Failure in identifying components"))
23
24  (format #t "There are ~d boxes~&"
25          (boxa-get-count boxes))
26
27  (do-ec (: i (boxa-get-count boxes))
28         (let ((box (boxa-get-box boxes i L-COPY)))
29           (let-values 
30             (((x y w h) (box-get-geometry box)))
31             ; constraint the size of image to save
32             (when (and (> w 10) (< w 50)
33                        (> h 10) (< h 50))
34               (format #t "Box ~d at (~d, ~d) size ~d x ~d~&"
35                       i x y w h)
36               (let ((pix (pixa-get-pix images i L-COPY)))
37                 (pix-write (string-concatenate (list "feyn-" (number->string i) ".png"))
38                            pix 
39                            IFF-PNG)))))))
Note: See TracBrowser for help on using the repository browser.