From: Pierre C. <Ba...@us...> - 2012-05-12 17:08:00
|
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 35f2720c1b040772eeefd7d06efd6ad4f3be3220 (commit) via b519178ead26f7d6f931e609886b493adf805696 (commit) from 293b6fc50d49888734dcd618762fe9cafff39bfd (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 35f2720c1b040772eeefd7d06efd6ad4f3be3220 Author: chicco <cha...@cr...> Date: Sat May 12 19:07:04 2012 +0200 [camlcv] more tests, catch errors, fix calibration commit b519178ead26f7d6f931e609886b493adf805696 Author: chicco <cha...@cr...> Date: Thu May 10 17:35:35 2012 +0200 [camlcv] easier to use, have tests ----------------------------------------------------------------------- Changes: diff --git a/info/vision/camlcv/_oasis b/info/vision/camlcv/_oasis index e586f57..b4c3985 100644 --- a/info/vision/camlcv/_oasis +++ b/info/vision/camlcv/_oasis @@ -29,5 +29,55 @@ Library "cv" CvHighGui CSources: cv_caml.c + CCopt: -x c++ -O2 + CClib: -lstdc++ XMETADescription: Core Opencv BuildDepends: bigarray + +Executable "leak" + Path: test/ + MainIs: leak.ml + Install: false + BuildDepends: cv + +Executable "test_drawing" + Path: test/ + MainIs: test_drawing.ml + Install: false + BuildDepends: cv + +Executable "test_good_feature_to_track" + Path: test/ + MainIs: test_good_feature_to_track.ml + Install: false + BuildDepends: cv + +Executable "test_improcess" + Path: test/ + MainIs: test_improcess.ml + Install: false + BuildDepends: cv + +Executable "test_split" + Path: test/ + MainIs: test_split.ml + Install: false + BuildDepends: cv + +Executable "test_threshold" + Path: test/ + MainIs: test_threshold.ml + Install: false + BuildDepends: cv + +Executable "test_find_chessboard_corners" + Path: test/ + MainIs: test_find_chessboard_corners.ml + Install: false + BuildDepends: cv + +Executable "test_calib" + Path: test/ + MainIs: test_calib.ml + Install: false + BuildDepends: cv diff --git a/info/vision/camlcv/_tags b/info/vision/camlcv/_tags index b018bdb..5e875f3 100644 --- a/info/vision/camlcv/_tags +++ b/info/vision/camlcv/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: b8f60d120ef9d7618b2ed02d64b8ef03) +# DO NOT EDIT (digest: c93fc9a48b0322812d7d9f91a98e5b8f) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -15,8 +15,41 @@ "_darcs": not_hygienic # Library cv "src/cv.cmxs": use_cv +<src/*.ml{,i}>: oasis_library_cv_ccopt +"src/cv_caml.c": oasis_library_cv_ccopt +<src/cv.{cma,cmxa}>: oasis_library_cv_cclib +"src/libcv_stubs.lib": oasis_library_cv_cclib +"src/dllcv_stubs.dll": oasis_library_cv_cclib +"src/libcv_stubs.a": oasis_library_cv_cclib +"src/dllcv_stubs.so": oasis_library_cv_cclib <src/cv.{cma,cmxa}>: use_libcv_stubs <src/*.ml{,i}>: pkg_bigarray "src/cv_caml.c": pkg_bigarray +# Executable test_threshold +"test/test_threshold.byte": use_cv +"test/test_threshold.byte": pkg_bigarray +# Executable leak +"test/leak.byte": use_cv +"test/leak.byte": pkg_bigarray +# Executable test_find_chessboard_corners +"test/test_find_chessboard_corners.byte": use_cv +"test/test_find_chessboard_corners.byte": pkg_bigarray +# Executable test_improcess +"test/test_improcess.byte": use_cv +"test/test_improcess.byte": pkg_bigarray +# Executable test_good_feature_to_track +"test/test_good_feature_to_track.byte": use_cv +"test/test_good_feature_to_track.byte": pkg_bigarray +# Executable test_drawing +"test/test_drawing.byte": use_cv +"test/test_drawing.byte": pkg_bigarray +# Executable test_split +"test/test_split.byte": use_cv +"test/test_split.byte": pkg_bigarray +# Executable test_calib +"test/test_calib.byte": use_cv +"test/test_calib.byte": pkg_bigarray +<test/*.ml{,i}>: use_cv +<test/*.ml{,i}>: pkg_bigarray # OASIS_STOP <src/*>: use_C_opencv diff --git a/info/vision/camlcv/myocamlbuild.ml b/info/vision/camlcv/myocamlbuild.ml index ed0acd9..f231df6 100644 --- a/info/vision/camlcv/myocamlbuild.ml +++ b/info/vision/camlcv/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: 4691146961f957a78ce95a45557aba80) *) +(* DO NOT EDIT (digest: 4a00093589bdfb2586c46078313938d7) *) module OASISGettext = struct # 21 "/media/data/ocaml/oasis/src/oasis/OASISGettext.ml" @@ -548,14 +548,33 @@ let package_default = { MyOCamlbuildBase.lib_ocaml = [("cv", ["src"])]; lib_c = [("cv", "src/", [])]; - flags = []; - includes = []; + flags = + [ + (["oasis_library_cv_ccopt"; "compile"], + [ + (OASISExpr.EBool true, + S + [ + A "-ccopt"; + A "-x"; + A "-ccopt"; + A "c++"; + A "-ccopt"; + A "-O2" + ]) + ]); + (["oasis_library_cv_cclib"; "link"], + [(OASISExpr.EBool true, S [A "-cclib"; A "-lstdc++"])]); + (["oasis_library_cv_cclib"; "ocamlmklib"; "c"], + [(OASISExpr.EBool true, S [A "-lstdc++"])]) + ]; + includes = [("test", ["src"])]; } ;; let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; -# 559 "myocamlbuild.ml" +# 578 "myocamlbuild.ml" (* OASIS_STOP *) open Ocamlbuild_plugin diff --git a/info/vision/camlcv/src/cvCore.ml b/info/vision/camlcv/src/cvCore.ml index 155690a..810965f 100644 --- a/info/vision/camlcv/src/cvCore.ml +++ b/info/vision/camlcv/src/cvCore.ml @@ -132,10 +132,89 @@ let rgb2gray = CV_RGB2GRAY let gray2rgb = CV_GRAY2RGB let rgb2rgba = CV_RGB2RGBA +(* zeros are: I don't know *) +let convert_output_channels = function + | CV_BGR2BGRA -> 4 + | CV_RGB2RGBA -> 4 + | CV_BGRA2BGR -> 3 + | CV_RGBA2RGB -> 3 + | CV_BGR2RGBA -> 4 + | CV_RGB2BGRA -> 4 + | CV_RGBA2BGR -> 3 + | CV_BGRA2RGB -> 3 + | CV_BGR2RGB -> 3 + | CV_RGB2BGR -> 3 + | CV_BGRA2RGBA -> 4 + | CV_RGBA2BGRA -> 4 + | CV_BGR2GRAY -> 1 + | CV_RGB2GRAY -> 1 + | CV_GRAY2BGR -> 3 + | CV_GRAY2RGB -> 3 + | CV_GRAY2BGRA -> 4 + | CV_GRAY2RGBA -> 4 + | CV_BGRA2GRAY -> 1 + | CV_RGBA2GRAY -> 1 + | CV_BGR2BGR565 -> 0 + | CV_RGB2BGR565 -> 0 + | CV_BGR5652BGR -> 3 + | CV_BGR5652RGB -> 3 + | CV_BGRA2BGR565 -> 0 + | CV_RGBA2BGR565 -> 0 + | CV_BGR5652BGRA -> 4 + | CV_BGR5652RGBA -> 4 + | CV_GRAY2BGR565 -> 0 + | CV_BGR5652GRAY -> 1 + | CV_BGR2BGR555 -> 0 + | CV_RGB2BGR555 -> 0 + | CV_BGR5552BGR -> 3 + | CV_BGR5552RGB -> 3 + | CV_BGRA2BGR555 -> 0 + | CV_RGBA2BGR555 -> 0 + | CV_BGR5552BGRA -> 4 + | CV_BGR5552RGBA -> 4 + | CV_GRAY2BGR555 -> 0 + | CV_BGR5552GRAY -> 1 + | CV_BGR2XYZ -> 3 + | CV_RGB2XYZ -> 3 + | CV_XYZ2BGR -> 3 + | CV_XYZ2RGB -> 3 + | CV_BGR2YCrCb -> 0 + | CV_RGB2YCrCb -> 0 + | CV_YCrCb2BGR -> 3 + | CV_YCrCb2RGB -> 3 + | CV_BGR2HSV -> 3 + | CV_RGB2HSV -> 3 + | CV_BGR2Lab -> 3 + | CV_RGB2Lab -> 3 + | CV_BayerBG2BGR -> 3 + | CV_BayerGB2BGR -> 3 + | CV_BayerRG2BGR -> 3 + | CV_BayerGR2BGR -> 3 + | CV_BayerBG2RGB -> 3 + | CV_BayerGB2RGB -> 3 + | CV_BayerRG2RGB -> 3 + | CV_BayerGR2RGB -> 3 + | CV_BGR2Luv -> 3 + | CV_RGB2Luv -> 3 + | CV_BGR2HLS -> 3 + | CV_RGB2HLS -> 3 + | CV_HSV2BGR -> 3 + | CV_HSV2RGB -> 3 + | CV_Lab2BGR -> 3 + | CV_Lab2RGB -> 3 + | CV_Luv2BGR -> 3 + | CV_Luv2RGB -> 3 + | CV_HLS2BGR -> 3 + | CV_HLS2RGB -> 3 + + external cvCreateImage : (int*int) -> cvType_ -> int -> ('a,'b) iplImage = "ocaml_cvCreateImage" external cvCvtColor : ('a,'b) iplImage -> ('d,'e) iplImage -> color_conversion_ -> unit = "ocaml_cvCvtColor" -external threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> float -> threshold_type -> unit = "ocaml_cvThreshold" -external adaptive_threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit = "ocaml_cvAdaptiveThreshold_bytecode" "ocaml_cvAdaptiveThreshold" +external threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> float -> float -> threshold_type -> unit = "ocaml_cvThreshold" +external adaptive_threshold' : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit = "ocaml_cvAdaptiveThreshold_bytecode" "ocaml_cvAdaptiveThreshold" + +external canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> + float -> float -> int -> unit = "ocaml_cvCanny" external cvSplit : ('a,'b) iplImage -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> @@ -145,13 +224,8 @@ external cvMerge : ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplIma ([`Channel_1],'b) iplImage option -> ([`Channel_1],'b) iplImage option -> ('a,'b) iplImage -> unit = "ocaml_cvMerge" -let split_3 src c1 c2 c3 = - cvSplit src (Some c1) (Some c2) (Some c3) None - -let merge_3 c1 c2 c3 dst = - cvMerge (Some c1) (Some c2) (Some c3) None dst - external get_cvType : cvType -> cvType_ = "ocaml_get_cvType" +external cvType_int : int -> cvType_ = "%identity" external get_color_conversion : color_conversion -> color_conversion_ = "ocaml_get_color_conversion" external image_size : ('a,'b) iplImage -> (int*int) = "ocaml_image_size" @@ -159,35 +233,50 @@ external image_channels : ('a,'b) iplImage -> int = "ocaml_image_channels" external image_depth : ('a,'b) iplImage -> int = "ocaml_image_depth" external image_data_order : ('a,'b) iplImage -> int = "ocaml_image_data_order" -(* type float_3point = *) -(* { mutable f0 : float; *) -(* mutable f1 : float; *) -(* mutable f2 : float; } *) +let create_image_from ?channels ?depth src = + let size = image_size src in + let type_ = cvType_int (match depth with + | None -> image_depth src + | Some d -> d) in + let channels = match channels with + | None -> image_channels src + | Some c -> c in + cvCreateImage size type_ channels + +let split_3' src c1 c2 c3 = + cvSplit src (Some c1) (Some c2) (Some c3) None -(* type int_3point = *) -(* { mutable i0 : int; *) -(* mutable i1 : int; *) -(* mutable i2 : int; } *) +let split src = + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let c1 = cvCreateImage size type_ 1 in + let c2 = cvCreateImage size type_ 1 in + let c3 = cvCreateImage size type_ 1 in + cvSplit src (Some c1) (Some c2) (Some c3) None; + c1,c2,c3 + +let merge_3' c1 c2 c3 dst = + cvMerge (Some c1) (Some c2) (Some c3) None dst -(* external get_float_3point : *) -(* ([`One],[`F32],[`BGR | `RGB | `HSV ]) iplImage -> *) -(* float_point -> unit *) -(* = "ocaml_get_float_3point" "noalloc" *) +let merge c1 c2 c3 = + let dst = create_image_from ~channels:3 c1 in + cvMerge (Some c1) (Some c2) (Some c3) None dst; + dst -(* external set_float_3point : *) -(* ([`One],[`F32],[`BGR | `RGB | `HSV ]) iplImage -> *) -(* float_point -> unit *) -(* = "ocaml_set_float_3point" "noalloc" *) +let threshold src threshold maxValue thresholdType = + let dst = create_image_from src in + threshold' src dst threshold maxValue thresholdType; + dst -(* external unsafe_get_int_3point : *) -(* ([`One],[`U8],[<`BGR | `RGB | `HSV ]) iplImage -> *) -(* int -> int_3point -> unit *) -(* = "ocaml_get_int_3point" "noalloc" *) +let adaptive_threshold src maxValue adaptiveMethod thresholdType blockSize param1 = + let dst = create_image_from src in + adaptive_threshold' src dst maxValue adaptiveMethod thresholdType blockSize param1; + dst -(* external unsafe_set_int_3point : *) -(* ([`One],[`U8],[<`BGR | `RGB | `HSV ]) iplImage -> *) -(* int -> int_3point -> unit *) -(* = "ocaml_set_int_3point" "noalloc" *) +let canny src ?(apertureSize=3) th1 th2 = + let dst = create_image_from src in + canny' src dst th1 th2 apertureSize; + dst type image_data = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array2.t @@ -198,9 +287,18 @@ external zero_image : ('a,'b) iplImage -> unit = "ocaml_cvZero" external clone_image : ('a,'b) iplImage -> ('a,'b) iplImage = "ocaml_cvCloneImage" let create_image ~x ~y _type i = cvCreateImage (x,y) (get_cvType _type) i -let convert_color ~src ~dst color_conversion = + +let convert_color' ~src ~dst color_conversion = cvCvtColor src dst (get_color_conversion color_conversion) +let convert_color src color_conversion = + let channels = convert_output_channels color_conversion in + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let dst = cvCreateImage size type_ channels in + cvCvtColor src dst (get_color_conversion color_conversion); + dst + type cvScalar = float * float * float * float type cvPoint = int * int type cvPoint2D32f = float * float @@ -213,6 +311,14 @@ type cvTermCriteria = termcrit_epsilon : bool; max_iter : int; epsilon : float; } +type vec3f = float * float * float + +type vec3f_vect + +external create_vec3f_vect : unit -> vec3f_vect = "ocaml_create_Vec3f_vector" +external vec3f_vect_size : vec3f_vect -> int = "ocaml_vector_size_Vec3f" +external vec3f_vect_add : vec3f_vect -> vec3f -> unit = "ocaml_vector_add_Vec3f" +external vec3f_vect_get : vec3f_vect -> int -> vec3f = "ocaml_vector_get_Vec3f" external cvCircle : ('a,[`U8]) iplImage -> cvPoint -> int -> cvScalar -> int -> unit = "ocaml_cvCircle" external cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> @@ -221,6 +327,50 @@ external cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> external cvRectangle : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit = "ocaml_cvRectangle" external cvLine : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit = "ocaml_cvLine" +type color = int * int * int + +let red = 255, 0, 0 +let green = 0, 255, 0 +let blue = 0, 0, 255 +let yellow = 255, 255, 0 +let magenta = 255, 0, 255 +let black = 0, 0, 0 +let white = 255, 255, 255 + +let scalar_color (r,g,b) = (float b, float g, float r, 0.) + +let circle dst ?(thickness=1) ?(color=blue) center radius = + cvCircle dst center radius (scalar_color color) thickness + +let ellipse dst ?(thickness=1) ?(color=blue) ?(angle=0.) ?(start_angle=0.) ?(end_angle=360.) + center size = + cvEllipse dst center size angle start_angle end_angle (scalar_color color) thickness + +type ellipse = { + ellipse_center : float * float; + ellipse_size : float * float; + ellipse_angle : float; +} + +let ellipse' dst ?thickness ?color ?start_angle ?end_angle + { + ellipse_center = x,y; + ellipse_size = w,h; + ellipse_angle = angle; + } = + ellipse dst ?thickness ?color ?start_angle ?end_angle + (int_of_float x, int_of_float y) + (int_of_float w, int_of_float h) + +let rectangle dst ?(thickness=1) ?(color=blue) p1 p2 = + cvRectangle dst p1 p2 (scalar_color color) thickness + +let line dst ?(thickness=1) ?(color=blue) p1 p2 = + cvLine dst p1 p2 (scalar_color color) thickness + +let draw_points ?(color=red) ?(size=2) i a = + Array.iter (fun (x,y) -> circle i ~color (int_of_float x,int_of_float y) size) a + (* memory handling *) type cvMemStorage @@ -291,12 +441,6 @@ external cvDrawContours : ('a,[`U8]) iplImage -> cvSeq -> cvScalar -> cvScalar - let draw_contours image seq in_color out_color level thickness offset = cvDrawContours image seq.seq in_color out_color level thickness offset -type ellipse = { - ellipse_center : float * float; - ellipse_size : float * float; - ellipse_angle : float; -} - external cvFitEllipse2 : cvSeq -> (float * float * float * float * float) option = "ocaml_cvFitEllipse2" let fit_ellipse seq = @@ -307,6 +451,37 @@ let fit_ellipse seq = ellipse_size = width,height; ellipse_angle = angle } +external cvGoodFeaturesToTrack : + ([`Channel_1],'b) iplImage -> + (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array2.t -> + float -> float -> + ([`Channel_1],[`U8]) iplImage option -> + int -> + bool -> + float -> + int + = "ocaml_cvGoodFeaturesToTrack_bytecode" "ocaml_cvGoodFeaturesToTrack" + +let good_features_to_track image ?mask ?(blockSize=3) ?(useHarris=false) ?(k=0.04) + maxCorners qualityLevel minDistance = + let ba = Bigarray.Array2.create Bigarray.float32 Bigarray.c_layout maxCorners 2 in + let count = cvGoodFeaturesToTrack image ba + qualityLevel minDistance + mask blockSize useHarris k in + Array.init count (fun i -> ba.{i,0}, ba.{i,1}) + +external houghCircles' : + ('a,[`U8]) iplImage -> + vec3f_vect -> + float -> float -> float -> float -> + int -> int -> unit + = "ocaml_HoughCircles_bytecode" "ocaml_HoughCircles" + +let houghCircles img ?(param1=100.) ?(param2=100.) ?(minRadius=0) ?(maxRadius=0) dp minDist = + let vec = create_vec3f_vect () in + houghCircles' img vec dp minDist param1 param2 minRadius maxRadius; + Array.init (vec3f_vect_size vec) (fun i -> vec3f_vect_get vec i) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -362,14 +537,17 @@ let find_corner_subpix ?(criteria=default_criteria) ?(winSize=11,11) ?(zeroZone= cvFindCornerSubPix i ba count (11,11) (-1,-1) criteria; end - (** camera calibration *) type ('channel) cvMat_float32 = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array3.t +type ('channel) cvMat_float64 = + (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array3.t + type ('channel) cvMat_int = - (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Array3.t + (int32, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array3.t +(* there is no 64 bit type in CvMat... so stick to int32 *) external cvCalibrateCamera2 : [`Channel_3] cvMat_float32 -> [`Channel_2] cvMat_float32 -> [`Channel_1] cvMat_int -> cvSize -> [`Channel_1] cvMat_float32 -> @@ -381,8 +559,8 @@ type calibration = cvSize * float * cvSize option * ((float*float) array array*( let init_calibration cb_size square_size : calibration = (cb_size, square_size, None, []) let corner_positions (x,y) square_size = - Array.init x - (fun i -> Array.init y + Array.init y + (fun i -> Array.init x (fun j -> (float j) *. square_size, (float i) *. square_size, 0.)) let add_calibration_image ((cb_size, square_size, i_size, state):calibration) image : calibration = @@ -420,8 +598,8 @@ let calibrate (cal:calibration) = let img_pos = Bigarray.reshape_3 (Bigarray.genarray_of_array3 img_pos) ((List.length state) * points) 1 2 in - let point_count = Array.create (List.length state) points in - let point_count = Bigarray.Array1.of_array Bigarray.int Bigarray.c_layout point_count in + let point_count = Array.map Int32.of_int (Array.create (List.length state) points) in + let point_count = Bigarray.Array1.of_array Bigarray.int32 Bigarray.c_layout point_count in let point_count = Bigarray.reshape_3 (Bigarray.genarray_of_array1 point_count) (List.length state) 1 1 in @@ -442,7 +620,9 @@ external cvInitUndistortMap : ([`Channel_1],[`F32]) iplImage -> ([`Channel_1],[`F32]) iplImage -> unit - = "cvInitUndistortMap" + = "ocaml_cvInitUndistortMap" + +type remap = ([ `Channel_1 ], [ `F32 ]) iplImage * ([ `Channel_1 ], [ `F32 ]) iplImage let init_undistort_map (x,y) (mat,v) = let mat = Bigarray.Array3.of_array Bigarray.float32 Bigarray.c_layout @@ -459,4 +639,22 @@ external cvRemap : ([`Channel_1],[`F32]) iplImage -> ([`Channel_1],[`F32]) iplImage -> unit - = "cvRemap" + = "ocaml_cvRemap" + +let remap' ((mapx,mapy):remap) src dst = + cvRemap src dst mapx mapy + +let remap ((mapx,mapy):remap) src = + let size = image_size src in + let type_ = cvType_int (image_depth src) in + let channels = image_channels src in + let dst = cvCreateImage size type_ channels in + cvRemap src dst mapx mapy; + dst + +external cvFindHomography : + [`Channel_2] cvMat_float64 -> + [`Channel_2] cvMat_float64 -> + [`Channel_1] cvMat_float64 -> + unit + = "ocaml_cvFindHomography" diff --git a/info/vision/camlcv/src/cvCore.mli b/info/vision/camlcv/src/cvCore.mli index 658edc5..3aa6239 100644 --- a/info/vision/camlcv/src/cvCore.mli +++ b/info/vision/camlcv/src/cvCore.mli @@ -11,6 +11,7 @@ type cvTermCriteria = termcrit_epsilon : bool; max_iter : int; epsilon : float; } +type vec3f = float * float * float type ('chan_num,'depth) iplImage @@ -54,18 +55,29 @@ val rgb2gray : ([`Channel_3],[`Channel_1]) conversion val gray2rgb : ([`Channel_1],[`Channel_3]) conversion val rgb2rgba : ([`Channel_3],[`Channel_4]) conversion -val convert_color : +val convert_color' : src:('c_src,'b) iplImage -> dst:('c_dst,'b) iplImage -> ('c_src,'c_dst) conversion -> unit -val split_3 : ([`Channel_3],'b) iplImage -> ([`Channel_1],'b) iplImage -> +val convert_color : + ('c_src,'b) iplImage -> + ('c_src,'c_dst) conversion -> + ('c_dst,'b) iplImage + +val split_3' : ([`Channel_3],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> unit -val merge_3 : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> +val split : ([`Channel_3],'b) iplImage -> + ([`Channel_1],'b) iplImage * ([`Channel_1],'b) iplImage * ([`Channel_1],'b) iplImage + +val merge_3' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> ([`Channel_3],'b) iplImage -> unit +val merge : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + ([`Channel_1],'b) iplImage -> ([`Channel_3],'b) iplImage + (** threshold *) type threshold_type = @@ -81,17 +93,79 @@ type adaptive_method = | CV_ADAPTIVE_THRESH_MEAN_C | CV_ADAPTIVE_THRESH_GAUSSIAN_C -val threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> float -> threshold_type -> unit -(** [threshold src dst threshold maxValue thresholdType] *) -val adaptive_threshold : ('a,'b) iplImage -> ('d,'e) iplImage -> float -> adaptive_method -> threshold_type -> int -> float -> unit -(** [adaptive_threshold src dst maxValue adaptiveMethod thresholdType blockSize param1] *) +val threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + float -> float -> threshold_type -> unit +(** [threshold' src dst threshold maxValue thresholdType] *) + +val threshold : ([`Channel_1],'b) iplImage -> float -> float -> threshold_type -> + ([`Channel_1],'b) iplImage +(** [threshold src threshold maxValue thresholdType] *) + +val adaptive_threshold' : ([`Channel_1],'b) iplImage -> ([`Channel_1],'b) iplImage -> + float -> adaptive_method -> threshold_type -> int -> float -> unit +(** [adaptive_threshold' src dst maxValue adaptiveMethod thresholdType blockSize param1] *) + +val adaptive_threshold : ([`Channel_1],'b) iplImage -> + float -> adaptive_method -> threshold_type -> int -> float -> ([`Channel_1],'b) iplImage +(** [adaptive_threshold src maxValue adaptiveMethod thresholdType blockSize param1] *) + +(** edge detection *) + +val canny' : ([`Channel_1],[`U8]) iplImage -> ([`Channel_1],[`U8]) iplImage -> + float -> float -> int -> unit +val canny : ([ `Channel_1 ], [ `U8 ]) iplImage -> + ?apertureSize:int -> + float -> float -> ([ `Channel_1 ], [ `U8 ]) iplImage +(** [canny src threshold1 threshold2] *) (** drawing *) -val cvCircle : ('a,[`U8]) iplImage -> cvPoint -> int -> cvScalar -> int -> unit -val cvEllipse : ('a,[`U8]) iplImage -> cvPoint -> cvSize -> float -> float -> float -> cvScalar -> int -> unit -val cvRectangle : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit -val cvLine : ('a,[`U8]) iplImage -> cvPoint -> cvPoint -> cvScalar -> int -> unit +type color = int * int * int (** red, green, blue *) + +val red : color +val green : color +val blue : color +val yellow : color +val magenta : color +val black : color +val white : color + +val circle : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> int -> unit + +type ellipse = { + ellipse_center : float * float; + ellipse_size : float * float; + ellipse_angle : float; +} + +val ellipse : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> + ?color:color -> + ?angle:float -> + ?start_angle:float -> ?end_angle:float -> cvPoint -> cvSize -> unit + +val ellipse' : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> + ?color:color -> + ?start_angle:float -> ?end_angle:float -> + ellipse -> unit + +val rectangle : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> cvPoint -> unit + +val line : ('a, [ `U8 ]) iplImage -> + ?thickness:int -> ?color:color -> + cvPoint -> cvPoint -> unit + +val draw_points : + ?color:color -> + ?size:int -> + ('a, [ `U8 ]) iplImage -> + cvPoint2D32f array -> unit + (**/**) val image_data_order : ('a,'b) iplImage -> int @@ -129,14 +203,24 @@ val find_contours : ?mode:contour_retrieval_mode -> ?meth:contour_approximation_ val draw_contours : ('a,[`U8]) iplImage -> seq -> cvScalar -> cvScalar -> int -> int -> cvPoint -> unit -type ellipse = { - ellipse_center : float * float; - ellipse_size : float * float; - ellipse_angle : float; -} - val fit_ellipse : seq -> ellipse option +val good_features_to_track : + ([ `Channel_1 ], 'a) iplImage -> + ?mask:([ `Channel_1 ], [ `U8 ]) iplImage -> + ?blockSize:int -> + ?useHarris:bool -> + ?k:float -> int -> float -> float -> cvPoint2D32f array +(** [good_features_to_track image ?mask ?(blockSize=3) ?(useHarris=false) ?(k=0.04) + maxCorners qualityLevel minDistance] *) + + val houghCircles : + ('a, [ `U8 ]) iplImage -> + ?param1:float -> + ?param2:float -> + ?minRadius:int -> ?maxRadius:int -> float -> float -> vec3f array +(** [houghCircles img dp minDist] *) + type calib_cb = | CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE @@ -165,12 +249,21 @@ val add_calibration_image : calibration -> ([ `Channel_1 ], [ `U8 ]) iplImage -> calibration val calibrate : calibration -> float * ( float array array * float array ) -val init_undistort_map : cvSize -> ( float array array * float array ) -> - ([ `Channel_1 ], [ `F32 ]) iplImage * ([ `Channel_1 ], [ `F32 ]) iplImage +type remap + +val init_undistort_map : cvSize -> ( float array array * float array ) -> remap +val remap' : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage -> unit +val remap : remap -> ('a, 'b) iplImage -> ('a, 'b) iplImage + +type ('channel) cvMat_float32 = + (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array3.t + +type ('channel) cvMat_float64 = + (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array3.t -external cvRemap : - ('a,'b) iplImage -> ('a,'b) iplImage -> - ([`Channel_1],[`F32]) iplImage -> - ([`Channel_1],[`F32]) iplImage -> +external cvFindHomography : + [`Channel_2] cvMat_float64 -> + [`Channel_2] cvMat_float64 -> + [`Channel_1] cvMat_float64 -> unit - = "cvRemap" + = "ocaml_cvFindHomography" diff --git a/info/vision/camlcv/src/cvHighGui.ml b/info/vision/camlcv/src/cvHighGui.ml index bc5ada3..e10f58f 100644 --- a/info/vision/camlcv/src/cvHighGui.ml +++ b/info/vision/camlcv/src/cvHighGui.ml @@ -40,14 +40,109 @@ let named_window ?(option=CV_WINDOW_DEFAULT) name = | CV_WINDOW_AUTOSIZE -> 1 in cvNamedWindow name opt -external wait_key : int -> char = "ocaml_cvWaitKey" +external destroy_window : string -> unit = "ocaml_cvDestroyWindow" +external destroy_all_windows : unit -> unit = "ocaml_cvDestroyAllWindows" + +external wait_key' : int -> int = "ocaml_cvWaitKey" + +let wait_key i = + let c = wait_key' i in + if c > 0 + then Some (Char.chr (c land 255)) + else None + external show_image : string -> ('a,'b) iplImage -> unit = "ocaml_cvShowImage" type int_var external create_int_var : int -> int_var = "ocaml_create_int_var" -external get_int_var : int_var -> int = "ocaml_get_int_var" -external set_int_var : int_var -> int -> unit = "ocaml_set_int_var" +external get_var : int_var -> int = "ocaml_get_int_var" +external set_var : int_var -> int -> unit = "ocaml_set_int_var" external cvCreateTrackbar : string -> string -> int_var -> int -> int = "ocaml_cvCreateTrackbar" -let create_trackbar ~name ~window var max = ignore (cvCreateTrackbar name window var max) +let create_trackbar ?default ~name ~window max = + let default = match default with + | None -> max / 2 + | Some d -> d in + let var = create_int_var default in + ignore (cvCreateTrackbar name window var max); + var + +type cap_prop = + | CV_CAP_PROP_DC1394_OFF + | CV_CAP_PROP_DC1394_MODE_MANUAL + | CV_CAP_PROP_DC1394_MODE_AUTO + | CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO + | CV_CAP_PROP_POS_MSEC + | CV_CAP_PROP_POS_FRAMES + | CV_CAP_PROP_POS_AVI_RATIO + | CV_CAP_PROP_FRAME_WIDTH + | CV_CAP_PROP_FRAME_HEIGHT + | CV_CAP_PROP_FPS + | CV_CAP_PROP_FOURCC + | CV_CAP_PROP_FRAME_COUNT + | CV_CAP_PROP_FORMAT + | CV_CAP_PROP_MODE + | CV_CAP_PROP_BRIGHTNESS + | CV_CAP_PROP_CONTRAST + | CV_CAP_PROP_SATURATION + | CV_CAP_PROP_HUE + | CV_CAP_PROP_GAIN + | CV_CAP_PROP_EXPOSURE + | CV_CAP_PROP_CONVERT_RGB + | CV_CAP_PROP_WHITE_BALANCE_BLUE_U + | CV_CAP_PROP_RECTIFICATION + | CV_CAP_PROP_MONOCROME + | CV_CAP_PROP_SHARPNESS + | CV_CAP_PROP_AUTO_EXPOSURE + | CV_CAP_PROP_GAMMA + | CV_CAP_PROP_TEMPERATURE + | CV_CAP_PROP_TRIGGER + | CV_CAP_PROP_TRIGGER_DELAY + | CV_CAP_PROP_WHITE_BALANCE_RED_V + | CV_CAP_PROP_MAX_DC1394 + | CV_CAP_PROP_AUTOGRAB + | CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + | CV_CAP_PROP_PREVIEW_FORMAT + | CV_CAP_OPENNI_DEPTH_GENERATOR + | CV_CAP_OPENNI_IMAGE_GENERATOR + | CV_CAP_OPENNI_GENERATORS_MASK + | CV_CAP_PROP_OPENNI_OUTPUT_MODE + | CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH + | CV_CAP_PROP_OPENNI_BASELINE + | CV_CAP_PROP_OPENNI_FOCAL_LENGTH + | CV_CAP_PROP_OPENNI_REGISTRATION_ON + | CV_CAP_PROP_OPENNI_REGISTRATION + | CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE + | CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE + | CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH + | CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON + | CV_CAP_GSTREAMER_QUEUE_LENGTH + | CV_CAP_PROP_PVAPI_MULTICASTIP + | CV_CAP_PROP_XI_DOWNSAMPLING + | CV_CAP_PROP_XI_DATA_FORMAT + | CV_CAP_PROP_XI_OFFSET_X + | CV_CAP_PROP_XI_OFFSET_Y + | CV_CAP_PROP_XI_TRG_SOURCE + | CV_CAP_PROP_XI_TRG_SOFTWARE + | CV_CAP_PROP_XI_GPI_SELECTOR + | CV_CAP_PROP_XI_GPI_MODE + | CV_CAP_PROP_XI_GPI_LEVEL + | CV_CAP_PROP_XI_GPO_SELECTOR + | CV_CAP_PROP_XI_GPO_MODE + | CV_CAP_PROP_XI_LED_SELECTOR + | CV_CAP_PROP_XI_LED_MODE + | CV_CAP_PROP_XI_MANUAL_WB + | CV_CAP_PROP_XI_AUTO_WB + | CV_CAP_PROP_XI_AEAG + | CV_CAP_PROP_XI_EXP_PRIORITY + | CV_CAP_PROP_XI_AE_MAX_LIMIT + | CV_CAP_PROP_XI_AG_MAX_LIMIT + | CV_CAP_PROP_XI_AEAG_LEVEL + | CV_CAP_PROP_XI_TIMEOUT + +external set_capture_property : cvCapture -> cap_prop -> float -> unit = + "ocaml_cvSetCaptureProperty" + +external get_capture_property : cvCapture -> cap_prop -> float = + "ocaml_cvGetCaptureProperty" diff --git a/info/vision/camlcv/src/cvHighGui.mli b/info/vision/camlcv/src/cvHighGui.mli index 8e93588..6e54b60 100644 --- a/info/vision/camlcv/src/cvHighGui.mli +++ b/info/vision/camlcv/src/cvHighGui.mli @@ -16,6 +16,82 @@ type cvCapture val capture_from_cam : int -> cvCapture val query_frame : cvCapture -> ([`Channel_3],[`U8]) iplImage +type cap_prop = + | CV_CAP_PROP_DC1394_OFF + | CV_CAP_PROP_DC1394_MODE_MANUAL + | CV_CAP_PROP_DC1394_MODE_AUTO + | CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO + | CV_CAP_PROP_POS_MSEC + | CV_CAP_PROP_POS_FRAMES + | CV_CAP_PROP_POS_AVI_RATIO + | CV_CAP_PROP_FRAME_WIDTH + | CV_CAP_PROP_FRAME_HEIGHT + | CV_CAP_PROP_FPS + | CV_CAP_PROP_FOURCC + | CV_CAP_PROP_FRAME_COUNT + | CV_CAP_PROP_FORMAT + | CV_CAP_PROP_MODE + | CV_CAP_PROP_BRIGHTNESS + | CV_CAP_PROP_CONTRAST + | CV_CAP_PROP_SATURATION + | CV_CAP_PROP_HUE + | CV_CAP_PROP_GAIN + | CV_CAP_PROP_EXPOSURE + | CV_CAP_PROP_CONVERT_RGB + | CV_CAP_PROP_WHITE_BALANCE_BLUE_U + | CV_CAP_PROP_RECTIFICATION + | CV_CAP_PROP_MONOCROME + | CV_CAP_PROP_SHARPNESS + | CV_CAP_PROP_AUTO_EXPOSURE + | CV_CAP_PROP_GAMMA + | CV_CAP_PROP_TEMPERATURE + | CV_CAP_PROP_TRIGGER + | CV_CAP_PROP_TRIGGER_DELAY + | CV_CAP_PROP_WHITE_BALANCE_RED_V + | CV_CAP_PROP_MAX_DC1394 + | CV_CAP_PROP_AUTOGRAB + | CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + | CV_CAP_PROP_PREVIEW_FORMAT + | CV_CAP_OPENNI_DEPTH_GENERATOR + | CV_CAP_OPENNI_IMAGE_GENERATOR + | CV_CAP_OPENNI_GENERATORS_MASK + | CV_CAP_PROP_OPENNI_OUTPUT_MODE + | CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH + | CV_CAP_PROP_OPENNI_BASELINE + | CV_CAP_PROP_OPENNI_FOCAL_LENGTH + | CV_CAP_PROP_OPENNI_REGISTRATION_ON + | CV_CAP_PROP_OPENNI_REGISTRATION + | CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE + | CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE + | CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH + | CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON + | CV_CAP_GSTREAMER_QUEUE_LENGTH + | CV_CAP_PROP_PVAPI_MULTICASTIP + | CV_CAP_PROP_XI_DOWNSAMPLING + | CV_CAP_PROP_XI_DATA_FORMAT + | CV_CAP_PROP_XI_OFFSET_X + | CV_CAP_PROP_XI_OFFSET_Y + | CV_CAP_PROP_XI_TRG_SOURCE + | CV_CAP_PROP_XI_TRG_SOFTWARE + | CV_CAP_PROP_XI_GPI_SELECTOR + | CV_CAP_PROP_XI_GPI_MODE + | CV_CAP_PROP_XI_GPI_LEVEL + | CV_CAP_PROP_XI_GPO_SELECTOR + | CV_CAP_PROP_XI_GPO_MODE + | CV_CAP_PROP_XI_LED_SELECTOR + | CV_CAP_PROP_XI_LED_MODE + | CV_CAP_PROP_XI_MANUAL_WB + | CV_CAP_PROP_XI_AUTO_WB + | CV_CAP_PROP_XI_AEAG + | CV_CAP_PROP_XI_EXP_PRIORITY + | CV_CAP_PROP_XI_AE_MAX_LIMIT + | CV_CAP_PROP_XI_AG_MAX_LIMIT + | CV_CAP_PROP_XI_AEAG_LEVEL + | CV_CAP_PROP_XI_TIMEOUT + +val set_capture_property : cvCapture -> cap_prop -> float -> unit +val get_capture_property : cvCapture -> cap_prop -> float + (** Gui interface *) type window_option = @@ -25,10 +101,14 @@ type window_option = val named_window : ?option:window_option -> string -> unit (** [named_window name] create a window named [name] *) +val destroy_window : string -> unit +val destroy_all_windows : unit -> unit + val show_image : string -> ('a,'b) iplImage -> unit (** [show_image window image] display the image [image] in the window [window] *) -val wait_key : int -> char +val wait_key' : int -> int +val wait_key : int -> char option (** [wait_key time] wait for [time] milliseconds for an event to occur. If [time < 0] it waits indefinitely. Nothing happens in the gui until this function is called. *) @@ -36,6 +116,6 @@ val wait_key : int -> char type int_var val create_int_var : int -> int_var -val get_int_var : int_var -> int -val set_int_var : int_var -> int -> unit -val create_trackbar : name:string -> window:string -> int_var -> int -> unit +val get_var : int_var -> int +val set_var : int_var -> int -> unit +val create_trackbar : ?default:int -> name:string -> window:string -> int -> int_var diff --git a/info/vision/camlcv/src/cv_caml.c b/info/vision/camlcv/src/cv_caml.c index 42cb9cd..a49aaf1 100644 --- a/info/vision/camlcv/src/cv_caml.c +++ b/info/vision/camlcv/src/cv_caml.c @@ -1,3 +1,4 @@ +extern "C" { #include <caml/alloc.h> #include <caml/fail.h> #include <caml/mlvalues.h> @@ -6,6 +7,7 @@ #include <caml/custom.h> #include <caml/bigarray.h> #include <caml/callback.h> +} #include <assert.h> #include <stdio.h> @@ -21,6 +23,267 @@ #undef uint64 #undef schar +using namespace cv; + +#define ERRWRAP(expr) \ +try \ +{ \ + expr; \ +} \ +catch (const cv::Exception &e) \ +{ \ + caml_failwith(e.what()); \ +} + +static Vec3f Vec3f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (Vec3f(v0,v1,v2)); +} + +static value Val_Vec3f(Vec3f v) { + CAMLparam0(); + CAMLlocal1(res); + res = caml_alloc_tuple(3); + for(int i = 0; i < 3; i++) { + Field(res,i) = caml_copy_double(v[i]); + } + CAMLreturn(res); +} + +/* c++ vector */ + +template <typename Type> +vector<Type>* Vector_val(value v) +{ + return *(vector<Type>**) Data_custom_val(v); +} + +extern "C" void caml_finalize_vector(value vec) +{ + //it is the same finalizer for all types... problems ? + vector<void*>* del = Vector_val<void*>(vec); + delete del; + return; +} + +static struct custom_operations vector_operations = { + (char*) "ocaml_vector", + caml_finalize_vector, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; +template <typename Type> +value ocaml_create_vector(value v) +{ + CAMLparam1(v); + CAMLlocal1(res); + res = caml_alloc_custom(&vector_operations, sizeof(vector<Type>*), 1, 10); + *(vector<Type>**) Data_custom_val(res) = new vector<Type>(); + CAMLreturn(res); +} + +template <typename Type> +value ocaml_vector_size(value v) +{ + CAMLparam1(v); + vector<Type>* vec = Vector_val<Type>(v); + CAMLreturn(Val_int(vec->size())); +} + +template <typename Type> +value ocaml_vector_add(value v, value vx, Type x) +{ + CAMLparam2(v,vx); + Vector_val<Type>(v)->push_back(x); + CAMLreturn(Val_unit); +} + +template <typename Type> +Type ocaml_vector_get(value v, value x) +{ + vector<Type>* vec = Vector_val<Type>(v); + Type ret; + try { + ret = vec->at(Int_val(x)); + } + catch (const std::exception &e) { + caml_failwith(e.what()); + }; + return(ret); +} + +extern "C" CAMLprim value ocaml_create_int_vector(value v) +{ + return(ocaml_create_vector<int>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_int(value v) +{ + return(ocaml_vector_size<int>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_int(value v, value x) +{ + return(ocaml_vector_add<int>(v,x,Int_val(x))); +} + +extern "C" CAMLprim value ocaml_vector_get_int(value v, value x) +{ + CAMLparam2(v,x); + CAMLreturn(Val_int(ocaml_vector_get<int>(v,x))); +} + +extern "C" CAMLprim value ocaml_create_Vec3f_vector(value v) +{ + return(ocaml_create_vector<Vec3f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_size_Vec3f(value v) +{ + return(ocaml_vector_size<Vec3f>(v)); +} + +extern "C" CAMLprim value ocaml_vector_add_Vec3f(value v, value x) +{ + return(ocaml_vector_add<Vec3f>(v,x,Vec3f_val(x))); +} +extern "C" CAMLprim value ocaml_vector_get_Vec3f(value v, value x) +{ + CAMLparam2(v,x); + Vec3f r = ocaml_vector_get<Vec3f>(v,x); + CAMLreturn(Val_Vec3f(r)); +} + +/* basic caml value conversions */ + +static CvScalar CvScalar_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + double v3 = Double_val(Field(v,3)); + return (cvScalar(v0,v1,v2,v3)); +} + +static CvPoint CvPoint_val(value v) { + int v0 = Int_val(Field(v,0)); + int v1 = Int_val(Field(v,1)); + return (cvPoint(v0,v1)); +} + +/* unused +static CvPoint2D32f CvPoint2D32f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + return (cvPoint2D32f(v0,v1)); +} + +static CvPoint3D32f CvPoint3D32f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (cvPoint3D32f(v0,v1,v2)); +} + +static CvPoint2D64f CvPoint2D64f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + return (cvPoint2D64f(v0,v1)); +} + +static CvPoint3D64f CvPoint3D64f_val(value v) { + double v0 = Double_val(Field(v,0)); + double v1 = Double_val(Field(v,1)); + double v2 = Double_val(Field(v,2)); + return (cvPoint3D64f(v0,v1,v2)); +} +*/ + +static CvSize CvSize_val(value v) { + int v0 = Int_val(Field(v,0)); + int v1 = Int_val(Field(v,1)); + return (cvSize(v0,v1)); +} + +static CvTermCriteria CvTermCriteria_val(value v) { + int tc_iter = Int_val(Field(v,0)); + int tc_eps = Int_val(Field(v,1)); + int type = 0; + if (tc_iter) type |= CV_TERMCRIT_ITER; + if (tc_eps) type |= CV_TERMCRIT_EPS; + int max_iter = Int_val(Field(v,2)); + double epsilon = Double_val(Field(v,3)); + return (cvTermCriteria(type,max_iter,epsilon)); +} + +static CvMat CvMat_val(value v) { + void* data = Data_bigarray_val(v); + int rows = Bigarray_val(v)->dim[0]; + int cols = Bigarray_val(v)->dim[1]; + int channels = Bigarray_val(v)->dim[2]; + int kind = Bigarray_val(v)->flags & BIGARRAY_KIND_MASK; + int type = 0; + switch (kind) { + + case BIGARRAY_FLOAT32: + switch (channels) { + case 1: + type = CV_32FC1; + break; + case 2: + type = CV_32FC2; + break; + case 3: + type = CV_32FC3; + break; + default: + break; + } + break; + + case BIGARRAY_FLOAT64: + switch (channels) { + case 1: + type = CV_64FC1; + break; + case 2: + type = CV_64FC2; + break; + case 3: + type = CV_64FC3; + break; + default: + break; + } + break; + + case BIGARRAY_INT32: + switch (channels) { + case 1: + type = CV_32SC1; + break; + case 2: + type = CV_32SC2; + break; + case 3: + type = CV_32SC3; + break; + default: + break; + } + break; + + default: + break; + } + if(type == 0) caml_failwith("CvMat_val case not handled"); + + return (cvMat(rows, cols, type, data)); +} + int cvType_table[] = { IPL_DEPTH_1U, IPL_DEPTH_8U, @@ -31,7 +294,7 @@ int cvType_table[] = { IPL_DEPTH_32S }; -int ocaml_get_cvType(int vtype) +extern "C" CAMLprim value ocaml_get_cvType(value vtype) { return (Val_int(cvType_table[Int_val(vtype)])); } @@ -44,7 +307,7 @@ int iscolor_table[] = { CV_LOAD_IMAGE_ANYCOLOR }; -int ocaml_get_iscolor(int iscolor) +extern "C" CAMLprim value ocaml_get_iscolor(value iscolor) { return (Val_int(iscolor_table[Int_val(iscolor)])); } @@ -61,7 +324,7 @@ void caml_finalize_CvMemStorage(value vstor) } static struct custom_operations CvMemStorage_operations = { - "ocaml_opencv_CvMemStorage", + (char*) "ocaml_opencv_CvMemStorage", caml_finalize_CvMemStorage, custom_compare_default, custom_hash_default, @@ -69,7 +332,7 @@ static struct custom_operations CvMemStorage_operations = { custom_deserialize_default }; -CAMLexport value ocaml_create_CvMemStorage(value vunit) +extern "C" CAMLprim value ocaml_create_CvMemStorage(value vunit) { CAMLparam1(vunit); CAMLlocal1 (res); @@ -79,7 +342,7 @@ CAMLexport value ocaml_create_CvMemStorage(value vunit) CAMLreturn (res); } -CAMLexport value ocaml_free_CvMemStorage(value vstor) +extern "C" CAMLprim value ocaml_free_CvMemStorage(value vstor) { CAMLparam1(vstor); caml_finalize_CvMemStorage(vstor); @@ -101,7 +364,7 @@ void caml_finalize_IplImage(value vimage) } static struct custom_operations IplImage_operations = { - "ocaml_opencv_IplImage", + (char*) "ocaml_opencv_IplImage", caml_finalize_IplImage, custom_compare_default, custom_hash_default, @@ -119,18 +382,25 @@ CAMLexport value caml_alloc_IplImage(IplImage *image) CAMLreturn (res); } -CAMLprim value ocaml_cvCreateImage(value vsize, value vtype, value vi) +extern "C" CAMLprim value ocaml_cvCreateImage(value vsize, value vtype, value vi) { CAMLparam3 (vsize, vtype, vi); CAMLlocal1 (res); - IplImage* image = cvCreateImage(cvSize(Int_val(Field (vsize, 0)), - Int_val(Field (vsize, 1))), - Int_val(vtype), Int_val(vi)); + IplImage* image = cvCreateImage(CvSize_val(vsize), Int_val(vtype), Int_val(vi)); + res = caml_alloc_IplImage(image); + CAMLreturn (res); +} + +extern "C" CAMLprim value ocaml_cvCreateImage_depth(value vsize, value vdepth, value vi) +{ + CAMLparam3 (vsize, vdepth, vi); + CAMLlocal1 (res); + IplImage* image = cvCreateImage(CvSize_val(vsize), Int_val(vdepth), Int_val(vi)); res = caml_alloc_IplImage(image); CAMLreturn (res); } -CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) +extern "C" CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) { CAMLparam2 (vfile, viscolor); CAMLlocal1 (res); @@ -140,7 +410,7 @@ CAMLprim value ocaml_cvLoadImage(value vfile, value viscolor) CAMLreturn (res); } -CAMLprim value ocaml_cvCloneImage(value vimage) +extern "C" CAMLprim value ocaml_cvCloneImage(value vimage) { CAMLparam1 (vimage); CAMLlocal1 (res); @@ -150,21 +420,21 @@ CAMLprim value ocaml_cvCloneImage(value vimage) CAMLreturn (res); } -CAMLprim value ocaml_cvZero(value vimage) +extern "C" CAMLprim value ocaml_cvZero(value vimage) { CAMLparam1 (vimage); cvZero( Image_val(vimage)->image ); CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvShowImage(value vwindow, value vimage) +extern "C" CAMLprim value ocaml_cvShowImage(value vwindow, value vimage) { CAMLparam2 (vwindow, vimage); cvShowImage( String_val(vwindow), Image_val(vimage)->image); CAMLreturn (Val_unit); } -CAMLprim value ocaml_image_size(value vimage) +extern "C" CAMLprim value ocaml_image_size(value vimage) { CAMLparam1 (vimage); CAMLlocal1 (res); @@ -175,14 +445,28 @@ CAMLprim value ocaml_image_size(value vimage) CAMLreturn (res); } -CAMLprim value ocaml_cvNamedWindow(value vwindow, value vi) +extern "C" CAMLprim value ocaml_cvNamedWindow(value vwindow, value vi) { CAMLparam2 (vwindow, vi); - cvNamedWindow(String_val(vwindow), Int_val(vi)); + ERRWRAP(cvNamedWindow(String_val(vwindow), Int_val(vi))); + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_cvDestroyWindow(value vwindow) +{ + CAMLparam1 (vwindow); + ERRWRAP(cvDestroyWindow(String_val(vwindow))); + CAMLreturn (Val_unit); +} + +extern "C" CAMLprim value ocaml_cvDestroyAllWindows(value vunit) +{ + CAMLparam1 (vunit); + ERRWRAP(cvDestroyAllWindows()); CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvWaitKey(value vi) +extern "C" CAMLprim value ocaml_cvWaitKey(value vi) { return (Val_int(cvWaitKey(Int_val(vi)))); } @@ -196,7 +480,7 @@ CAMLexport void caml_finalize_CvCapture(value vcapture) } static struct custom_operations CvCapture_operations = { - "ocaml_opencv_CvCapture", + (char*) "ocaml_opencv_CvCapture", caml_finalize_CvCapture, custom_compare_default, custom_hash_default, @@ -212,7 +496,7 @@ CAMLexport value caml_alloc_CvCapture(CvCapture *capture) return res; } -CAMLprim value ocaml_cvCaptureFromCAM(value vsource) +extern "C" CAMLprim value ocaml_cvCaptureFromCAM(value vsource) { CAMLparam1 (vsource); CAMLlocal1 (res); @@ -222,7 +506,7 @@ CAMLprim value ocaml_cvCaptureFromCAM(value vsource) CAMLreturn (res); } -CAMLprim value ocaml_cvQueryFrame(value vcapture) +extern "C" CAMLprim value ocaml_cvQueryFrame(value vcapture) { CAMLparam1 (vcapture); CAMLlocal1 (res); @@ -233,6 +517,99 @@ CAMLprim value ocaml_cvQueryFrame(value vcapture) CAMLreturn (res); } +int cv_cap_table[] = { + CV_CAP_PROP_DC1394_OFF, + CV_CAP_PROP_DC1394_MODE_MANUAL, + CV_CAP_PROP_DC1394_MODE_AUTO, + CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO, + CV_CAP_PROP_POS_MSEC, + CV_CAP_PROP_POS_FRAMES, + CV_CAP_PROP_POS_AVI_RATIO, + CV_CAP_PROP_FRAME_WIDTH, + CV_CAP_PROP_FRAME_HEIGHT, + CV_CAP_PROP_FPS, + CV_CAP_PROP_FOURCC, + CV_CAP_PROP_FRAME_COUNT, + CV_CAP_PROP_FORMAT, + CV_CAP_PROP_MODE, + CV_CAP_PROP_BRIGHTNESS, + CV_CAP_PROP_CONTRAST, + CV_CAP_PROP_SATURATION, + CV_CAP_PROP_HUE, + CV_CAP_PROP_GAIN, + CV_CAP_PROP_EXPOSURE, + CV_CAP_PROP_CONVERT_RGB, + CV_CAP_PROP_WHITE_BALANCE_BLUE_U, + CV_CAP_PROP_RECTIFICATION, + CV_CAP_PROP_MONOCROME, + CV_CAP_PROP_SHARPNESS, + CV_CAP_PROP_AUTO_EXPOSURE, + CV_CAP_PROP_GAMMA, + CV_CAP_PROP_TEMPERATURE, + CV_CAP_PROP_TRIGGER, + CV_CAP_PROP_TRIGGER_DELAY, + CV_CAP_PROP_WHITE_BALANCE_RED_V, + CV_CAP_PROP_MAX_DC1394, + CV_CAP_PROP_AUTOGRAB, + CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING, + CV_CAP_PROP_PREVIEW_FORMAT, + CV_CAP_OPENNI_DEPTH_GENERATOR, + CV_CAP_OPENNI_IMAGE_GENERATOR, + CV_CAP_OPENNI_GENERATORS_MASK, + CV_CAP_PROP_OPENNI_OUTPUT_MODE, + CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH, + CV_CAP_PROP_OPENNI_BASELINE, + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, + CV_CAP_PROP_OPENNI_REGISTRATION_ON, + CV_CAP_PROP_OPENNI_REGISTRATION, + CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, + CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE, + CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH, + CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON, + CV_CAP_GSTREAMER_QUEUE_LENGTH, + CV_CAP_PROP_PVAPI_MULTICASTIP, + CV_CAP_PROP_XI_DOWNSAMPLING, + CV_CAP_PROP_XI_DATA_FORMAT, + CV_CAP_PROP_XI_OFFSET_X, + CV_CAP_PROP_XI_OFFSET_Y, + CV_CAP_PROP_XI_TRG_SOURCE, + CV_CAP_PROP_XI_TRG_SOFTWARE, + CV_CAP_PROP_XI_GPI_SELECTOR, + CV_CAP_PROP_XI_GPI_MODE, + CV_CAP_PROP_XI_GPI_LEVEL, + CV_CAP_PROP_XI_GPO_SELECTOR, + CV_CAP_PROP_XI_GPO_MODE, + CV_CAP_PROP_XI_LED_SELECTOR, + CV_CAP_PROP_XI_LED_MODE, + CV_CAP_PROP_XI_MANUAL_WB, + CV_CAP_PROP_XI_AUTO_WB, + CV_CAP_PROP_XI_AEAG, + CV_CAP_PROP_XI_EXP_PRIORITY, + CV_CAP_PROP_XI_AE_MAX_LIMIT, + CV_CAP_PROP_XI_AG_MAX_LIMIT, + CV_CAP_PROP_XI_AEAG_LEVEL, + CV_CAP_PROP_XI_TIMEOUT +}; + +extern "C" CAMLprim value ocaml_cvSetCaptureProperty(value vcapture,value vprop, + value vval) +{ + CAMLparam3(vcapture, vprop, vval); + ERRWRAP(cvSetCaptureProperty(Capture_val(vcapture), + cv_cap_table[Int_val(vprop)], + Double_val(vval))); + CAMLreturn(Val_unit); +} + +extern "C" CAMLprim value ocaml_cvGetCaptureProperty(value vcapture,value vprop) +{ + CAMLparam2(vcapture, vprop); + double ret; + ERRWRAP(ret = cvGetCaptureProperty(Capture_val(vcapture), + cv_cap_table[Int_val(vprop)])); + CAMLreturn(caml_copy_double(ret)); +} + #define Int_var_val(v) (*(int**) (Data_custom_val(v))) CAMLexport void caml_finalize_Int_var(value vvar) @@ -242,7 +619,7 @@ CAMLexport void caml_finalize_Int_var(value vvar) } static struct custom_operations int_var_operations = { - "ocaml_opencv_int_var", + (char*) "ocaml_opencv_int_var", caml_finalize_Int_var, custom_compare_default, custom_hash_default, @@ -264,12 +641,12 @@ CAMLexport value caml_alloc_int_var(int def) { value res; res = caml_alloc_custom(&int_var_operations, sizeof(int*), 1, 1000); - Int_var_val(res) = cv_malloc(sizeof(int)); + Int_var_val(res) = (int*) cv_malloc(sizeof(int)); *(Int_var_val(res)) = def; return res; } -CAMLprim value ocaml_create_int_var(value vdef) +extern "C" CAMLprim value ocaml_create_int_var(value vdef) { CAMLparam1 (vdef); CAMLlocal1 (res); @@ -277,14 +654,14 @@ CAMLprim value ocaml_create_int_var(value vdef) CAMLreturn (res); } -CAMLprim value ocaml_get_int_var(value vvar) +extern "C" CAMLprim value ocaml_get_int_var(value vvar) { CAMLparam1 (vvar); int* var = Int_var_val(vvar); CAMLreturn (Val_int(*var)); } -CAMLprim value ocaml_set_int_var(value vvar, value vval) +extern "C" CAMLprim value ocaml_set_int_var(value vvar, value vval) { CAMLparam2 (vvar, vval); int* var = Int_var_val(vvar); @@ -292,7 +669,7 @@ CAMLprim value ocaml_set_int_var(value vvar, value vval) CAMLreturn (Val_unit); } -CAMLprim value ocaml_cvCreateTrackbar(value vname, value vwindow, value vvar, value vmax) +extern "C" CAMLprim value ocaml_cvCreateTrackbar(value vname, value vwindow, value vvar, value vmax) { CAMLparam4 (vname, vwindow, vvar, vmax); int res = cvCreateTrackbar(String_val(vname), String_val(vwindow), @@ -375,12 +752,12 @@ int conversion_table[] = { CV_HLS2RGB }; -int ocaml_get_color_conversion(int vtype) +extern "C" CAMLprim value ocaml_get_color_conversion(value vtype) { return (Val_int(conversion_table[Int_val(vtype)])); } -CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) +extern "C" CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) { CAMLparam3(vsrc, vdst, vtype); cvCvtColor(Image_val(vsrc)->image, @@ -389,7 +766,7 @@ CAMLprim value ocaml_cvCvtColor(value vsrc, value vdst, value vtype) CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, +extern "C" CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, value vdst1, value vdst2, value vdst3) { CAMLparam5(vsrc, vdst0, vdst1, vdst2, vdst3); @@ -408,7 +785,7 @@ CAMLprim value ocaml_cvSplit(value vsrc, value vdst0, CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvMerge(value vsrc0, value vsrc1, value vsrc2, +extern "C" CAMLprim value ocaml_cvMerge(value vsrc0, value vsrc1, value vsrc2, value vsrc3, value vdst) { CAMLparam5(vsrc0, vsrc1, vsrc2, vsrc3, vdst); @@ -442,7 +819,7 @@ int adaptiveMethod_table[] = { CV_ADAPTIVE_THRESH_GAUSSIAN_C, }; -CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, +extern "C" CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, value vmaxValue, value vthresholdType) { CAMLparam5(vsrc, vdst, vthreshold, vmaxValue, vthresholdType); @@ -454,7 +831,7 @@ CAMLprim value ocaml_cvThreshold(value vsrc, value vdst, value vthreshold, CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue, +extern "C" CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue, value vadaptiveMethod, value vthresholdType, value vblockSize, value vparam1) { @@ -470,52 +847,88 @@ CAMLprim value ocaml_cvAdaptiveThreshold(value vsrc, value vdst, value vmaxValue CAMLreturn(Val_unit); } -CAMLprim value ocaml_cvAdaptiveThreshold_bytecode( value * argv, int argn ) +extern "C" CAMLprim value ocaml_cvAdaptiveThreshold_bytecode( value * argv, int argn ) { return ocaml_cvAdaptiveThreshold( argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6] ); } -/* CAMLprim value ocaml_get_float_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vsrc)->image; */ -/* int index = Int_val(vindex); */ -/* Store_double_field(vres,0,image->imageData[3*i]); */ -/* Store_double_field(vres,1,image->imageData[3*i+1]); */ -/* Store_double_field(vres,2,image->imageData[3*i+2]); */ -/* CAMLreturn(Val_unit); */ -/* } */ - -/* CAMLprim value ocaml_set_float_3point(value vimage, value vindex, value vval) */ -/* { */ -/* IplImage* image = Image_val(vsrc)->image; */ -/* int index = Int_val(vindex); */ -/* camlimage->imageData[3*i] = Double_field(vval,0); */ -/* camlimage->imageData[3*i+1] = Double_field(vval,1); */ -/* camlimage->imageData[3*i+2] = Double_field(vval,2); */ -/* CAMLreturn(Val_unit); */ -/* } */ - -/* CAMLprim value ocaml_get_int_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vimage)->image; */ -/* int i = Int_val(vindex); */ -/* Field(vres,0) = image->imageData[3*i]; */ -/* Field(vres,1) = image->imageData[3*i+1]; */ -/* Field(vres,2) = image->imageData[3*i+2]; */ -/* return Val_unit; */ -/* } */ - -/* CAMLprim value ocaml_set_int_3point(value vimage, value vindex, value vres) */ -/* { */ -/* IplImage* image = Image_val(vimage)->image; */ -/* int i = Int_val(vindex); */ -/* image->imageData[3*i] = Field(vres,0); */ -/* image->imageData[3*i+1] = Field(vres,1); */ -/* image->imageData[3*i+2] = Field(vres,2); */ -/* return Val_unit; */ -/* } */ - -CAMLprim value ocaml_image_to_bigarray(value vimage) +extern "C" CAMLprim value ocaml_cvCanny(value vimage, value vedges, + value vthreshold1, value vthreshold2, + value vapertureSize) +{ + CAMLparam5(vimage, vedges, vthreshold1, vthreshold2, vapertureSize); + + cvCanny(Image_val(vimage)->image, + Image_val(vedges)->image, + Double_val(vthreshold1), + Double_val(vthreshold2), + Int_val(vapertureSize)); + + CAMLreturn(Val_unit); +} + +/* +extern "C" CAMLprim value ocaml_medianBlur(value vsrc, value vdst, value ksize) +{ + CAMLparam3(vsrc, vdst, ksize); + + Mat dst = Mat(Image_val(vdst)->image); + + ERRWRAP( + medianBlur(Mat(Image_val(vsrc)->image), + &dst, + Int_val(ksize))); + + CAMLreturn(Val_unit); +} +*/ + +extern "C" CAMLprim value ocaml_cvGoodFeaturesToTrack( + value image, + value vcorners, + value qualityLevel, + value minDistance, + value vmask, + value blockSize, + value useHarris, + value k) +{ + CAMLparam5(image, + vcorners, + qualityLevel, + minDistance, + vmask); + CAMLxparam3(blockSize, + useHarris, + k); + + CvArr* mask = Is_long(vmask) ? NULL : Image_val(Field(vmask,0))->image; + CvPoint2D32f* corners = (CvPoint2D32f*) Data_bigarray_val(vcorners); + int cornerCount = Bigarray_val(vcorners)->dim[0];; + + ERRWRAP( + cvGoodFeaturesToTrack(Image_val(image)->image, + NULL, + NULL, + corners, + &cornerCount, + Double_val(qualityLevel), + Double_val(minDistance), + mask, + Int_val(blockSize), + Bool_val(useHarris), + Double_val(k))); + + CAMLreturn(Val_int(cornerCount)); +} + +extern "C" CAMLprim value ocaml_cvGoodFeaturesToTrack_bytecode( value * argv, int argn ) +{ + return ocaml_cvGoodFeaturesToTrack( argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6], argv[7] ); +} + +extern "C" CAMLprim value ocaml_image_to_bigarray(value vimage) { CAMLparam1(vimage); CAMLlocal1(ba); @@ -528,150 +941,26 @@ CAMLprim value ocaml_image_to_bigarray(value vimage) CAMLreturn(ba); } -CAMLprim value ocaml_image_channels(value vimage) +extern "C" CAMLprim value ocaml_image_channels(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->nChannels)); } -CAMLprim value ocaml_image_depth(value vimage) +extern "C" CAMLprim value ocaml_image_depth(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->depth)); } -CAMLprim value ocaml_image_data_order(value vimage) +extern "C" CAMLprim value ocaml_image_data_order(value vimage) { CAMLparam1(vimage); CAMLreturn(Val_int(Image_val(vimage)->image->dataOrder)); } -static CvScalar CvScalar_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - double v3 = Double_val(Field(v,3)); - return (cvScalar(v0,v1,v2,v3)); -} - -static CvPoint CvPoint_val(value v) { - int v0 = Int_val(Field(v,0)); - int v1 = Int_val(Field(v,1)); - return (cvPoint(v0,v1)); -} - -/* unused -static CvPoint2D32f CvPoint2D32f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - return (cvPoint2D32f(v0,v1)); -} - -static CvPoint3D32f CvPoint3D32f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - return (cvPoint3D32f(v0,v1,v2)); -} - -static CvPoint2D64f CvPoint2D64f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - return (cvPoint2D64f(v0,v1)); -} - -static CvPoint3D64f CvPoint3D64f_val(value v) { - double v0 = Double_val(Field(v,0)); - double v1 = Double_val(Field(v,1)); - double v2 = Double_val(Field(v,2)); - return (cvPoint3D64f(v0,v1,v2)); -} -*/ - -static CvSize CvSize_val(value v) { - int v0 = Int_val(Field(v,0)); - int v1 = Int_val(Field(v,1)); - return (cvSize(v0,v1)); -} - -static CvTermCriteria CvTermCriteria_val(value v) { - int tc_iter = Int_val(Field(v,0)); - int tc_eps = Int_val(Field(v,1)); - int type = 0; - if (tc_iter) type |= CV_TERMCRIT_ITER; - if (tc_eps) type |= CV_TERMCRIT_EPS; - int max_iter = Int_val(Field(v,2)); - double epsilon = Double_val(Field(v,3)); - return (cvTermCriteria(type,max_iter,epsilon)); -} - -static CvMat CvMat_val(value v) { - void* data = Data_bigarray_val(v); - int rows = Bigarray_val(v)->dim[0]; - int cols = Bigarray_val(v)->dim[1]; - int channels = Bigarray_val(v)->dim[2]; - int kind = Bigarray_val(v)->flags & BIGARRAY_KIND_MASK; - int type = 0; - switch (kind) { - - case BIGARRAY_FLOAT32: - switch (channels) { - case 1: - type = CV_32FC1; - break... [truncated message content] |