private void ReInitShutterSpeed() { lock (Locker) { try { //byte datasize = 4; ShutterSpeed.Clear(); foreach (KeyValuePair <uint, string> keyValuePair in _shutterTable) { ShutterSpeed.AddValues(keyValuePair.Value, keyValuePair.Key); } //byte[] result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, CONST_PROP_EOS_ShutterSpeed); //int type = BitConverter.ToInt16(result, 2); //byte formFlag = result[(2 * datasize) + 5]; //UInt32 defval = BitConverter.ToUInt32(result, datasize + 5); //for (int i = 0; i < result.Length - ((2 * datasize) + 6 + 2); i += datasize) //{ // UInt32 val = BitConverter.ToUInt32(result, ((2 * datasize) + 6 + 2) + i); // ShutterSpeed.AddValues(_shutterTable.ContainsKey(val) ? _shutterTable[val] : val.ToString(), val); //} //ShutterSpeed.SetValue(defval); } catch (Exception ex) { Log.Debug("EOS Shutter speed init", ex); } } }
private void SetCameraSettings(AEMode aeMode, WhiteBalance balance, ApertureValue apertureValue, CameraISOSensitivity cameraIsoSensitivity, ShutterSpeed shutterSpeed) { //_imageProcessor.SetSetting((uint)PropertyId.AEMode, (uint)aeMode); TODO Не поддерживается Eos 1100 _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)balance); _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)apertureValue); //_imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint))); _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)cameraIsoSensitivity); _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)shutterSpeed); }
public virtual async Task<CompositionProcessingResult> TakePictureAsync(byte[] liveViewImageStream, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { Size liveViewImageStreamSize; using (var stream = new MemoryStream(liveViewImageStream)) { var img = Image.FromStream(stream); liveViewImageStreamSize = img.Size; } return new CompositionProcessingResult(_pattern, await TakePictureInternal(liveViewImageStreamSize, selectedAeMode, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed, selectedWhiteBalance, token)); }
private async Task<byte[]> Run(Size liveViewImageStreamSize, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { var settings = GetCameraPhotoSettings(); List<byte[]> pictures = new List<byte[]>(); for (int i = 0; i < _pattern.Images.Count; i++) { token.ThrowIfCancellationRequested(); RaiseImageNumberChanged(i + 1); RaiseTimerElapsed(4); await Task.Delay(TimeSpan.FromSeconds(2), token); for (int j = 3; j >= 0; j--) { RaiseTimerElapsed(j); await Task.Delay(TimeSpan.FromSeconds(1), token); } SetCameraSettings(Enum.Parse(typeof(AEMode), settings.SelectedAeMode), Enum.Parse(typeof(WhiteBalance), settings.SelectedWhiteBalance), Enum.Parse(typeof(ApertureValue), settings.SelectedAvValue), Enum.Parse(typeof(CameraISOSensitivity), settings.SelectedIsoSensitivity), Enum.Parse(typeof(ShutterSpeed), settings.SelectedShutterSpeed)); //await Task.Delay(TimeSpan.FromSeconds(1)); //RaiseImageNumberChanged(i + 1); // await Task.Delay(TimeSpan.FromSeconds(1), token); token.ThrowIfCancellationRequested(); byte[] picture = await _imageProcessor.DoTakePicture(); pictures.Add(picture); token.ThrowIfCancellationRequested(); // await Task.Delay(TimeSpan.FromSeconds(3), token); //todo SetCameraSettings(selectedAeMode, selectedWhiteBalance, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed); StopLiveView(); StartLiveView(); } byte[] result = _imageUtils.ProcessImages(pictures, liveViewImageStreamSize, _pattern); return result; }
private void ReInitShutterSpeed() { lock (Locker) { try { ShutterSpeed.Clear(); var data = Camera.GetPropertyDescription(Edsdk.PropID_Tv); foreach (KeyValuePair <uint, string> keyValuePair in _shutterTable) { if (data.NumElements > 0) { if (ArrayContainValue(data.PropDesc, keyValuePair.Key)) { ShutterSpeed.AddValues(keyValuePair.Value, keyValuePair.Key); } } else { ShutterSpeed.AddValues(keyValuePair.Value, keyValuePair.Key); } } long value = Camera.GetProperty(Edsdk.PropID_Tv); if (value == 0) { ShutterSpeed.IsEnabled = false; } else { ShutterSpeed.IsEnabled = true; ShutterSpeed.SetValue(Camera.GetProperty(Edsdk.PropID_Tv), false); } } catch (Exception ex) { Log.Debug("EOS Shutter speed init", ex); } } }
public override bool Init(DeviceDescriptor deviceDescriptor) { IsBusy = false; //the device not connected try { ConnectToWiaDevice(deviceDescriptor); } catch (Exception exception) { Log.Error("Unable to connect camera using wia driver", exception); return(false); } DeviceManager = new DeviceManager(); DeviceManager.RegisterEvent(Conts.wiaEventItemCreated, deviceDescriptor.WiaId); DeviceManager.OnEvent += DeviceManager_OnEvent; try { Device = deviceDescriptor.WiaDevice; DeviceName = Device.Properties["Description"].get_Value(); Manufacturer = Device.Properties["Manufacturer"].get_Value(); SerialNumber = StaticHelper.GetSerial(Device.Properties["PnP ID String"].get_Value()); } catch (Exception ex) { Log.Debug("Init error", ex); } IsConnected = true; try { try { Property apertureProperty = Device.Properties[Conts.CONST_PROP_F_Number]; if (apertureProperty != null) { foreach (var subTypeValue in apertureProperty.SubTypeValues) { double d = (int)subTypeValue; string s = (d / 100).ToString("0.0"); FNumber.AddValues(s, (int)d); FNumber.ReloadValues(); if ((int)subTypeValue == (int)apertureProperty.get_Value()) { FNumber.SetValue((int)d); } } } } catch (COMException) { FNumber.IsEnabled = false; } try { Property isoProperty = Device.Properties[Conts.CONST_PROP_ISO_Number]; if (isoProperty != null) { foreach (var subTypeValue in isoProperty.SubTypeValues) { IsoNumber.AddValues(subTypeValue.ToString(), (int)subTypeValue); IsoNumber.ReloadValues(); if ((int)subTypeValue == (int)isoProperty.get_Value()) { IsoNumber.SetValue((int)subTypeValue); } } } } catch (COMException) { IsoNumber.IsEnabled = false; } try { Property shutterProperty = Device.Properties[Conts.CONST_PROP_Exposure_Time]; if (shutterProperty != null) { foreach (int subTypeValue in shutterProperty.SubTypeValues) { if (ShutterTable.ContainsKey((int)subTypeValue)) { ShutterSpeed.AddValues(ShutterTable[(int)subTypeValue], (int)subTypeValue); } } ShutterSpeed.ReloadValues(); ShutterSpeed.SetValue(shutterProperty.get_Value()); } } catch (COMException) { ShutterSpeed.IsEnabled = false; } try { Property wbProperty = Device.Properties[Conts.CONST_PROP_WhiteBalance]; if (wbProperty != null) { foreach (var subTypeValue in wbProperty.SubTypeValues) { if (WbTable.ContainsKey((int)subTypeValue)) { WhiteBalance.AddValues(WbTable[(int)subTypeValue], (int)subTypeValue); } } WhiteBalance.ReloadValues(); WhiteBalance.SetValue(wbProperty.get_Value()); } } catch (COMException) { WhiteBalance.IsEnabled = false; } try { Property modeProperty = Device.Properties[Conts.CONST_PROP_ExposureMode]; if (modeProperty != null) { foreach (var subTypeValue in modeProperty.SubTypeValues) { if (ExposureModeTable.ContainsKey((int)subTypeValue)) { Mode.AddValues(ExposureModeTable[(int)subTypeValue], Convert.ToUInt32(subTypeValue)); } } Mode.ReloadValues(); Mode.SetValue(Convert.ToUInt32(modeProperty.get_Value())); } Mode.IsEnabled = false; } catch (COMException) { Mode.IsEnabled = false; } try { Property ecProperty = Device.Properties[Conts.CONST_PROP_ExposureCompensation]; if (ecProperty != null) { foreach (var subTypeValue in ecProperty.SubTypeValues) { decimal d = (int)subTypeValue; string s = decimal.Round(d / 1000, 1).ToString(); if (d > 0) { s = "+" + s; } ExposureCompensation.AddValues(s, (int)subTypeValue); } ExposureCompensation.ReloadValues(); ExposureCompensation.SetValue(ecProperty.get_Value()); } } catch (COMException) { ExposureCompensation.IsEnabled = false; } try { Property csProperty = Device.Properties[Conts.CONST_PROP_CompressionSetting]; if (csProperty != null) { foreach (var subTypeValue in csProperty.SubTypeValues) { if (CSTable.ContainsKey((int)subTypeValue)) { CompressionSetting.AddValues(CSTable[(int)subTypeValue], (int)subTypeValue); } } CompressionSetting.ReloadValues(); CompressionSetting.SetValue(csProperty.get_Value()); } } catch (COMException) { CompressionSetting.IsEnabled = false; } try { Property emmProperty = Device.Properties[Conts.CONST_PROP_ExposureMeteringMode]; if (emmProperty != null) { foreach (var subTypeValue in emmProperty.SubTypeValues) { if (EMMTable.ContainsKey((int)subTypeValue)) { ExposureMeteringMode.AddValues(EMMTable[(int)subTypeValue], (int)subTypeValue); } } ExposureMeteringMode.ReloadValues(); ExposureMeteringMode.SetValue(emmProperty.get_Value()); } } catch (COMException) { CompressionSetting.IsEnabled = false; } try { Property fmProperty = Device.Properties[Conts.CONST_PROP_FocusMode]; if (fmProperty != null) { foreach (int subTypeValue in fmProperty.SubTypeValues) { uint subval = Convert.ToUInt16(subTypeValue); if (FMTable.ContainsKey(subval)) { FocusMode.AddValues(FMTable[subval], subval); } } FocusMode.ReloadValues(); FocusMode.SetValue(Convert.ToUInt16((int)fmProperty.get_Value())); } } catch (COMException) { FocusMode.IsEnabled = false; } try { Battery = Device.Properties[Conts.CONST_PROP_BatteryStatus].get_Value(); } catch (COMException) { Battery = 0; } IsConnected = true; } catch (Exception exception) { Log.Error(exception); IsConnected = false; } HaveLiveView = true; //Capabilities.Add(CapabilityEnum.LiveView); return(true); }
protected async Task<byte[]> TakePictureInternal(Size liveViewImageStreamSize, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { return await Task.Run(() => Run(liveViewImageStreamSize, selectedAeMode, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed, selectedWhiteBalance, token), token); }
private void SetCameraSettings(AEMode aeMode, WhiteBalance balance, ApertureValue apertureValue, CameraISOSensitivity cameraIsoSensitivity, ShutterSpeed shutterSpeed) { _imageProcessor.SetSetting((uint)PropertyId.AEMode, (uint)aeMode); _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)balance); _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)apertureValue); //_imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint))); _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)cameraIsoSensitivity); _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)shutterSpeed); }
private async Task <byte[]> Run(Size liveViewImageStreamSize, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { var settings = GetCameraPhotoSettings(); var pictures = new List <byte[]>(); for (var i = 0; i < _pattern.Images.Count; i++) { token.ThrowIfCancellationRequested(); RaiseImageNumberChanged(i + 1); RaiseTimerElapsed(4); await Task.Delay(TimeSpan.FromSeconds(2), token); for (var j = 3; j >= 0; j--) { RaiseTimerElapsed(j); await Task.Delay(TimeSpan.FromSeconds(1), token); } SetCameraSettings(Enum.Parse(typeof(AEMode), settings.SelectedAeMode), Enum.Parse(typeof(WhiteBalance), settings.SelectedWhiteBalance), Enum.Parse(typeof(ApertureValue), settings.SelectedAvValue), Enum.Parse(typeof(CameraISOSensitivity), settings.SelectedIsoSensitivity), Enum.Parse(typeof(ShutterSpeed), settings.SelectedShutterSpeed)); //await Task.Delay(TimeSpan.FromSeconds(1)); //RaiseImageNumberChanged(i + 1); //await Task.Delay(TimeSpan.FromSeconds(1), token); token.ThrowIfCancellationRequested(); var picture = await _imageProcessor.DoTakePicture(); pictures.Add(picture); token.ThrowIfCancellationRequested(); //await Task.Delay(TimeSpan.FromSeconds(3), token); //todo SetCameraSettings(selectedAeMode, selectedWhiteBalance, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed); StopLiveView(); StartLiveView(); } var result = _imageUtils.ProcessImages(pictures, liveViewImageStreamSize, _pattern); return(result); }
protected async Task <byte[]> TakePictureInternal(Size liveViewImageStreamSize, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { return(await Task.Run(() => Run(liveViewImageStreamSize, selectedAeMode, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed, selectedWhiteBalance, token), token)); }
public virtual async Task <CompositionProcessingResult> TakePictureAsync(byte[] liveViewImageStream, AEMode selectedAeMode, ApertureValue selectedAvValue, CameraISOSensitivity selectedIsoSensitivity, ShutterSpeed selectedShutterSpeed, WhiteBalance selectedWhiteBalance, CancellationToken token) { Size liveViewImageStreamSize; using (var stream = new MemoryStream(liveViewImageStream)) { var img = Image.FromStream(stream); liveViewImageStreamSize = img.Size; } return(new CompositionProcessingResult(_pattern, await TakePictureInternal(liveViewImageStreamSize, selectedAeMode, selectedAvValue, selectedIsoSensitivity, selectedShutterSpeed, selectedWhiteBalance, token))); }
static void Main(string[] args) { MtpResponse res; MtpCommand command = new MtpCommand(); // 接続されているデバイスIDを取得する string[] deviceIds = command.GetDeviceIds(); if (deviceIds.Length == 0) { return; } // RICOH THETA S デバイスを取得する string targetDeviceId = String.Empty; foreach (string deviceId in deviceIds) { if ("RICOH THETA S".Equals(command.GetDeviceFriendlyName(deviceId))) { targetDeviceId = deviceId; break; } } if (targetDeviceId.Length == 0) { return; } command.Open(targetDeviceId); // イベントを受け取れるようにする command.MtpEvent += MtpEventListener; // DeviceInfo res = command.Execute(MtpOperationCode.GetDeviceInfo, null, null); DeviceInfo deviceInfo = new DeviceInfo(res.Data); // DevicePropDesc(StillCaptureMode) res = command.Execute(MtpOperationCode.GetDevicePropDesc, new uint[1] { (uint)MtpDevicePropCode.StillCaptureMode }, null); DevicePropDesc dpd = new DevicePropDesc(res.Data); // シャッター優先 command.Execute(MtpOperationCode.SetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.ExposureProgramMode }, BitConverter.GetBytes((ushort)ExposureProgramMode.ShutterPriorityProgram)); // シャッター速度(Get) res = command.Execute(MtpOperationCode.GetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.ShutterSpeed }, null); ShutterSpeed ss = new ShutterSpeed(res.Data); // シャッター速度(Set) ss = new ShutterSpeed(1, 100); // 1/100 res = command.Execute(MtpOperationCode.SetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.ShutterSpeed }, ss.Data); // シャッター速度(Get) res = command.Execute(MtpOperationCode.GetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.ShutterSpeed }, null); ss = new ShutterSpeed(res.Data); // DevicePropDesc(ExposureIndex) res = command.Execute(MtpOperationCode.GetDevicePropDesc, new uint[1] { (uint)MtpDevicePropCode.ExposureIndex }, null); dpd = new DevicePropDesc(res.Data); // StillCaptureMode res = command.Execute(MtpOperationCode.GetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.StillCaptureMode }, null); StillCaptureMode mode = (StillCaptureMode)BitConverter.ToUInt16(res.Data, 0); // ストレージIDをとる res = command.Execute(MtpOperationCode.GetStorageIDs, null, null); uint[] storageIds = Utils.GetUIntArray(res.Data); // ストレージ情報をとる res = command.Execute(MtpOperationCode.GetStorageInfo, new uint[1] { storageIds[0] }, null); StorageInfo storageInfo = new StorageInfo(res.Data); // オブジェクト数をとる res = command.Execute(MtpOperationCode.GetNumObjects, new uint[3] { storageIds[0], 0, 0 }, null); uint num = res.Parameter1; // GetObjectHandles res = command.Execute(MtpOperationCode.GetObjectHandles, new uint[3] { storageIds[0], 0, 0 }, null); uint[] objectHandles = Utils.GetUIntArray(res.Data); // 静止画か動画をデスクトップに保存する // objectHandlesの最初の3つはフォルダのようなので4つ目を取得する if (objectHandles.Length > 3) { // ファイル名を取得する res = command.Execute(MtpOperationCode.GetObjectInfo, new uint[1] { objectHandles[3] }, null); ObjectInfo objectInfo = new ObjectInfo(res.Data); // ファイルを取得する res = command.Execute(MtpOperationCode.GetObject, new uint[1] { objectHandles[3] }, null); if (res.ResponseCode == MtpResponseCode.OK) { // デスクトップへ保存する using (FileStream fs = new FileStream( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + objectInfo.Filename, // ファイル名 FileMode.Create, FileAccess.Write)) { fs.Write(res.Data, 0, res.Data.Length); } } } // 撮影する res = command.Execute(MtpOperationCode.InitiateCapture, new uint[2] { 0, 0 }, null); // デバイスよさようなら command.Close(); }