PowerShell Control over Nikon D3000 Camera

Posted on Dot net Slackers See other posts from Dot net Slackers
Published on Mon, 26 Apr 2010 00:00:00 GMT Indexed on 2010/04/26 16:53 UTC
Read the original article Hit count: 965

Filed under:

My wife got me a Nikon D3000 camera for Christmas last year, and Im loving it but still trying to wrap my head around some of its features.  For instance, when you plug it into a computer via USB, it doesnt show up as a drive like most cameras Ive used to, but rather it shows up as Computer\D3000.  After a bit of research, Ive learned that this is because it implements the MTP/PTP protocol, and thus doesnt actually let Windows mount the cameras storage as a drive letter.  Nikon describes the use of the MTP and PTP protocols in their cameras here.

What Im really trying to do is gain access to the cameras file system via PowerShell.  Ive been using a very handy PowerShell script to pull pictures off of my cameras and organize them into folders by date.  Id love to be able to do the same thing with my Nikon D3000, but so far I havent been able to figure out how to get access to the files in PowerShell.  If you know, Id appreciate any links/tips you can provide.  All I could find is a shareware product called PTPdrive, which Im not prepared to shell out money for (yet).  (and yes you can do much the same thing with Windows 7s Import Pictures and Videos wizard, which is pretty good too)

However, in my searching, I did find some really cool stuff you can do with PowerShell and one of these cameras, like actually taking pictures via PowerShell commands.  Credit for this goes to James ONeill and Mark Wilson.  Heres what I was able to do:

Taking Pictures via PowerShell with D3000

First, connect your camera, turn it on, and launch PowerShell.  Execute the following commands to see what commands your device supports. 

$dialog = New-Object -ComObject "WIA.CommonDialog"
$device = $dialog.ShowSelectDevice()
$device.Commands

You should see something like this:

image

Now, to take a picture, simply point your camera at something and then execute this command:

$device.ExecuteCommand("{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}")

image

Imagine my surprise when this actually took a picture (with auto-focus):

DSC_0146

Imagine what you could do with a camera completely under the control of your computer  Time-lapse photography would be pretty simple, for instance, with a very simple loop that takes a picture and then sleeps for a minute (or whatever time period).  Hooked up to a laptop for portability (and an A/C power supply), this would be pretty trivial to implement.  I may have to give it a shot and report back.


Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.



Email this Article

© Dot net Slackers or respective owner