PowerShell Control over Nikon D3000 Camera
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:
Now, to take a picture, simply point your camera at something and then execute this command:
$device.ExecuteCommand("{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}")
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Imagine my surprise when this actually took a picture (with auto-focus):
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.