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()))

3 thoughts on “Capture Video in 2 Lines of Code

  1. 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?

    1. 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).

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.