(* EMAIL Image detector Copyright (C) 2009 BODIN Antoine This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ocamlc -I +camlimages graphics.cma ci_core.cma ci_png.cma ci_graphics.cma unix.cma email.ml -o email ocaml -I +camlimages graphics.cma ci_core.cma ci_png.cma ci_graphics.cma unix.cma email.ml *) let stdsize = 45 let loadimg f = let graphics = Graphic_image.array_of_image (Images.load f []) in let resize m = Array.append m (Array.make_matrix (stdsize - (Array.length m)) (Array.length m.(0)) 16777215) in let arrayreverse m = let (w,h) = (Array.length m, Array.length m.(0)) in let mat = Array.make_matrix h w 0 in Array.iteri (fun x l -> Array.iteri (fun y p -> mat.(y).(x)<-p) l) m; mat in arrayreverse (resize graphics) let load_alphabet dir typ = let incrchar a = char_of_int ((int_of_char a) + 1) in let load f = loadimg (dir^"/"^f^typ) in let specialchar = [('_', load "underscore"); ('-', load "dash"); ('.', load "dot"); ('@', load "at")] in let rec f c = match c with 'a'..'z' | '0'..'9' -> (c, load (Char.escaped c))::f (incrchar c) | _ -> [] in specialchar @ (f 'a') @ (f '0') let getemail (alphadir,typ) = let alphabet = load_alphabet alphadir typ in fun imglocation -> let img = loadimg imglocation in let rec searchletter start i alphabet = match alphabet with [] -> i | [(c,t)] when (Array.length t)=i -> print_char c; i | _ -> searchletter start (i+1) (List.filter (function (a,b) when (Array.length b)>i && b.(i)=img.(start+i) -> true | _ -> false) alphabet) in let rec convert = function start when start convert (start+(searchletter start 0 alphabet)) | _ -> () in convert 0 (* execute *) let imgdir dir = let get = getemail ("./alphabet", ".png") in let hdir = Unix.opendir dir in try while true do match Unix.readdir hdir with "." | ".." -> () | file -> get (dir^file); print_endline "" done with _ -> () let manual () = let get = getemail ("./alphabet", ".png") in match Array.length Sys.argv with 2 -> get Sys.argv.(1); print_endline "" | _ -> try while true do get (read_line ()); print_endline "" done with _ -> () let _ = imgdir "./address/" (* let _ = manual () *)