Random header image... Refresh for more!

Achievement Unlocked: The Situation Is Under Control

The first bit of code for Crazy Weekend Project III has been checked in.  It’s a rework of the OpenCV Video Capture code from CWP I that makes it a little bit more friendly and reusable.  (And probably introduces some fun bugs…)

For those wishing to play along at home:

The new solution is located here:  http://www.mathpirate.net/svn/Projects/AtariRobot/AtariRobot2/

You may be required to pull projects from other places in the repository, including /external and /Projects/AtariRobot.

Here’s the current interface of the VideoCapture class:

public class VideoCapture
    public List<IplImage> HistoricalFrames { get; protected set; }
    public IplImage CurrentFrame { get; protected set; }
    public CvCapture Capture { get; protected set; }
    public int FrameTimeMS { get; protected set; }
    public Options Options { get; protected set; }
    public int FrameNumber { get; protected set; }

    public void Start();
    public void Start(Options options);
    public void Stop();

Argh, I’ve forgotten how to successfully paste code into WordPress so that the indention isn’t mangled (Good thing I’m not writing Python!) and so greater thans and less thans and ampersands aren’t destroyed.

Anyway, you just new up one of these VideoCapture classes, then call Start().  If you’ve already configured the video options (What camera ID to use or what video file to read), you can pass that in, otherwise it will ask when you call Start().  Start() will start a new thread that constantly reads frames at the given video’s frame rate1 and sticks them into the HistoricalFrames List.  Current Frame is always the latest frame, and operations will generally use this frame.  When you’re done, call Stop() and it’ll dispose everything for you and kill the thread.  Three lines to get frames from a video.  Much nicer than the 30 or so that were there before.

  1. Or at least close to it.  I’m using Thread.Sleep() here, which is not the best for timing this sort of thing… []


There are no comments yet...

Kick things off by filling out the form below.

Leave a Comment