Permalink
Browse files

rename

  • Loading branch information...
1 parent 475e33c commit b954ab36e4284be80fbfe959ef24ad3d427f930e Dos Santos committed Oct 20, 2012
Showing with 22 additions and 249 deletions.
  1. +22 −15 OCR/Extraction.ml
  2. +0 −234 OCR/Extraction2.ml
View
@@ -133,6 +133,8 @@ type labelise =
mutable value:int;
mutable label:int;
}
+
+(* Ajoute à chaque pixel de mtx une variable label initialisé à -1 *)
let mtx2labelise mtx w h =
let lab = Array.make_matrix w h { value = 0; label = -1 } in
for x = 0 to w-1 do
@@ -142,7 +144,7 @@ let mtx2labelise mtx w h =
done;
lab
- (* ne pas utiliser sur les contours d'une matrice *)
+ (* ne pas utiliser sur les contours d'une matrice / propage le label aux pixelsnon-blancs voisins *)
let rec propag mtx i j acc =
if mtx.(i).(j).label = -1 && mtx.(i).(j).value <> 255 then
begin
@@ -153,47 +155,51 @@ let rec propag mtx i j acc =
propag mtx i j+1 acc
end
+(* Détermine pour chaque pixel le numéro de label de son bloc *)
let path mtx w h =
let lab = mtx2labelise mtx w h in
- let accu = ref 0 in
+ let l = ref 0 in
for x = 1 to w-2 do
for y = 1 to h-2 do
if lab.(x).(y).label = -1 && lab.(x).(y).value <> 255 then
(
- propag lab x y accu;
- accu := !accu +1
+ propag lab x y l;
+ l := !l +1
)
done
done;
lab
+(* Calcule le nombre de bloc dans mtx *)
let max_label mtx w h =
let maxi = ref(0) in
for x = 0 to w-1 do
for y = 0 to h-1 do
maxi := max (!maxi) (mtx.(x).(y).label)
done
- done
+ done;
maxi
+(* Crée le vecteur contenant tous les blocs de mtx *)
let lab2label mtx w h =
let lab = path mtx w h in
- let vect = Array.make ((max_label mtx) -1)
- { value=0; firstx= -1; firsty = -1; lastx = -1; lasty = -1} in
+ let vect = Array.init ((max_label mtx) -1) (fun i ->
+{ value=i; firstx= w; firsty = h; lastx = 0; lasty = 0}) in
for x = 1 to w-2 do
for y = 1 to h-2 do
- let l = lab.(x).(y).label and v = lab.(x).(y).value in
- if lab.(x).(y).label <> -1 then
+ let l = lab.(x).(y).label in
+ if l <> -1 then
(
- if (vect[l].firstx = -1) then
- ( vect[l].firstx <- x; vect[l].firsty <- y )
-
-
-
+ vect[l].firstx <- min (vect[l].firstx) x
+ vect[l].firsty <- min (vect[l].firsty) y
+ vect[l].lastx < max (vect[l].lastx) x
+ vect[l].lasty <- max (vect[l].lasty) y
)
done
- done
+ done;
+ vect
+(*
let get_line (mtx, n) w h =
print_int n;
let mtx2 = Array.make_matrix w h 255
@@ -225,3 +231,4 @@ let get_line (mtx, n) w h =
done
done;
mtx2
+*)
View
@@ -1,234 +0,0 @@
-let h_prj mtx w h c =
- if c > w then
- invalid_arg "C value is higher than the width of the image.";
- let mtx2 = Array.make_matrix w h 255 and n = ref 0 and min = ref 0 in
- for y = 0 to h-1 do
- for x = 0 to w-1 do
- if mtx.(x).(y) = 255 then
- begin
- mtx2.(x).(y) <- 255;
- n := !n+1
- end
- else
- begin
- if !min = 0 then
- begin
- min := x+1;
- n := 0;
- mtx2.(x).(y) <- 0
- end
- else
- if !n <= c then
- begin
- for i = !min to x+1 do
- mtx2.(i).(y) <- 0
- done;
- min := x+1;
- n := 0;
- end
- else
- begin
- mtx2.(x).(y) <- 0;
- min := x+1;
- n := 0
- end
- end
- done;
- min := 0;
- n := 0;
- done;
- mtx2
-
-let v_prj mtx w h c =
- if c > h then
- invalid_arg "C value is higher than the width of the image.";
- let mtx2 = Array.make_matrix w h 255 and n = ref 0 and min = ref 0 in
- for x = 0 to w-1 do
- for y = 0 to h-1 do
- if mtx.(x).(y) = 255 then
- begin
- mtx2.(x).(y) <- 255;
- n := !n+1
- end
- else
- begin
- if !min = 0 then
- begin
- min := y+1;
- n := 0;
- mtx2.(x).(y) <- 0
- end
- else
- if !n <= c then
- begin
- for i = !min to y+1 do
- mtx2.(x).(i) <- 0
- done;
- min := y+1;
- n := 0;
- end
- else
- begin
- mtx2.(x).(y) <- 0;
- min := y+1;
- n := 0
- end
- end
- done;
- min := 0;
- n := 0;
- done;
- mtx2
-
-let rlsa mtx w h ch cv =
- 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
- for x = 0 to w-1 do
- if mtx1.(x).(y) = 0 && mtx2.(x).(y) = 0 then
- mtx3.(x).(y) <- 0
- else
- mtx3.(x).(y) <- 255
- done
- done;
- mtx3
-
-let labelling mtx w h =
- let mtx2 = Array.make_matrix w h 255 and v = ref 1 in
- for y = 1 to h-1 do
- for x = 1 to w-1 do
- if mtx.(x).(y) = 0 then
- begin
- if mtx2.(x-1).(y-1) <> 255 then
- mtx2.(x).(y) <- mtx2.(x-1).(y-1)
- else if mtx2.(x).(y-1) <> 255 then
- mtx2.(x).(y) <- mtx2.(x).(y-1)
- else if mtx2.(x+1).(y-1) <> 255 then
- mtx2.(x).(y) <- mtx2.(x+1).(y-1)
- else if mtx2.(x+1).(y) <> 255 then
- mtx2.(x).(y) <- mtx2.(x+1).(y)
- else
- begin
- mtx2.(x).(y) <- !v;
- v := !v+1
- end
- end
- else
- mtx2.(x).(y) <- 255
- done
- done;
- (mtx2, !v)
-
-
-type label = {
- mutable value:int;
- mutable firstx:int;
- mutable lastx:int;
- mutable firsty:int;
- mutable lasty:int
-}
-
-type labelise =
- {
- mutable value:int;
- mutable label:int;
- }
-
-(* Ajoute à chaque pixel de mtx une variable label initialisé à -1 *)
-let mtx2labelise mtx w h =
- let lab = Array.make_matrix w h { value = 0; label = -1 } in
- for x = 0 to w-1 do
- for y = 0 to h-1 do
- lab.(x).(y).value <- mtx.(x).(y)
- done
- done;
- lab
-
- (* ne pas utiliser sur les contours d'une matrice / propage le label aux pixelsnon-blancs voisins *)
-let rec propag mtx i j acc =
- if mtx.(i).(j).label = -1 && mtx.(i).(j).value <> 255 then
- begin
- mtx.(i).(j).label <- !acc;
- propag mtx i j-1 acc;
- propag mtx i-1 j acc;
- propag mtx i+1 j acc;
- propag mtx i j+1 acc
- end
-
-(* Détermine pour chaque pixel le numéro de label de son bloc *)
-let path mtx w h =
- let lab = mtx2labelise mtx w h in
- let l = ref 0 in
- for x = 1 to w-2 do
- for y = 1 to h-2 do
- if lab.(x).(y).label = -1 && lab.(x).(y).value <> 255 then
- (
- propag lab x y l;
- l := !l +1
- )
- done
- done;
- lab
-
-(* Calcule le nombre de bloc dans mtx *)
-let max_label mtx w h =
- let maxi = ref(0) in
- for x = 0 to w-1 do
- for y = 0 to h-1 do
- maxi := max (!maxi) (mtx.(x).(y).label)
- done
- done;
- maxi
-
-(* Crée le vecteur contenant tous les blocs de mtx *)
-let lab2label mtx w h =
- let lab = path mtx w h in
- let vect = Array.init ((max_label mtx) -1) (fun i ->
-{ value=i; firstx= w; firsty = h; lastx = 0; lasty = 0}) in
- for x = 1 to w-2 do
- for y = 1 to h-2 do
- let l = lab.(x).(y).label in
- if l <> -1 then
- (
- vect[l].firstx <- min (vect[l].firstx) x
- vect[l].firsty <- min (vect[l].firsty) y
- vect[l].lastx < max (vect[l].lastx) x
- vect[l].lasty <- max (vect[l].lasty) y
- )
- done
- done;
- vect
-
-(*
-let get_line (mtx, n) w h =
- print_int n;
- let mtx2 = Array.make_matrix w h 255
- and vec = Array.make n { k = 0; b = (0, 0); e = (0, 0) }
- and v = ref 0 in
- for y = 0 to h-1 do
- for x = 0 to w-1 do
- v := mtx.(x).(y);
- if !v <> 255 then
- begin
- if vec.(!v).k <> 0 then
- vec.(!v).e <- (x, y)
- else
- vec.(!v) <- { k = !v; b = (x, y); e = (x, y) }
- end
- done
- done;
- let b = ref (0, 0) and e = ref (0, 0) in
- for i = 0 to n-1 do
- b := vec.(i).b;
- e := vec.(i).e;
- for x = (fst !b) to (fst !e) do
- mtx2.(x).(snd !b) <- 0;
- mtx2.(x).(snd !e) <- 0
- done;
- for y = (snd !b) to (snd !e) do
- mtx2.(fst !b).(y) <- 0;
- mtx2.(fst !e).(y) <- 0
- done
- done;
- mtx2
-*)

0 comments on commit b954ab3

Please sign in to comment.