private void OpenSession() { if (CameraListBox.SelectedIndex >= 0) { MainCamera = CamList[CameraListBox.SelectedIndex]; MainCamera.OpenSession(); MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated; MainCamera.ProgressChanged += MainCamera_ProgressChanged; MainCamera.StateChanged += MainCamera_StateChanged; MainCamera.DownloadReady += MainCamera_DownloadReady; SessionButton.Content = "Close Session"; SessionLabel.Content = MainCamera.DeviceName; AvList = MainCamera.GetSettingsList(PropertyID.Av); TvList = MainCamera.GetSettingsList(PropertyID.Tv); ISOList = MainCamera.GetSettingsList(PropertyID.ISO); foreach (var Av in AvList) { AvCoBox.Items.Add(Av.StringValue); } foreach (var Tv in TvList) { TvCoBox.Items.Add(Tv.StringValue); } foreach (var ISO in ISOList) { ISOCoBox.Items.Add(ISO.StringValue); } AvCoBox.SelectedIndex = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue); TvCoBox.SelectedIndex = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue); ISOCoBox.SelectedIndex = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue); SettingsGroupBox.IsEnabled = true; LiveViewGroupBox.IsEnabled = true; } }
private async void Start_Click(object sender, RoutedEventArgs e) { int totalimg = q.Count; OverallProg.Maximum = totalimg; OverallProg.Minimum = 0; while (q.Count > 0) { try { goset = (setting)q.Dequeue(); //do not update goset with new value if an exposure was not taken due to failure MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(goset.getEXP()).IntValue); // set exposure MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(goset.getAP()).IntValue); // set aperture MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(goset.getISO()).IntValue); // set ISO sensitivity MainCamera.TakePhotoAsync(); // capture image statustext.Text = "Capturing image " + (totalimg - q.Count) + " of " + totalimg; } catch (Exception ex) { ReportError(ex.Message, false); break; // stop while loop if error arises } finally { OverallProg.Value = totalimg - q.Count; await WaitAsynchronously(); } } statustext.Text = "Complete"; }
private void AvCoBox_SelectedIndexChanged(object sender, EventArgs e) { try { if (IsUIInit) { MainCamera.Av = AvValues.GetValue((string)AvCoBox.SelectedItem); } } catch (Exception ex) { ShowError(ex); } }
public void ISOChanged(object sender, int value) { if (ISOComboBox.SelectedIndex < 0 || !SessionOpen()) { return; } Camera.SetSetting(PropertyID.ISO, AvValues.GetValue((string)ISOComboBox.SelectedItem).IntValue); GUI.Camera_StatusUpdate("ISO set to: " + value); }
public bool TakePhoto(string[] camSettings) //where cS[0] is ISO(sensitivity), cS[1] is Tv(exposition), cS[2] is Tv in bulb mode and cS[3] is Av(apperture) { try { APIHandler = new CanonAPI(); if (OpenSession()) { if (!Error) { ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto"); MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(camSettings[0]).IntValue); MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(camSettings[3]).IntValue); MainCamera.SetCapacity(4096, int.MaxValue); Console.WriteLine($"Set image output path to: {ImageSaveDirectory}"); Console.WriteLine("Taking photo with special settings..."); CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)); if (tv == TvValues.Bulb) { MainCamera.TakePhotoBulb(int.Parse(camSettings[2])); } else { MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(camSettings[1]).IntValue); MainCamera.TakePhoto(); } WaitEvent.WaitOne(); if (!Error) { Console.WriteLine("Photo taken and saved"); return(true); } else { return(false); } } else { return(false); } } else { return(false); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); } finally { MainCamera?.Dispose(); APIHandler.Dispose(); } }
private void AvCoBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (AvCoBox.SelectedIndex < 0) { return; } MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue((string)AvCoBox.SelectedItem).IntValue); } catch (Exception ex) { ReportError(ex.Message, false); } }
public void SetInitGUI() { if (IsGUIInit || !GUI.IsInitialized) { return; } if (CamList?.Count >= 1) { try { GUI.Dispatcher.Invoke((Action) delegate { AvComboBox = GUI.GetComboBox(PropertyID.Av); TvComboBox = GUI.GetComboBox(PropertyID.Tv); ISOComboBox = GUI.GetComboBox(PropertyID.ISO); GUI.GetSavePathTextBox().Text = defSaveDir; foreach (var Av in AvList) { AvComboBox.Items.Add(AvComboBox.Items.Add(Av.StringValue)); } foreach (var Tv in TvList) { TvComboBox.Items.Add(TvComboBox.Items.Add(Tv.StringValue)); } foreach (var ISO in ISOList) { ISOComboBox.Items.Add(ISOComboBox.Items.Add(ISO.StringValue)); } AvComboBox.SelectedIndex = AvComboBox.Items.IndexOf(AvValues.GetValue(Camera.GetInt32Setting(PropertyID.Av)).StringValue); TvComboBox.SelectedIndex = TvComboBox.Items.IndexOf(TvValues.GetValue(Camera.GetInt32Setting(PropertyID.Tv)).StringValue); ISOComboBox.SelectedIndex = ISOComboBox.Items.IndexOf(ISOValues.GetValue(Camera.GetInt32Setting(PropertyID.ISO)).StringValue); GUI.Camera_StatusUpdate("Connected with:" + Camera.DeviceName); GUI.Camera_OpenedSession(Camera); GUI.LiveViewButton_Click(null, null); IsConnected = true; IsGUIInit = true; }); } catch (Exception e) { Console.WriteLine(e); ReportError(e.Message, false); } } else { GUI.Dispatcher.Invoke((Action) delegate { GUI.Camera_StatusUpdate("No camera connected"); }); } }
private void OpenSession() { if (CameraListBox.SelectedIndex >= 0) { MainCamera = CamList[CameraListBox.SelectedIndex]; MainCamera.OpenSession(); MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated; MainCamera.ProgressChanged += MainCamera_ProgressChanged; MainCamera.StateChanged += MainCamera_StateChanged; MainCamera.DownloadReady += MainCamera_DownloadReady; if (IsInit) { try { MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); //new MainCamera.SetCapacity(); //new BrowseButton.IsEnabled = true; button.IsEnabled = true; //new } catch (Exception ex) { ReportError(ex.Message, false); } } SessionButton.Content = "Close Session"; SessionLabel.Content = MainCamera.DeviceName; AvList = MainCamera.GetSettingsList(PropertyID.Av); TvList = MainCamera.GetSettingsList(PropertyID.Tv); ISOList = MainCamera.GetSettingsList(PropertyID.ISO); foreach (var Av in AvList) { AvCoBox.Items.Add(Av.StringValue); } foreach (var Tv in TvList) { TvCoBox.Items.Add(Tv.StringValue); } foreach (var ISO in ISOList) { ISOCoBox.Items.Add(ISO.StringValue); } AvCoBox.SelectedIndex = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue); TvCoBox.SelectedIndex = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue); ISOCoBox.SelectedIndex = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue); SettingsGroupBox.IsEnabled = true; LiveViewGroupBox.IsEnabled = true; //SaveFolderBrowser.SelectedPath = SavePathTextBox.Text; //new } }
private void OpenSession() { if (CameraListBox.SelectedIndex >= 0) { MainCamera = CamList[CameraListBox.SelectedIndex]; MainCamera.OpenSession(); MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated; MainCamera.ProgressChanged += MainCamera_ProgressChanged; MainCamera.StateChanged += MainCamera_StateChanged; MainCamera.DownloadReady += MainCamera_DownloadReady; SessionButton.Content = "Close Session"; SessionLabel.Content = MainCamera.DeviceName; AvList = MainCamera.GetSettingsList(PropertyID.Av); TvList = MainCamera.GetSettingsList(PropertyID.Tv); ISOList = MainCamera.GetSettingsList(PropertyID.ISO); foreach (var Av in AvList) { AvCoBox.Items.Add(Av.StringValue); } foreach (var Tv in TvList) { TvCoBox.Items.Add(Tv.StringValue); } foreach (var ISO in ISOList) { ISOCoBox.Items.Add(ISO.StringValue); } AvCoBox.SelectedIndex = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue); TvCoBox.SelectedIndex = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue); ISOCoBox.SelectedIndex = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue); SettingsGroupBox.IsEnabled = true; LiveViewGroupBox.IsEnabled = true; if ((bool)STComputerRdButton.IsChecked) { MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); } else if ((bool)STBothRdButton.IsChecked) { MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Both); } MainCamera.SetCapacity(4096, int.MaxValue); // MessageBox.Show("dupa", "Error", MessageBoxButton.OK, MessageBoxImage.None); } }
static void Main(string[] args) { try { APIHandler = new CanonAPI(); List <Camera> cameras = APIHandler.GetCameraList(); if (!OpenSession()) { Console.WriteLine("No camera found. Please plug in camera"); APIHandler.CameraAdded += APIHandler_CameraAdded; WaitEvent.WaitOne(); WaitEvent.Reset(); } if (!Error) { //ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto"); ImageSaveDirectory = "G:\\CSE260\\dataset\\3"; MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); MainCamera.SetCapacity(4096, int.MaxValue); Console.WriteLine($"Set image output path to: {ImageSaveDirectory}"); int SHUTTER_ID = 30; // Get aperture and shutter speed tables CameraValue[] AvList = MainCamera.GetSettingsList(PropertyID.Av); CameraValue[] TvList = MainCamera.GetSettingsList(PropertyID.Tv); // Loop over all aperture for (int i_av = 0; i_av < AvList.Length; ++i_av) { // Validate shutter speed if (SHUTTER_ID - i_av >= TvList.Length) { Console.WriteLine("shutter speed out of bounds"); break; } // Set Aperture and Shutter Speed MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue((string)AvList[i_av]).IntValue); MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvList[SHUTTER_ID - i_av]).IntValue); Console.WriteLine("set av to " + (string)AvList[i_av]); Console.WriteLine("set tv to " + (string)TvList[SHUTTER_ID - i_av]); System.Threading.Thread.Sleep(500); int now_av = MainCamera.GetInt32Setting(PropertyID.Av); int now_tv = MainCamera.GetInt32Setting(PropertyID.Tv); if ((int)AvList[i_av] != now_av) { Console.WriteLine("av comfirmation failed"); } if ((int)TvList[SHUTTER_ID - i_av] != now_tv) { Console.WriteLine("tv comfirmation failed"); } double shutterTime = TvList[SHUTTER_ID - i_av].DoubleValue; int waitTime = (int)(shutterTime * 1000 + 2000); Console.WriteLine("Wait Time is " + waitTime); // 22 +3 Steps for (int f = 0; f < 22; ++f) { int actualf = f; if (!atFar) { actualf = 21 - f; } ImageFileName = now_av + "_" + actualf + ".CR3"; MainCamera.TakePhoto(); System.Threading.Thread.Sleep(waitTime); // Flip the step direction each time to save time if (atFar) { MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Near3); } else { MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3); } System.Threading.Thread.Sleep(500); } // Flip far->near and far<-near atFar = !atFar; } /* * try { MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3); } * catch (Exception ex) * { Console.WriteLine(ex); }*/ /* * Console.WriteLine("Taking photo with current settings..."); * CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)); * if (tv == TvValues.Bulb) MainCamera.TakePhotoBulb(2); * else MainCamera.TakePhoto(); * WaitEvent.WaitOne(); */ if (!Error) { Console.WriteLine("Photo taken and saved"); } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("finally"); MainCamera?.Dispose(); APIHandler.Dispose(); Console.WriteLine("Good bye! (press any key to close)"); Console.ReadKey(); } }