Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV from F#

Tags:

opencv

f#

I would like to analyse the colour of a picture. Is it possible to use the OpenCV library with F# (the only language I am familiar with). If yes, do you know where I can find a tutorial/book on this subject (OpenCV 2 Computer Vision seems great but is written for C++ users).

like image 907
fabco63 Avatar asked Sep 20 '11 21:09

fabco63


People also ask

Can I use OpenCV with C?

OpenCV is a popular Computer Vision library to develop applications built using C++ and C. It has several uses like Object Detection and Video Processing. Computer Vision overlaps with fields like Image Processing, Photogrammetry, and Pattern Recognition. A popular wrapper Emgu CV is used to run OpenCV using C#.

Is OpenCV written in C or C++?

Programming language OpenCV is written in C++ and its primary interface is in C++, but it still retains a less comprehensive though extensive older C interface. All of the new developments and algorithms appear in the C++ interface.

Which language is best for OpenCV?

If you want to make use of OpenCV, C/C++ is best, but you can also use the Python or Java API as well.


2 Answers

This is definitely possible using F# with one of .NET wrappers over OpenCV. For example, below is the "Hello World" snippet that comes with EmguCV translated from C# to F# that works perfectly:

open Emgu.CV
open Emgu.CV.CvEnum
open Emgu.CV.Structure

[<EntryPoint>]
let main(_) =
    let win1 = "Test Window"
    CvInvoke.cvNamedWindow(win1) |> ignore
    use img = new Image<Bgr, byte>(400, 200, Bgr(255.,0.,0.))
    let f = ref (MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 1., 1.))
    img.Draw("Hello, World", f, System.Drawing.Point(10,80), Bgr(0.,255.,0.))
    CvInvoke.cvShowImage(win1, img.Ptr)
    CvInvoke.cvWaitKey(0) |> ignore
    CvInvoke.cvDestroyWindow(win1)
    0

EmguCV web site and installation provide some C# tutorials that may give you initial traction. Your mileage may vary, depending on your F# interop skills among other factors.

like image 160
Gene Belitski Avatar answered Nov 12 '22 07:11

Gene Belitski


Emgu CV is the most popular option with Emgu CV Essentials book. Two other .NET OpenCV wrapper projects:

  • OpenCvSharp
  • OpenCV.NET
like image 35
Paul Jurczak Avatar answered Nov 12 '22 05:11

Paul Jurczak