Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add charcter extraction and optimisation

  • Loading branch information...
commit 2e7fe6cc5c6f5ace20422029b2b902c06d43f268 1 parent 66c07aa
@CercleOnix authored
View
BIN  OCR/.Extraction.ml.swp
Binary file not shown
View
BIN  OCR/.Pretreatment.ml.swp
Binary file not shown
View
BIN  OCR/.main.ml.swp
Binary file not shown
View
34 OCR/Extraction.ml
@@ -102,7 +102,7 @@ let v_prj mtx w h c =
(*
Algorithme de détection des lignes et colonnes.
*)
-let rlsa mtx w h ch cv =
+let rlsa mtx w h ch cv ce =
let mtx1 = h_prj mtx w h ch and mtx2 = v_prj mtx w h cv and
mtx3 = Array.make_matrix w h 0 in
for y = 0 to h-1 do
@@ -113,7 +113,7 @@ let rlsa mtx w h ch cv =
mtx3.(x).(y) <- 255
done
done;
- mtx3
+ h_prj mtx3 w h ce
(*
Fonction de propagation des 4-connexes.
@@ -203,7 +203,7 @@ let get_lng_iter mtx w h =
*)
let get_class bi =
let rm = (float)bi.no /. (float)bi.t in
- if bi.h < 75 && rm < 5. then
+ if bi.h < 130 && rm < 7. then
1
else
2
@@ -268,6 +268,18 @@ let get_blocks mtxi (mtxs, n) w h =
vec
(*
+ Renvoi un vecteur de label contenance les informations
+ sur les formes d'une image.
+*)
+let labellise_blocks mtx w h =
+ let mtx2 = rlsa mtx w h 200 300 12 in
+ get_blocks mtx (get_lng_rec mtx2 w h) w h
+
+let labellise_char mtx w h =
+ let mtx2 = v_prj mtx w h 6 in
+ get_blocks mtx2 (get_lng_rec mtx2 w h) w h
+
+(*
Efface les images ou lignes inutilee.
*)
let clean mtx vec =
@@ -286,7 +298,6 @@ let clean mtx vec =
end
done;
mtx
-
(*
Dessine des rectangles autours des lignes de textes.
*)
@@ -306,3 +317,18 @@ let draw_rec mtx vec =
done
done;
mtx2
+
+(*
+ Résultat de l'extraction des blocs.
+*)
+let result_blocs mtx w h =
+ let vec = labellise_blocks mtx w h in
+ draw_rec (clean mtx vec) vec
+
+(*
+ Résultat de l'extraction des charactères.
+*)
+let result_char mtx w h =
+ let vec = labellise_blocks mtx w h in
+ let vec2 = labellise_char (clean mtx vec) w h in
+ draw_rec mtx vec2
View
5 OCR/OSdl.ml
@@ -21,6 +21,11 @@ let display su w h =
Sdlvideo.flip des
(*
+ Sauvegarde une surface en un fichier .bmp.
+*)
+let save su s = Sdlvideo.save_BMP su s
+
+(*
Attend une touche.
*)
let rec wait () =
View
12 OCR/main.ml
@@ -13,11 +13,11 @@ let main () =
let mtx2 = Pretreatment.conv_filter_3x3 mtx w h
[|2;5;2;5;20;5;2;5;2|] (1./.48.) in
let mtx3 = Pretreatment.bin mtx2 w h in
- let mtx4 = Extraction.h_prj (Extraction.rlsa mtx3 w h 300 500) w h 30 in
- let vec = Extraction.get_blocks mtx3 (Extraction.get_lng_rec mtx4 w h) w h in
- let mtx5 = Extraction.clean mtx3 vec in
- OSdl.display (Pretreatment.mtx2su mtx5 w h pfi) w h;
- OSdl.wait ();
- exit 0
+ let mtx4 = (*Extraction.draw_rec mtx (Extraction.get_blocks mtx3 (Extraction.get_lng_rec (Extraction.rlsa mtx3 w h 300 500 30) w h) w h)*)Extraction.result_char mtx3 w h in
+ let suf = Pretreatment.mtx2su mtx4 w h pfi in
+ OSdl.display suf w h;
+ OSdl.save suf "result.bmp";
+ OSdl.wait ();
+ exit 0
let _ = main ();
Please sign in to comment.
Something went wrong with that request. Please try again.