Permalink
Browse files

add hough_skew_detection function

  • Loading branch information...
1 parent e4636d0 commit 5b302a89d3ebf5caef8ed980a05986a0b1d3c0ce dezyal committed Oct 17, 2012
Showing with 29 additions and 5 deletions.
  1. +29 −5 OCR/Rotation.ml
View
@@ -1,8 +1,11 @@
(*
- [Fonction de détection d'angle]
+ [Détection d'angle: hough_skew_detection]
Détection de l'inclinaison à l'aide
- de la transformé de Hough
+ de la transformé de Hough.
+ Découpage en 4 fonctions.
*)
+
+(* Remplissage de l'accumulateur *)
let px_vote acc acc_w acc_h x y w h rho_max =
let ox = x-w/2 and oy = y-h/2 in
for i=0 to acc_w do
@@ -12,17 +15,38 @@ let px_vote acc acc_w acc_h x y w h rho_max =
0.5 +. (rho/.rho_max +. 0.5)*.(float)acc_h) in
acc.(i).(i_rho) <- acc.(i).(i_rho) + 1
done
-
+(* Detection de l'intersection des sinusoides *)
+let winner acc w h rho_max=
+ let max = ref(-1) and win_rho = ref(0) and win_theta = ref(0) in
+ for x = 0 to w-1 do
+ for y = 0 to h-1 do
+ let xy_val = acc.(x).(y) in
+ if xy_val > max then
+ max := !xy_val;
+ win_rho := y;
+ win_theta := x;
+ done
+ done;
+ let rho = ((float)!win_rho/.(float)w -. 0.5)*.rho_max in
+ let theta = ((float)!win_theta/.(float)h -. 0.5)*.3.14159265 in
+ (rho,theta)
+(* Conversion d'une droite polaire en cartésien *)
+let rhotheta2ab rho theta w h =
+ let a = -.cos(theta)/.sin(theta) in
+ let b = rho/.sin(theta) +. (float)w/.2. -. a*.(float)w/.2. in
+ (a,b)
+(* Fonction finale *)
let hough_skew_detection mtx w h =
let rho_max = sqrt((float)(w*w +h*h)) in
let theta_w = 360 and rho_h = int_of_float(1.+.rho_max) in
let acc = Array.make_matrix theta_w rho_h 0 in
for x = 0 to w-1 do
for y = 0 to h-1 do
px_vote acc theta_w rho_h x y w h rho_max;
- (* To be continued... *)
done
- done
+ done(*;
+ let (rho,theta) = winner !acc theta_w rho_h rho_max in
+ rhotheta2ab rho theta*)
(*
[Fonction Rotate]

0 comments on commit 5b302a8

Please sign in to comment.