Permalink
Browse files

rajout interface bug sur le Main.ml

  • Loading branch information...
1 parent f978b07 commit 5d8a2419dd4f1bd87f275849b1cc068f1b5e054b Chuck committed Dec 1, 2012
Showing with 170 additions and 26 deletions.
  1. +43 −15 Interface/ocr_gui.ml
  2. +26 −0 OCR/Main.ml
  3. +7 −11 OCR/Makefile
  4. +94 −0 OCR/ocr_gui.ml
View
58 Interface/ocr_gui.ml
@@ -7,31 +7,57 @@ let window = GWindow.window
~height:600
~width:800 ()
-let box = GPack.vbox ~packing:window#add ()
+let box = GPack.vbox
+ ~spacing:10
+ ~border_width:10
+ ~packing:window#add ()
(* Toolbar *)
-let toolbar = GButton.toolbar
- ~orientation:`HORIZONTAL
+let toolbar = GButton.toolbar
+ ~orientation:`HORIZONTAL
~style:`ICONS
~packing:(box#pack ~expand:false) ()
-
+
let data = [`T "Extraire le texte"; `S; `B `SAVE; `S; `B `CUT; `B `COPY; `B `PASTE; `S;]
let _ =
let packing = toolbar#insert in
List.iter (function
- | `S -> ignore (GButton.separator_tool_item ~packing ())
- | `B stock -> ignore (GButton.tool_button ~stock ~packing ())
- | `T label -> ignore (GButton.tool_button ~label ~packing ())
- | _ -> ()
+ | `S -> ignore (GButton.separator_tool_item ~packing ())
+ | `B stock -> ignore (GButton.tool_button ~stock ~packing ())
+ | `T label -> let btn = GButton.tool_button ~label ~packing ()
+ in ignore btn;btn#connect#clicked (Main#main ())
+ | _ -> ()
) data
+
+let item = GButton.tool_item
+ ~packing:toolbar#insert ()
+
+let about_button =
+ let dlg = GWindow.about_dialog
+ ~authors:
+ ["Les Greens :
+Abisaad Elie (<abisaa_e@epita.fr>)
+Dos Santos Johan (<dossan_j@epita.fr>)
+Froger Antoine (<froger_a@epita.fr>)
+Gibert Charles (<gibert_c@epita.fr>)"]
+ ~copyright:"Copyright © 2012-2013 Colibri"
+ ~version:" colibri 1.0"
+ ~website:"site elie ici"
+ ~position:`CENTER_ON_PARENT
+ ~parent:window
+ ~destroy_with_parent:true () in
+ let btn = GButton.button ~stock:`ABOUT ~packing:item#add () in
+ GMisc.image ~stock:`ABOUT ~packing:btn#set_image ();
+ btn#connect#clicked (fun () -> ignore (dlg#run ()); dlg#misc#hide ());
+ btn
(* Parcourir *)
let btn = GFile.chooser_button
~action:`OPEN
~packing:(box#pack ~expand:false) ()
-
+
let get_contents = function (* str_op -> str *)
| Some x -> x
| _ -> raise Not_found
@@ -43,22 +69,24 @@ let txt_frame = GBin.aspect_frame
let entry = GEdit.entry
~text: ""
~packing: txt_frame#add
-()
+ ()
+
(* Image Preview *)
let img_frame = GBin.aspect_frame
~label:"Image"
~packing:box#add ()
-
+
let image = GMisc.image
~packing:img_frame#add ()
-
+
(* Events *)
let _ =
btn#connect#selection_changed ~callback:(
fun _ -> image#set_file(get_contents btn#filename);
- entry#set_text("Texte extrait à partir de l'image.")
+ entry#set_text("Texte extrait à partir de l'image.")
);
window#connect#destroy ~callback:GMain.quit;
-window#show();
-GMain.main()
+ window#show();
+ GMain.main()
+
View
26 OCR/Main.ml
@@ -0,0 +1,26 @@
+(*
+Entrée du programme.
+*)
+let main img =
+ OSdl.init ();
+ let su = Sdlloader.load_image img in
+ let si = Sdlvideo.surface_info su and
+ pfi = Sdlvideo.surface_format su in
+ let w = si.Sdlvideo.w and h = si.Sdlvideo.h in
+ let mtx = Pretreatment.su2grey su w h in
+ let mtx2 = Pretreatment.conv_filter_3x3 mtx w h
+ [|2;5;2;5;20;5;2;5;2|] (1./.48.) in
+ let mtx2 = Binarisation.wiener mtx2 in(*
+ [|0;1;0;1;-4;1;0;1;0|] (1.) in
+let mtx3 = Pretreatment.new_binarisation
+ (Pretreatment.pre_bin mtx2 w h) w h in*)
+ let mtx3 = Binarisation.niblack mtx2 in
+ let angle = Rotation.hough_skew_detection mtx3 w h in
+ let mtx3 = Rotation.rotate mtx3 w h (-.angle) in
+ (* let mtx_debug = Rotation.trace_line mtx3 w h (angle) in
+ *) print_string " degree:";print_float (Tools.rad2deg angle);
+ OSdl.display (Pretreatment.mtx2su mtx3 w h pfi) w h;
+ OSdl.wait ();
+ (*OSdl.display (Pretreatment.mtx2su mtx_debug w h pfi) w h;*)
+ exit 0
+
View
18 OCR/Makefile
@@ -1,14 +1,10 @@
-OCL = ocamlopt
-OCLF = -I +sdl
-OCLD = bigarray.cmxa sdl.cmxa sdlloader.cmxa
-SRC = main.ml
-DST = Ocr
-DPD = Tools.ml Pretreatment.ml OSdl.ml Rotation.ml Binarisation.ml
+LIB = ocamlopt -I +sdl -I +lablgtk2
+DPDC = sdl.cmxa sdlloader.cmxa bigarray.cmxa lablgtk.cmxa
+MOD = Tools.ml Pretreatment.ml OSdl.ml Rotation.ml Binarisation.ml Main.ml
-Exe: Ocr Clean
+EXE:
+ $(LIB) $(DPDC) -o Interface $(MOD) ocr_gui.ml
-Ocr:
- $(OCL) $(OCLF) $(OCLD) -o $(DST) $(DPD) $(SRC)
+Clean :
+ rm *.cm* *.o Interface
-Clean:
- rm -f *.c* *.o
View
94 OCR/ocr_gui.ml
@@ -0,0 +1,94 @@
+let _ = GMain.init()
+
+(* Fenêtre principale de l'application. *)
+let window = GWindow.window
+ ~title:"Colibri"
+ ~position:`CENTER
+ ~height:600
+ ~width:800 ()
+
+let box = GPack.vbox
+ ~spacing:10
+ ~border_width:10
+ ~packing:window#add ()
+
+(* Toolbar *)
+let toolbar = GButton.toolbar
+ ~orientation:`HORIZONTAL
+ ~style:`ICONS
+ ~packing:(box#pack ~expand:false) ()
+
+(* Parcourir *)
+let btn = GFile.chooser_button
+ ~action:`OPEN
+ ~packing:(box#pack ~expand:false) ()
+
+let get_contents = function (* str_op -> str *)
+ | Some x -> x
+ | _ -> raise Not_found
+
+
+let data = [`T "Extraire le texte"; `S; `B `SAVE; `S; `B `CUT; `B `COPY; `B `PASTE; `S;]
+
+let _ =
+ let packing = toolbar#insert in
+ List.iter (function
+ | `S -> ignore (GButton.separator_tool_item ~packing ())
+ | `B stock -> ignore (GButton.tool_button ~stock ~packing ())
+ | `T label -> let btn1 = GButton.tool_button ~label ~packing ()
+ in ignore btn1;btn1#connect#clicked (let img = btn#title
+ in Main.main img)
+ | _ -> ()
+ ) data
+
+let item = GButton.tool_item
+ ~packing:toolbar#insert ()
+
+let about_button =
+ let dlg = GWindow.about_dialog
+ ~authors:
+ ["Les Greens :
+
+Abisaad Elie (<abisaa_e@epita.fr>)
+Dos Santos Johan (<dossan_j@epita.fr>)
+Froger Antoine (<froger_a@epita.fr>)
+Gibert Charles (<gibert_c@epita.fr>)"]
+ ~copyright:"Copyright © 2012-2013 Colibri"
+ ~version:" colibri 1.0"
+ ~website:"site elie ici"
+ ~position:`CENTER_ON_PARENT
+ ~parent:window
+ ~destroy_with_parent:true () in
+ let btn = GButton.button ~stock:`ABOUT ~packing:item#add () in
+ GMisc.image ~stock:`ABOUT ~packing:btn#set_image ();
+ btn#connect#clicked (fun () -> ignore (dlg#run ()); dlg#misc#hide ());
+ btn
+
+(* Textbox *)
+let txt_frame = GBin.aspect_frame
+ ~label:"Texte"
+ ~packing:box#add ()
+let entry = GEdit.entry
+ ~text: ""
+ ~packing: txt_frame#add
+ ()
+
+(* Image Preview *)
+let img_frame = GBin.aspect_frame
+ ~label:"Image"
+ ~packing:box#add ()
+
+let image = GMisc.image
+ ~packing:img_frame#add ()
+
+(* Events *)
+let _ =
+ btn#connect#selection_changed ~callback:(
+ fun _ -> image#set_file(get_contents btn#filename);
+ entry#set_text("Texte extrait à partir de l'image.")
+ );
+ window#connect#destroy ~callback:GMain.quit;
+
+ window#show();
+ GMain.main()
+

0 comments on commit 5d8a241

Please sign in to comment.