From: Pierre C. <Ba...@us...> - 2012-05-15 01:09:31
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 25db4f2c52fbbb93893caa63239965d6fe4156de (commit) from 08c2505def22aa273c38c7174e02e3b8f2255df8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 25db4f2c52fbbb93893caa63239965d6fe4156de Author: chicco <cha...@cr...> Date: Tue May 15 03:09:07 2012 +0200 [camlcv] add missing tests ----------------------------------------------------------------------- Changes: diff --git a/info/vision/camlcv/test/test_contour_canny.ml b/info/vision/camlcv/test/test_contour_canny.ml new file mode 100644 index 0000000..cb820b4 --- /dev/null +++ b/info/vision/camlcv/test/test_contour_canny.ml @@ -0,0 +1,35 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + let gray = convert_color src bgr2gray in + (* let gray = s in *) + let gray = gaussian_blur ~size:(3,3) gray 2. 2. in + let gray' = convert_color gray gray2bgr in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + let edges' = clone_image edges in + let contours = contours (find_contours ~meth:CV_CHAIN_APPROX_TC89_KCOS edges) in + + List.iter (fun (Contour (c,l)) -> draw_contours ~level:0 gray' c) contours; + + let ellipses = List.map (fun (Contour (c,l)) -> fit_ellipse c) contours in + List.iter (function | None -> () + | Some e -> ellipse' src e) ellipses; + + show_image "canny" edges'; + show_image "gray" gray'; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_detect_ellipse.ml b/info/vision/camlcv/test/test_detect_ellipse.ml new file mode 100644 index 0000000..9ca9478 --- /dev/null +++ b/info/vision/camlcv/test/test_detect_ellipse.ml @@ -0,0 +1,49 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "s" +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "v" + +let smin = create_trackbar ~default:0 ~name:"min" ~window:"s" 256 +let smax = create_trackbar ~default:256 ~name:"max" ~window:"s" 256 + +let vmin = create_trackbar ~default:0 ~name:"min" ~window:"v" 256 +let vmax = create_trackbar ~default:256 ~name:"max" ~window:"v" 256 + +let rec show () = + let src = get_image () in + let src = gaussian_blur src ~size:(3,3) 2. 2. in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + + let v' = between v (* (equalize_hist v) *) (get_var vmin) (get_var vmax) in + let s' = between s (* (equalize_hist s) *) (get_var smin) (get_var smax) in + + let filtered = copy s' (Some v') in + let filtered = erode filtered (5,5) in + let filtered = dilate filtered (5,5) in + + let filtered_src = copy src (Some filtered) in + +(* let final_src = copy src (Some final) in *) + + let contours = contours (find_contours filtered) in + + List.iter (fun (Contour (c,l)) -> draw_contours ~level:0 src c) contours; + + let ellipses = List.map (fun (Contour (c,l)) -> fit_ellipse c) contours in + List.iter (function | None -> () + | Some e -> ellipse' src e) ellipses; + + show_image "s" s'; + show_image "v" v'; + show_image "src" src; + show_image "filtered" filtered_src; +(* show_image "final" final_src; *) + match wait_key 10 with + | Some 'q' -> + Printf.printf "s: %i %i\nv: %i %i\n%!" (get_var smin) (get_var smax) (get_var vmin) (get_var vmax) + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_detect_lines.ml b/info/vision/camlcv/test/test_detect_lines.ml new file mode 100644 index 0000000..698f56d --- /dev/null +++ b/info/vision/camlcv/test/test_detect_lines.ml @@ -0,0 +1,52 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "h" +let hmin = create_trackbar ~default:0 ~name:"hmin" ~window:"h" 255 +let hmax = create_trackbar ~default:76 ~name:"hmax" ~window:"h" 255 + +let pi = 4. *. (atan 1.) + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + (* let gray = convert_color src bgr2gray in *) + let gray = v in + let a = good_features_to_track + gray + 50 + 0.01 + 5. in + let gray = gaussian_blur ~size:(3,3) gray 1. 1. in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + + let h' = between h (get_var hmin) (get_var hmax) in + let dilate_h = erode h' (3,3) in + let edges' = copy edges (Some dilate_h) in + + let lines = + houghLinesP + ~minLineLength:30. + ~maxLineGap:20. + edges' 1. (pi /. 180.) 30 in + + Array.iter (fun (x1,y1,x2,y2) -> line ~color:red src (x1,y1) (x2,y2)) lines; + + draw_points ~color:blue src a; + + show_image "h" h'; + show_image "canny" edges'; + show_image "gray" gray; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_homography.ml b/info/vision/camlcv/test/test_homography.ml new file mode 100644 index 0000000..6bee39d --- /dev/null +++ b/info/vision/camlcv/test/test_homography.ml @@ -0,0 +1,66 @@ +open CvCore +open CvHighGui +open Test_base + +let v_prod (x1,y1) (x2,y2) = x1 *. x2 +. y1 *. y2 + +let i_array a = + Array.mapi (fun i a -> + Array.mapi (fun j v -> v,(i,j)) a) a + +let get_minv v a = + List.hd (List.sort (fun (v1,_) (v2,_) -> + compare (v_prod v v1) (v_prod v v2)) a) + +let x_size = 8. +let y_size = 6. + +let float_c (x,y) = int_of_float x, int_of_float y + +let lower_left (ix,iy) a' = + let a = List.flatten (Array.to_list (Array.map Array.to_list (i_array a'))) in + let ix, iy = float ix, float iy in + let p00 = get_minv (ix,-.iy) a in + let pxy = get_minv (-.ix,iy) a in + let p0y = get_minv (ix,iy) a in + let px0 = get_minv (-.ix,-.iy) a in + p00, px0, p0y, pxy + +let norm v = + match v with + | [|a;b;c|] -> [|a/.c;b/.c;1.|] + | _ -> assert false + +let print_a = Array.iter (Printf.printf " %f") + +let rec show () = + let image = get_image () in + let gray = convert_color image bgr2gray in + let r = find_chessboard_corners gray (6,8) in + (match array_of_chessboard_corners r with + | None -> () + | Some a -> + let (p0,_),(p1,_),(p2,_),(p3,_) = lower_left (image_size image) a in + draw_chessboard_corners image r; + circle image ~color:red (float_c p0) 30; + circle image ~color:green (float_c p1) 30; + circle image ~color:blue (float_c p2) 30; + circle image ~color:yellow (float_c p3) 30; + let homo = find_homography + ~obj_pos:[|0.,0.; + x_size,0.; + 0.,y_size; + x_size,y_size|] + ~img_pos:[|p0;p1;p2;p3|] in + let v1 = norm (mult homo [|0.;0.;1.|]) in + let v2 = norm (mult homo [|3.;3.;1.|]) in + line image ~color:red ~thickness:5 (int_of_float v1.(0),int_of_float v1.(1)) + (int_of_float v2.(0),int_of_float v2.(1)); + Array.iter (fun a -> print_a a; Printf.printf "\n") homo; + Printf.printf "\n%!"); + show_image "out" image; + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () diff --git a/info/vision/camlcv/test/test_houghLines.ml b/info/vision/camlcv/test/test_houghLines.ml new file mode 100644 index 0000000..1ebf008 --- /dev/null +++ b/info/vision/camlcv/test/test_houghLines.ml @@ -0,0 +1,49 @@ +open CvCore +open CvHighGui +open Test_base + +let _ = named_window ~option:CV_WINDOW_AUTOSIZE "canny" +let canny_t1 = create_trackbar ~default:50 ~name:"t1" ~window:"canny" 255 +let canny_t2 = create_trackbar ~default:200 ~name:"t2" ~window:"canny" 255 + +let pi = 4. *. (atan 1.) + +let rec show () = + let src = get_image () in + let hsv = convert_color src bgr2hsv in + let h,s,v = split hsv in + (* let gray = convert_color src bgr2gray in *) + let gray = v in + let gray = gaussian_blur ~size:(3,3) gray 2. 2. in + let edges = canny gray (float (get_var canny_t1)) (float (get_var canny_t2)) in + + let x,y = image_size edges in + let circles = houghCircles gray + ~param1:(float (get_var canny_t1)) + ~param2:(float (get_var canny_t2)) + ~minRadius:0 + ~maxRadius:0 + 1. (float x /. 8.) in + + Array.iter (fun (x1,y1,r) -> + circle src + (int_of_float x1,int_of_float y1) + (int_of_float r)) circles; + + let lines = + houghLinesP + ~minLineLength:50. + ~maxLineGap:20. + edges 1. (pi /. 180.) 50 in + + Array.iter (fun (x1,y1,x2,y2) -> line ~color:red src (x1,y1) (x2,y2)) lines; + + show_image "canny" edges; + show_image "gray" gray; + show_image "src" src; + + match wait_key 10 with + | Some 'q' -> () + | _ -> show () + +let _ = show () hooks/post-receive -- krobot |