Sunday, May 26, 2013

Time Lapse Photography, Part 1 - An Introduction

Photography has been around a long time. The basic ideas and science behind photography hasn't changed significantly unless you consider ideas such as rolling shutters, and the huge amount of small, cheap digital cameras that have popped up in the past 15 or so years.
The basic premise is the same across all formats though, you have a shutter(or a combination thereof), a lens, and a small set of circuitry that opens these shutters, flips mirrors, and times everything down to thousands, or sometimes millions of seconds. 
Film is simply an extrapolation thereof, old film strips are just long lines of images, played at a fast frame rate (24 or 30 fps), or an extremely fast frame rate (1000+) for modern high speed cameras.

Time lapse photography is a method utilized by a variety of filmmakers over generations. Time lapse, and slow motion are effectively opposite ideas. Things that you see in slow motion such as this one are images captured at a rate much FASTER than the human eye can see.

The opposite end of this spectrum is time lapse. Video that produce a time lapsing effect is captured a much SLOWER rate than the eye can see.
Work here property of http://projectyose.com/

Time lapse photography is the focus of our current project and will ultimately be the focus of many future posts regarding such. In the video above, you will notice a motion from the camera where it moves on a plane either on a diagonal, or panning from left to right. It is the production of this motion, in conjunction with telling the camera when to fire, that will be the main focus of this project. 

There are many high end professional camera dollies on the market: 
Many that are used in high end film production and film sets. These cost thousands or tens of thousands and can carry a camera man, and a 200 lb camera. 


There are also small production dollies that carry either a small 1080p camera, a RED camera, or a beefy SLR. 
There are also smaller production dollies made specifically for DSLRs. This is going to be the type of dolly that we are working on. It seems many DSLR owners have already been seeking a cheap solution to adding motion to their work, so as such a great community of photographers has already formed, many of whom are extra supportive of open source projects and often support reproductions, and sharing of ideas. One resource that immediately shows it's wealth is http://openmoco.org/ This community of photographers, programmers and problems solvers have been sharing ideas for years and many of them have started their own businesses providing motion control to other photographers. 

In part 2 of this introduction I will further explain the mechanics behind time lapse, motion control, and how the two come together to make great video compositions. In the posts following this, we will be building a motion controlled camera dolly to carry a DSLR. To build it, we're going to use many open source parts, both hardware, and software wise. The heart of the project contains an Arduino, an LCD shield, motor shield, and camera controller. As such, all of the programming is almost entirely going to be related to the Arduino. 

If you're interested in more reading, check out openmoco.org, or for more videos http://timescapes.org/

If you're interested in purchasing a ready-built dolly, that you can hook up to a DSLR camera and go, then I can't recommend a company any higher than dynamicperception.com. Dynamic Perception highly supports open source design, and is a major inspiration for the build that follows. They make amazing products that is backed up by amazing customer support. For those of us that like to tinker though, stay tuned! We're going to go over a variety of options and things to consider when building your own dolly. 

Tuesday, April 23, 2013

.NET, OAuth2, and the Google Analytics Service account.

Google likes to change things. About a year ago I went through one of their C#  Data Export examples to grab some Analytics data for a program I was writing. The previous method of authentication was easy add the user/pass into the url request or add an API key to the query.

In August 2012 Google deprecated the v2.3 reporting and authentication method in favor of OAuth2 at the time of deprecation Google didn't provide a lot of information for C# / .NET developers who needed to migrate off the old way.

http://code.google.com/p/gdata-issues/issues/detail?id=2955

Since that time they've improved their dot-net-client libraries and wrote a tutorial on authenticating with OAuth2. I wasn't able to get their code to compile when I attempted but it did put me on the correct path.

This is a project of firsts: first time with MVC, first time attempting to make a SPA (Single-Page Application) Knockout.js, and first time working with OAuth2 authentication.  I followed John Papa's excellent SPA Overview for the most part.

The latest WebSite and MVC WebSite default templates from Microsoft have OAuth2 authentication built in and doesn't require any setup at all just two-step authentication with whatever service we're logging in with.
I didn't want this since I only wanted access to my analytics account. The analytics API also seemed to have some issues getting certain information using this method.

After some intense googling I found the OAuth2 Service account of course with no working C#/.NET examples...This is what I ended up doing.

I put everything I could find together into this project.

Follow the beginning of Googles OAuth2  tutorial and register your app in Googles API Console.

Create a ClientID and choose 'service account' download your private key.  


Edit the following:

Models/Utils.cs

 public static IAuthenticator getCredentials(string scope)
    {
        const string ServiceAccountId = "SERVICEACCOUNTID.apps.googleusercontent.com";
        const string ServiceAccountUser = "ServiceAccountUser@developer.gserviceaccount.com";
      try
      {
          AssertionFlowClient client = new AssertionFlowClient(
              GoogleAuthenticationServer.Description,
              new X509Certificate2(
                  HttpContext.Current.Server.MapPath("~/Content/key/0eee0d919aaef70bbb5da23b192aede576577058-privatekey.p12"), "notasecret", X509KeyStorageFlags.Exportable))
{ Scope = scope,  ServiceAccountId = ServiceAccountUser};
 OAuth2Authenticator<AssertionFlowClient> authenticator = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
 return authenticator;
}
catch (Exception ex)
{ }
 return null;
}
Changing the path to the location of the key download from the console earlier. and changing SERVICEACCOUNTID and ServiceAccountUser to whats listed in the API Console. Once thats completed the Controller will attempt to authenticate using the method below:
try {
    Session["authenticator"] = Utils.getCredentials(AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue());
    IAuthenticator authenticator = Session["authenticator"] as IAuthenticator;
    AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer() {
        Authenticator = authenticator
    });
    var profiles = service.Management.Profiles.List("~all", "~all").Fetch();
    user.profiles = profiles;

} catch (Exception ex) {
    ViewBag.Error = ex.Message;
    return View("Error");
}
One thing to note is that it seems this current version can only authenticate one scope at a time...I've been unable to pass in more than one.

AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue() will only bring back the profiles that are available under the authenticated account.

A different scope is needed to query the profiles and the analytics data in them. In addition to changing the scope the service account  needs to be added to the analytics profile as an authenticated user.

GitHub Project
Google Dot Net Client Libraries
Google OAuth2 
Google Service Account documentation 

Saturday, April 13, 2013

RaspberryPi, Boblight, and the WS2801 LED - Follow up


(game isn't using boblight leds)

Had some time this weekend to follow up on some of the comments from my last post.

Gregory posted a link to this excellent tutorial. Allowing boblight and xbmc to run off the same pi.

cell phone camera doesn't capture the colors correctly but you get the idea: