Home > F# > Capture Video in 2 Lines of Code

Capture Video in 2 Lines of Code

Literally. Well almost. 2 meaningful lines + some boilerplate. This has got to be easier than even Python!

Using EmguCV, a wrapper around OpenCV and F# Interactive:

#I @"C:\<project directory>\packages\EmguCV.3.0.0\lib\net451"
#r "Emgu.CV.dll"
#r "Emgu.Util.dll"
#r "System.Windows.Forms"

open Emgu.CV
open System.Windows.Forms

let capture = new Capture()
Application.Idle.Add(fun _ -> CvInvoke.Imshow("Camera", capture.QueryFrame()))

Categories: F# Tags: , , , ,
  1. bjorn
    April 11, 2016 at 6:50 am

    I’m trying to use Emgu.CV in FSI (via Nuget package) in visual studio 2015 but getting “System.TypeInitializationException: The type initializer for ‘Emgu.CV.CvInvoke’ threw an exception. —> System.DllNotFoundException: Unable to load DLL ‘cvextern’ ”

    Are you also using visual studio and have you done anything to reference the unmanaged OpenCV .dlls in your solution?

    • April 11, 2016 at 8:48 am

      Make sure you run the installation from their website. The NuGet package doesn’t install supporting binaries. Then add the directory with the supporting binaries (I installed from their website, so for me it’s %emgu_dir%\bin\x64 to your PATH and restart Visual Studio. This will be the directory which has all the OpenCV libraries and cvextern.dll, that wraps calls to them. Also, if you are on an x64 system, make sure your FSI runs as x64 (Tools -> Options -> F# Tools -> F# Interactive -> 64-bit Interactive set to true).

  1. March 27, 2016 at 12:11 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: