Wrapperにある”demo/continuouscapture”には、高速連写で5ショットするプログラムが入っています。
 これを素材に、1ショットずつ画像をSDカードにセーブしながら低速連写(キャッシュに溜まらず延々撮像可能なRAWのみ・2ショット/秒)するプログラムに改編しました。
 高速/低速を指示するコードの部分がエラーになるので、ココをコメントアウトしました。ボディの設定で動くようになります。
 続いて単写の時に使ったSDカードにセーブするルーチンを下記の赤文字の部分に挿入しました。
 このソースでは20ショット(10秒)撮像します。
 これを使えば第2・3接触のダイヤモンドリング狙いの撮像もこなせるでしょう。
 次にやることは、シャッター速度を変えるプログラムを作ることでしょう。
 最後はすべてを組み合わせて自動撮像化することですが、さて?
Index Next

//

// This work is licensed under a Creative Commons Attribution 3.0 Unported License.

//

// Thomas Dideriksen (thomas@dideriksen.com)

// M_shi with Welfare Lab.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.IO;

using Nikon;

 

//

// This demo shows how to perform continuous capture and store the images to disk

//

 

namespace demo_continuouscapture

{

    class DemoContinuousCapture

    {

        NikonDevice _device;

        AutoResetEvent _waitForDevice = new AutoResetEvent(false);

        AutoResetEvent _waitForCaptureComplete = new AutoResetEvent(false);

        int _captureCount = 0;

        NikonImage image;

        NikonDevice sender;

        NikonDevice device;

 

        public void Run()

        {

            try

            {

                NikonManager manager = new NikonManager("Type0008.md3");

 

                // Listen for the 'DeviceAdded' event

                manager.DeviceAdded += manager_DeviceAdded;

 

                // Wait for a device to arrive

                _waitForDevice.WaitOne();

                /*ここで引っかかって動かなかったためコメントアウト

                // Set shooting mode to 'continuous, highspeed'

                NikonEnum shootingMode = _device.GetEnum(eNkMAIDCapability.kNkMAIDCapability_ShootingMode);

                shootingMode.Index = (int)eNkMAIDShootingMode.kNkMAIDShootingMode_CH;

                _device.SetEnum(eNkMAIDCapability.kNkMAIDCapability_ShootingMode, shootingMode);

                */

                // Set number of continuous captures - in this case we want 5

                _device.SetUnsigned(eNkMAIDCapability.kNkMAIDCapability_ContinuousShootingNum, 20);

 

                // Hook up capture events

                _device.ImageReady += _device_ImageReady;

                _device.CaptureComplete += _device_CaptureComplete;

 

                // Capture

                _device.Capture();

 

                // Wait for the capture to complete

                _waitForCaptureComplete.WaitOne();

 

                // Shutdown

                manager.Shutdown();

 

                if (_device == null)

                {

                    this._device = device;

 

                    device.SetUnsigned(eNkMAIDCapability.kNkMAIDCapability_SaveMedia,

                        (uint)eNkMAIDSaveMedia.kNkMAIDSaveMedia_Card);

 

                    // Signal that we got a device

                    _waitForDevice.Set();

                }

 

            }

            catch (NikonException ex)

            {

                Console.WriteLine(ex.Message);

            }

        }

 

        void _device_ImageReady(NikonDevice sender, NikonImage image)

        {

            // Save captured image to disk

            string filename = "image" + _captureCount.ToString() + ((image.Type == NikonImageType.Jpeg) ? ".jpg" : ".nef");

            _captureCount++;

 

            using (FileStream s = new FileStream(filename, FileMode.Create, FileAccess.Write))

            {

                s.Write(image.Buffer, 0, image.Buffer.Length);

            }

        }

 

        void _device_CaptureComplete(NikonDevice sender, int data)

        {

            // Signal the the capture completed

            _waitForCaptureComplete.Set();

        }

 

         void manager_DeviceAdded(NikonManager sender, NikonDevice device)

       {

            if (_device == null)

            {

                this._device = device;

 

                device.SetUnsigned(eNkMAIDCapability.kNkMAIDCapability_SaveMedia,

                    (uint)eNkMAIDSaveMedia.kNkMAIDSaveMedia_Card);

 

                // Signal that we got a device

                _waitForDevice.Set();

            }

        }

    }

 

    class Program

    {

        static void Main(string[] args)

        {

            DemoContinuousCapture demo = new DemoContinuousCapture();

            demo.Run();

        }

    }

}


Index Next
inserted by FC2 system